Graphics Reference
In-Depth Information
float f1 = float(rand_lcg(rng_state)) *
(1.0 / 4294967296.0);
float f2 = float(rand_lcg(rng_state)) *
(1.0 / 4294967296.0);
// Set properties of new particle
p.Radius = Radius;
p.Position.x = DomainBoundsMin.x + f0 *
((DomainBoundsMax.x - DomainBoundsMin.x) + 1);
p.Position.z = DomainBoundsMin.z + f1 *
((DomainBoundsMax.z - DomainBoundsMin.z) + 1);
p.Position.y = (DomainBoundsMax.y - 6) + f2 *
((DomainBoundsMax.y - (DomainBoundsMax.y-6)) + 1);
p.OldPosition = p.Position;
p.Energy = MaxLifetime;
// Append the new particle to the output buffer
NewState.Append(p);
}
7.
Next, we will add a compute shader that takes the consume buffer to simulate
falling snow.
[numthreads(THREADSX, THREADSY, 1)]
void Snowfall(uint groupIndex: SV_GroupIndex,
uint3 groupId : SV_GroupID,
uint3 groupThreadId: SV_GroupThreadID,
uint3 threadId : SV_DispatchThreadID)
{
uint indx = threadId.x + threadId.y * THREADSX;
// Skip out of bounds threads
if (indx >= ParticleCount)
return;
// Load/Consume particle
Particle p = CurrentState.Consume();
ApplyForces(p);
// Ensure the particle does not fall endlessly
p.Position.y = max(p.Position.y, DomainBoundsMin.y);
// Count down time to live
p.Energy -= FrameTime;
// If no longer falling only let sit for a second
 
Search WWH ::




Custom Search