ParticleSpawnCS.hlsl 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // RUN: %dxc -E main -T cs_6_0 -O0 %s | FileCheck %s
  2. // CHECK: threadId
  3. // CHECK: bufferUpdateCounter
  4. // CHECK: bufferLoad
  5. // CHECK: bufferStore
  6. //
  7. // Copyright (c) Microsoft. All rights reserved.
  8. // This code is licensed under the MIT License (MIT).
  9. // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
  10. // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
  11. // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
  12. // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
  13. //
  14. // Developed by Minigraph
  15. //
  16. // Author: Julia Careaga
  17. // James Stanard
  18. //
  19. #include "ParticleUpdateCommon.hlsli"
  20. #include "ParticleUtility.hlsli"
  21. StructuredBuffer< ParticleSpawnData > g_ResetData : register( t0 );
  22. RWStructuredBuffer< ParticleMotion > g_OutputBuffer : register( u2 );
  23. [RootSignature(Particle_RootSig)]
  24. [numthreads(64, 1, 1)]
  25. void main( uint3 DTid : SV_DispatchThreadID )
  26. {
  27. uint index = g_OutputBuffer.IncrementCounter();
  28. if (index >= MaxParticles)
  29. return;
  30. uint ResetDataIndex = RandIndex[DTid.x].x;
  31. ParticleSpawnData rd = g_ResetData[ResetDataIndex];
  32. float3 emitterVelocity = EmitPosW - LastEmitPosW;
  33. float3 randDir = rd.Velocity.x * EmitRightW + rd.Velocity.y * EmitUpW + rd.Velocity.z * EmitDirW;
  34. float3 newVelocity = emitterVelocity * EmitterVelocitySensitivity + randDir;
  35. float3 adjustedPosition = EmitPosW - emitterVelocity * rd.Random + rd.SpreadOffset;
  36. ParticleMotion newParticle;
  37. newParticle.Position = adjustedPosition;
  38. newParticle.Rotation = 0.0;
  39. newParticle.Velocity = newVelocity + EmitDirW * EmitSpeed;
  40. newParticle.Mass = rd.Mass;
  41. newParticle.Age = 0.0;
  42. newParticle.ResetDataIndex = ResetDataIndex;
  43. g_OutputBuffer[index] = newParticle;
  44. }