FlowFieldVS.usf 931 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2023 ZSttt, Inc. All Rights Reserved.
  2. #include "/Engine/Public/Platform.ush"
  3. #include "/Engine/Private/Common.ush"
  4. #ifndef FLOWFIELD2D_USE_COMPUTE
  5. #define FLOWFIELD2D_USE_COMPUTE true
  6. #endif
  7. float2 QuadSize;
  8. #if FLOWFIELD2D_USE_COMPUTE
  9. StructuredBuffer<float2> Particles;
  10. #else
  11. Texture2D<float4> Particles;
  12. uint2 ParticlesResolution;
  13. #endif
  14. void DrawParticles
  15. (
  16. in float4 Vertex : ATTRIBUTE0,
  17. uint IId : SV_InstanceID,
  18. out float2 OutParticle : TEXCOORD0,
  19. out float4 Output : SV_POSITION
  20. )
  21. {
  22. #if FLOWFIELD2D_USE_COMPUTE
  23. OutParticle = Particles[IId];
  24. #else
  25. uint2 Pos = uint2(IId / ParticlesResolution.x, IId % ParticlesResolution.x);
  26. float4 color = Particles.Load(uint3(Pos, 0));
  27. OutParticle = float2(color.r / 255.0 + color.b, color.g / 255.0 + color.a);
  28. #endif
  29. float2 UV = OutParticle.xy + (QuadSize * Vertex.xy);
  30. UV = 2.0 * UV - 1.0;
  31. Output = float4(UV.r, UV.g, 0.0, 1.0);
  32. }