博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
利用Vertex shader实现Point Sprites
阅读量:2439 次
发布时间:2019-05-10

本文共 1222 字,大约阅读时间需要 4 分钟。

通常,point sprites只能通过GS来实现,但是最新的DX11.1后技术,可以直接利用VS实现,并且速度更快:

  • 创建一个point buffer作为SRV绑定到VS上;
  • 调用Draw或者 DrawIndexed来渲染一个三角形列表;
  • 在VS中读取point buffer中的信息扩展为一个四边形;
这个技术可以用particle渲染,Bokeh DOF sprites
PS:小物体不要使用Drawinstanced.
C++ 代码:

pD3dContext->IASetIndexBuffer(g_pParticleIndexBuffer, DXGI_FORMAT_R32_UINT, 0);pD3dContex->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);pD3dContext->DrawIndexed(g_particleCount*6, 0, 0);

HLSL代码:

VSInstanceParticleDrawOut VSIndexBuffer( uint id:SV_VERTEXID){    VSInstancedParticleDrawOut output;    uint particleIndex = id/4;    uint vertexInQuad = id%4;    // calculate the position of the vertex    float3 position;    position.x = (vertexInQuad%2) ? 1.0 : -1.0;    position.y = (vertexInQuad&2) ? -1.0 : 1.0;    position.z = 0.0;    position.xy *= PARTICLE_RADIUS;    position = mul(position, (float3x3)g_mInvView) + g_bufPosColor[particleIndex].pos.xyz;    output.pos = mul(float4(position,1.0), g_mWorldViewProj );    output.color = g_bufPosColor[particleIndex].color;    // texture coordinate    output.tex.x = (vertexInQuad%2) ? 1.0 : 0.0;    output.tex.y = (vertexInQuad&2) ? 1.0 : 0.0;    return output;}

性能:

DrawIndexed() 性能最高; Draw()稍慢点,但是不需要IB。DrawInstanced() 性能极差,不建议使用。

转载地址:http://yhwqb.baihongyu.com/

你可能感兴趣的文章
预装正版的市场意义(转)
查看>>
创建小于16M XFree86迷你Linux系统(转)
查看>>
shell中常用的工具(转)
查看>>
使用MySQL内建复制功能来最佳化可用性(转)
查看>>
一个比较vista的vista主题for rf5.0fb(转)
查看>>
推荐一款 Linux 上比较漂亮的字体(转)
查看>>
在Linux中添加新的系统调用(转)
查看>>
Fedora Core 5.0 安装教程{下载}(转)
查看>>
把ACCESS的数据导入到Mysql中(转)
查看>>
shell里边子函数与主函数的实例(转)
查看>>
Linux中MAXIMA符号运算软件的简介(转)
查看>>
银行选择Linux 则无法回避高成本(转)
查看>>
上网聊天需要防范的几大威胁(转)
查看>>
[分享]后门清除完全篇(转)
查看>>
用php在linux下连接mssql2000(转)
查看>>
让你的Linux支持WEB修改密码(转)
查看>>
MYSQL的master/slave数据同步配置(转)
查看>>
LINUX 与 UPS(转)
查看>>
一个完整的ftp远程批量shell(转)
查看>>
Vsftpd匿名无法上传,配置如下,帮忙找下原因,谢谢~!(转)
查看>>