Graphics Reference
In-Depth Information
// Forces
float3 force = (float3)0;
// Directional force
force += normalize(ForceDirection) * ForceStrength;
// Damping
float windResist = 0.9;
force *= windResist;
particle.OldPosition = particle.Position;
// Integration step
particle.Position += force * FrameTime;
}
// Random Number Generator methods
uint rand_lcg(inout uint rng_state)
{ // Linear congruential generator
rng_state = 1664525 * rng_state + 1013904223;
return rng_state;
}
uint wang_hash(uint seed)
{ // Initialize a random seed
seed = (seed ^ 61) ^ (seed >> 16);
seed *= 9;
seed = seed ^ (seed >> 4);
seed *= 0x27d4eb2d;
seed = seed ^ (seed >> 15);
return seed;
}
6.
Next, we will create the particle generator that inserts new particles into an
append buffer.
[numthreads(THREADSX, 1, 1)]
void Generator(uint groupIndex: SV_GroupIndex,
uint3 groupId : SV_GroupID, uint3 groupThreadId:
SV_GroupThreadID, uint3 threadId : SV_DispatchThreadID)
{
uint indx = threadId.x + threadId.y * THREADSX;
Particle p = (Particle)0;
// Initialize random seed
uint rng_state = wang_hash(RandomSeed + indx);
// Random float between [0, 1]
float f0 = float(rand_lcg(rng_state)) *
(1.0 / 4294967296.0);
 
Search WWH ::




Custom Search