Graphics Reference
In-Depth Information
float3 Force = ( G * m1m2 / (r*r) ) * normalize( d );
// Calculate the new velocity, accounting for the acceleration from
// the gravitational force over the current time step.
p.velocity = p.velocity + ( Force / ml ) * TimeFactors.x;
// Calculate the new position, accounting for the new velocity value
// over the current time step.
p.position += p.velocity * TimeFactors.x;
// Update the life time left for the particle,
p. time = p. time + TimeFactors.x;
// Test to see how close the particle is to the black hole, and
// don't pass it to the output list if it is too close,
if ( r > eventHorizon )
{
if ( p. time < 10.0f )
{
NewSimulationState.Append( p );
}
}
}
}
Listing 12.10. Updating the state of each particle.
If the current thread corresponds to a live particle, it consumes one particle from the
consume buffer. It then calculates the gravitational force from the black hole, the accelera-
tion caused by this force, the new velocity caused by the acceleration, and finally the new
position is calculated from the updated velocity. Once the particle state has been updated,
we finally test to see if we are within an eventHorizon radius of the black hole. If we are,
then the particle is not appended to the output append buffer. This effectively eliminates
the particle from the system, since it isn't propagated to the next simulation step. Similarly,
if a particle has been alive longer than a threshold amount of time, it is not added to the
output buffer.
Rendering the Particle System
After performing a simulation update phase, we have a structured buffer that contains the
current state of the particle system. The next step is to render the results of our simulation
in an efficient manner. The pipeline configuration is shown in Figure 12.13 for reference
during the description. As discussed earlier, if at all possible, we are trying to keep the
CPU from having to read back any information about the particle system. For render-
ing the results of the particle system, we want to do the same thing and avoid having to
read the particle data back to system memory. Unfortunately, we cannot directly use the
structured buffer as a vertex buffer, since vertex buffers are not allowed to have other bind
Search WWH ::




Custom Search