2
0

FluidRender_GS.hlsl 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // RUN: %dxc -E main -T gs_6_0 %s | FileCheck %s
  2. // CHECK: emitStream
  3. // CHECK: emitStream
  4. // CHECK: emitStream
  5. // CHECK: cutStream
  6. //--------------------------------------------------------------------------------------
  7. // File: FluidRender.hlsl
  8. //
  9. // Copyright (c) Microsoft Corporation. All rights reserved.
  10. //--------------------------------------------------------------------------------------
  11. //--------------------------------------------------------------------------------------
  12. // Particle Rendering
  13. //--------------------------------------------------------------------------------------
  14. struct Particle {
  15. float2 position;
  16. float2 velocity;
  17. };
  18. struct ParticleDensity {
  19. float density;
  20. };
  21. StructuredBuffer<Particle> ParticlesRO : register( t0 );
  22. StructuredBuffer<ParticleDensity> ParticleDensityRO : register( t1 );
  23. cbuffer cbRenderConstants : register( b0 )
  24. {
  25. matrix g_mViewProjection;
  26. float g_fParticleSize;
  27. };
  28. struct VSParticleOut
  29. {
  30. float2 position : POSITION;
  31. float4 color : COLOR;
  32. };
  33. struct GSParticleOut
  34. {
  35. float4 position : SV_Position;
  36. float4 color : COLOR;
  37. float2 texcoord : TEXCOORD;
  38. };
  39. //--------------------------------------------------------------------------------------
  40. // Visualization Helper
  41. //--------------------------------------------------------------------------------------
  42. static const float4 Rainbow[5] = {
  43. float4(1, 0, 0, 1), // red
  44. float4(1, 1, 0, 1), // orange
  45. float4(0, 1, 0, 1), // green
  46. float4(0, 1, 1, 1), // teal
  47. float4(0, 0, 1, 1), // blue
  48. };
  49. float4 VisualizeNumber(float n)
  50. {
  51. return lerp( Rainbow[ floor(n * 4.0f) ], Rainbow[ ceil(n * 4.0f) ], frac(n * 4.0f) );
  52. }
  53. float4 VisualizeNumber(float n, float lower, float upper)
  54. {
  55. return VisualizeNumber( saturate( (n - lower) / (upper - lower) ) );
  56. }
  57. //--------------------------------------------------------------------------------------
  58. // Particle Geometry Shader
  59. //--------------------------------------------------------------------------------------
  60. static const float2 g_positions[4] = { float2(-1, 1), float2(1, 1), float2(-1, -1), float2(1, -1) };
  61. static const float2 g_texcoords[4] = { float2(0, 1), float2(1, 1), float2(0, 0), float2(1, 0) };
  62. [maxvertexcount(4)]
  63. void main(point VSParticleOut In[1], inout TriangleStream<GSParticleOut> SpriteStream)
  64. {
  65. [unroll]
  66. for (int i = 0; i < 4; i++)
  67. {
  68. GSParticleOut Out = (GSParticleOut)0;
  69. float4 position = float4(In[0].position, 0, 1) + g_fParticleSize * float4(g_positions[i], 0, 0);
  70. Out.position = mul(position, g_mViewProjection);
  71. Out.color = In[0].color;
  72. Out.texcoord = g_texcoords[i];
  73. SpriteStream.Append(Out);
  74. }
  75. SpriteStream.RestartStrip();
  76. }