Embed presentation
Download as PPSX, PPTX







![SV_VertexID● Can use the vertex id to decide whatvertex data to fetch● Fetch from SRV, or procedurally create avertexVSOut VertexShader(SV_VertexID id){float3 vertex = g_VertexBuffer[id];…}](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fvertexshadertricks-billbilodeau-140403092257-phpapp01%2f75%2fVertex-Shader-Tricks-by-Bill-Bilodeau-AMD-at-GDC14-8-2048.jpg&f=jpg&w=240)








![Point Sprites: HLSL CodeVSInstancedParticleDrawOut VSIndexBuffer(uint id:SV_VERTEXID){VSInstancedParticleDrawOut output;uint particleIndex = id / 4;uint vertexInQuad = id % 4;// calculate the position of the vertexfloat3 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 coordinateoutput.tex.x = (vertexInQuad % 2) ? 1.0 : 0.0;output.tex.y = (vertexInQuad & 2) ? 1.0 : 0.0;return output;}](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fvertexshadertricks-billbilodeau-140403092257-phpapp01%2f75%2fVertex-Shader-Tricks-by-Bill-Bilodeau-AMD-at-GDC14-17-2048.jpg&f=jpg&w=240)









![Bounding Box: HLSL Codevoid UAVBBoxSkinVS(VSSkinnedIn input, uint id:SV_VERTEXID ){// skin the vertex. . .// output the max and min for the bounding boxint x = (int) (vSkinned.Pos.x * FLOAT_SCALE); // convert to integerint y = (int) (vSkinned.Pos.y * FLOAT_SCALE);int z = (int) (vSkinned.Pos.z * FLOAT_SCALE);InterlockedMin(g_BBoxUAV[0], x);InterlockedMin(g_BBoxUAV[1], y);InterlockedMin(g_BBoxUAV[2], z);InterlockedMax(g_BBoxUAV[3], x);InterlockedMax(g_BBoxUAV[4], y);InterlockedMax(g_BBoxUAV[5], z);. . .](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fvertexshadertricks-billbilodeau-140403092257-phpapp01%2f75%2fVertex-Shader-Tricks-by-Bill-Bilodeau-AMD-at-GDC14-27-2048.jpg&f=jpg&w=240)

![Particle System: HLSL Codeuint particleIndex = id / 4;uint vertexInQuad = id % 4;// calculate the new position of the vertexfloat3 oldPosition = g_bufPosColor[particleIndex].pos.xyz;float3 oldVelocity = g_bufPosColor[particleIndex].velocity.xyz;// Euler integration to find new position and velocityfloat3 acceleration = normalize(oldVelocity) * ACCELLERATION;float3 newVelocity = acceleration * g_deltaT + oldVelocity;float3 newPosition = newVelocity * g_deltaT + oldPosition;g_particleUAV[particleIndex].pos = float4(newPosition, 1.0);g_particleUAV[particleIndex].velocity = float4(newVelocity, 0.0);// Generate sprite vertices. . .](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fvertexshadertricks-billbilodeau-140403092257-phpapp01%2f75%2fVertex-Shader-Tricks-by-Bill-Bilodeau-AMD-at-GDC14-29-2048.jpg&f=jpg&w=240)





The document discusses advanced techniques and optimizations for vertex shaders in DirectX 11, highlighting common bottlenecks and providing various performance-enhancing strategies. It covers the use of features such as advanced vertex outputs, instancing methods, and UAVs (Unordered Access Views) in shaders. Additionally, it presents examples and code snippets demonstrating how to implement full-screen triangles, point sprites, and a particle system utilizing these techniques.







![SV_VertexID● Can use the vertex id to decide whatvertex data to fetch● Fetch from SRV, or procedurally create avertexVSOut VertexShader(SV_VertexID id){float3 vertex = g_VertexBuffer[id];…}](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fvertexshadertricks-billbilodeau-140403092257-phpapp01%2f75%2fVertex-Shader-Tricks-by-Bill-Bilodeau-AMD-at-GDC14-8-2048.jpg&f=jpg&w=240)








![Point Sprites: HLSL CodeVSInstancedParticleDrawOut VSIndexBuffer(uint id:SV_VERTEXID){VSInstancedParticleDrawOut output;uint particleIndex = id / 4;uint vertexInQuad = id % 4;// calculate the position of the vertexfloat3 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 coordinateoutput.tex.x = (vertexInQuad % 2) ? 1.0 : 0.0;output.tex.y = (vertexInQuad & 2) ? 1.0 : 0.0;return output;}](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fvertexshadertricks-billbilodeau-140403092257-phpapp01%2f75%2fVertex-Shader-Tricks-by-Bill-Bilodeau-AMD-at-GDC14-17-2048.jpg&f=jpg&w=240)









![Bounding Box: HLSL Codevoid UAVBBoxSkinVS(VSSkinnedIn input, uint id:SV_VERTEXID ){// skin the vertex. . .// output the max and min for the bounding boxint x = (int) (vSkinned.Pos.x * FLOAT_SCALE); // convert to integerint y = (int) (vSkinned.Pos.y * FLOAT_SCALE);int z = (int) (vSkinned.Pos.z * FLOAT_SCALE);InterlockedMin(g_BBoxUAV[0], x);InterlockedMin(g_BBoxUAV[1], y);InterlockedMin(g_BBoxUAV[2], z);InterlockedMax(g_BBoxUAV[3], x);InterlockedMax(g_BBoxUAV[4], y);InterlockedMax(g_BBoxUAV[5], z);. . .](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fvertexshadertricks-billbilodeau-140403092257-phpapp01%2f75%2fVertex-Shader-Tricks-by-Bill-Bilodeau-AMD-at-GDC14-27-2048.jpg&f=jpg&w=240)

![Particle System: HLSL Codeuint particleIndex = id / 4;uint vertexInQuad = id % 4;// calculate the new position of the vertexfloat3 oldPosition = g_bufPosColor[particleIndex].pos.xyz;float3 oldVelocity = g_bufPosColor[particleIndex].velocity.xyz;// Euler integration to find new position and velocityfloat3 acceleration = normalize(oldVelocity) * ACCELLERATION;float3 newVelocity = acceleration * g_deltaT + oldVelocity;float3 newPosition = newVelocity * g_deltaT + oldPosition;g_particleUAV[particleIndex].pos = float4(newPosition, 1.0);g_particleUAV[particleIndex].velocity = float4(newVelocity, 0.0);// Generate sprite vertices. . .](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fvertexshadertricks-billbilodeau-140403092257-phpapp01%2f75%2fVertex-Shader-Tricks-by-Bill-Bilodeau-AMD-at-GDC14-29-2048.jpg&f=jpg&w=240)



