ParticleDraw_GS.hlsl 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // RUN: %dxc -E main -T gs_6_0 %s | FileCheck %s
  2. // CHECK: storeOutput
  3. // CHECK: emitStream
  4. // CHECK: cutStream
  5. //--------------------------------------------------------------------------------------
  6. // File: ParticleDraw.hlsl
  7. //
  8. // Shaders for rendering the particle as point sprite
  9. //
  10. // Copyright (c) Microsoft Corporation. All rights reserved.
  11. //--------------------------------------------------------------------------------------
  12. struct VSParticleIn
  13. {
  14. float4 color : COLOR;
  15. uint id : SV_VERTEXID;
  16. };
  17. struct VSParticleDrawOut
  18. {
  19. float3 pos : POSITION;
  20. float4 color : COLOR;
  21. };
  22. struct GSParticleDrawOut
  23. {
  24. float2 tex : TEXCOORD0;
  25. float4 color : COLOR;
  26. float4 pos : SV_POSITION;
  27. };
  28. struct PSParticleDrawIn
  29. {
  30. float2 tex : TEXCOORD0;
  31. float4 color : COLOR;
  32. };
  33. struct PosVelo
  34. {
  35. float4 pos;
  36. float4 velo;
  37. };
  38. Texture2D g_txDiffuse;
  39. StructuredBuffer<PosVelo> g_bufPosVelo;
  40. SamplerState g_samLinear
  41. {
  42. Filter = MIN_MAG_MIP_LINEAR;
  43. AddressU = Clamp;
  44. AddressV = Clamp;
  45. };
  46. cbuffer cb0
  47. {
  48. row_major float4x4 g_mWorldViewProj;
  49. row_major float4x4 g_mInvView;
  50. };
  51. cbuffer cb1
  52. {
  53. static float g_fParticleRad = 10.0f;
  54. };
  55. cbuffer cbImmutable
  56. {
  57. static float3 g_positions[4] =
  58. {
  59. float3( -1, 1, 0 ),
  60. float3( 1, 1, 0 ),
  61. float3( -1, -1, 0 ),
  62. float3( 1, -1, 0 ),
  63. };
  64. static float2 g_texcoords[4] =
  65. {
  66. float2(0,0),
  67. float2(1,0),
  68. float2(0,1),
  69. float2(1,1),
  70. };
  71. };
  72. //
  73. // GS for rendering point sprite particles. Takes a point and turns it into 2 tris.
  74. //
  75. [maxvertexcount(4)]
  76. void main(point VSParticleDrawOut input[1], inout TriangleStream<GSParticleDrawOut> SpriteStream)
  77. {
  78. GSParticleDrawOut output;
  79. //
  80. // Emit two new triangles
  81. //
  82. for(int i=0; i<4; i++)
  83. {
  84. float3 position = g_positions[i] * g_fParticleRad;
  85. position = mul( position, (float3x3)g_mInvView ) + input[0].pos;
  86. output.pos = mul( float4(position,1.0), g_mWorldViewProj );
  87. output.color = input[0].color;
  88. output.tex = g_texcoords[i];
  89. SpriteStream.Append(output);
  90. }
  91. SpriteStream.RestartStrip();
  92. }