Particle_GS.hlsl 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // RUN: %dxc -E main -T gs_6_0 %s | FileCheck %s
  2. // CHECK: storeOutput
  3. // CHECK: emitStream
  4. // CHECK: storeOutput
  5. // CHECK: emitStream
  6. // CHECK: storeOutput
  7. // CHECK: emitStream
  8. // CHECK: storeOutput
  9. // CHECK: emitStream
  10. // CHECK: cutStream
  11. //--------------------------------------------------------------------------------------
  12. // File: Particle.hlsl
  13. //
  14. // HLSL file containing shader function to render front-facing particles.
  15. //
  16. // Copyright (c) Microsoft Corporation. All rights reserved.
  17. //--------------------------------------------------------------------------------------
  18. #include "shader_include.hlsli"
  19. //--------------------------------------------------------------------------------------
  20. // Internal defines
  21. //--------------------------------------------------------------------------------------
  22. #define FIXED_VERTEX_RADIUS 5.0
  23. //--------------------------------------------------------------------------------------
  24. // Structures
  25. //--------------------------------------------------------------------------------------
  26. struct VS_PARTICLE_INPUT
  27. {
  28. float3 WSPos : POSITION;
  29. };
  30. struct GS_PARTICLE_INPUT
  31. {
  32. float4 WSPos : POSITION;
  33. };
  34. struct PS_PARTICLE_INPUT
  35. {
  36. float4 Pos : SV_POSITION;
  37. float2 Tex : TEXCOORD0;
  38. };
  39. //--------------------------------------------------------------------------------------
  40. // Geometry Shader to render point sprites
  41. //--------------------------------------------------------------------------------------
  42. [maxvertexcount(4)]
  43. void main(point GS_PARTICLE_INPUT input[1], inout TriangleStream<PS_PARTICLE_INPUT> SpriteStream)
  44. {
  45. const float3 g_positions[4] =
  46. {
  47. float3( -1.0, 1.0, 0.0 ),
  48. float3( 1.0, 1.0, 0.0 ),
  49. float3( -1.0, -1.0, 0.0 ),
  50. float3( 1.0, -1.0, 0.0 ),
  51. };
  52. const float2 g_texcoords[4] =
  53. {
  54. float2( 0.0, 1.0 ),
  55. float2( 1.0, 1.0 ),
  56. float2( 0.0, 0.0 ),
  57. float2( 1.0, 0.0 ),
  58. };
  59. PS_PARTICLE_INPUT output = (PS_PARTICLE_INPUT)0;
  60. // Emit two new triangles
  61. [unroll]for( int i=0; i<4; ++i )
  62. {
  63. float3 position = g_positions[i] * FIXED_VERTEX_RADIUS;
  64. position = mul( position, (float3x3)g_mInvView ) + input[0].WSPos;
  65. output.Pos = mul( float4( position, 1.0 ), g_mViewProjection );
  66. // Pass texture coordinates
  67. output.Tex = g_texcoords[i];
  68. // Add vertex
  69. SpriteStream.Append( output );
  70. }
  71. SpriteStream.RestartStrip();
  72. }