Graphics Reference
In-Depth Information
The result of executing this compute shader is to insert eight particles into the system
at uniformly distributed, but randomized directions. If this is performed several times in
succession, the result is a halo of particles emitted from the emission point in all directions.
This is depicted in Figure 12.12, which is a screen shot where the particles are allowed to
continue travelling in their initial velocity directions, as determined by the randomized
vectors.
Particle State Update Phase
Once all of the particles have been added into the particle system, we can finally execute
the actual simulation calculations to update the state of the particle system. This is per-
formed in a compute shader that follows the threading model described in the "Threading
Scheme" section. Essentially we dispatch an appropriate number of thread groups to ensure
that we have enough threads to process all of the particles in the simulation. In our sample,
we can simply retain a count of the number of particles that have been created, and assume
that the particles remain in existence for their entire possible lifetime. This estimate is then
used to round up to the next higher multiple of 512 to determine how many thread groups
to dispatch.
The particle system update shader is set up as shown in Listing 12.8. The update
method that is used within the inner loop to actually update the particle is directly based on
the physically based gravitation equations described in the "Theory" section. The portion
of the shader for executing this update method is shown in Listing 12.10.
static const float G = 10.0f;
static const float m1 = 1.0f;
static const float m2 = 1000.0f;
static const float mlm2 = ml * m2;
static const float eventHonizon = 5.0f;
[numthreads( 512, 1, 1)]
void CSMAIN( uint3 DispatchThreadID : SV_DispatchThreadID )
{
// Check for if this thread should run or not.
uint myID = DispatchThreadID. x
+ DispatchThreadID.y * 512
+ DispatchThreadID.z * 512 * 512;
if ( mylD < NumParticles.x )
{
// Get the current particle
Particle p = CurrentSimulationState.Consume();
// Calculate the current gravitational force applied to it
float3 d = ConsumerLocation.xyz - p.position;
float r = length( d );
Search WWH ::




Custom Search