FluidRender_VS.hlsl 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // RUN: %dxc -E main -T vs_6_0 %s | FileCheck %s
  2. // CHECK: bufferLoad
  3. // CHECK: Saturate
  4. // CHECK: Round_pi
  5. // CHECK: Round_ni
  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. // Vertex Shader
  59. //--------------------------------------------------------------------------------------
  60. VSParticleOut main(uint ID : SV_VertexID)
  61. {
  62. VSParticleOut Out = (VSParticleOut)0;
  63. Out.position = ParticlesRO[ID].position;
  64. Out.color = VisualizeNumber(ParticleDensityRO[ID].density, 1000.0f, 2000.0f);
  65. return Out;
  66. }