-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticleCS.hlsl
More file actions
31 lines (27 loc) · 946 Bytes
/
ParticleCS.hlsl
File metadata and controls
31 lines (27 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//this shader handnles the movement of the particles
cbuffer Time
{
float deltaTime;
float random;
float2 padding;
};
RWBuffer<float> particlePosition;
[numthreads(8, 1, 1)]
void main(uint3 dt_id : SV_DispatchThreadID)
{
float3 currentPosition = float3(particlePosition[dt_id.x * 3 + 0], particlePosition[dt_id.x * 3 + 1], particlePosition[dt_id.x * 3 + 2]);
float3 output = currentPosition;
output.y += 2 * deltaTime; //movement, change the constant for faster/slower particles
if (output.y > 10) //if at a certain height
{
output.y = (random)-(float)dt_id.x;
if (output.y < -10) //to not start too far below
{
output.y = -10;
}
}
//set new position for particle
particlePosition[dt_id.x * 3 + 0] = output.x;
particlePosition[dt_id.x * 3 + 1] = output.y;
particlePosition[dt_id.x * 3 + 2] = output.z;
}