Graphics Reference
In-Depth Information
Particle System Rendering Algorithm
This section provides a high-level overview of how the transform
feedback-based particle system works. At initialization time, two buffer
objects are allocated to hold the particle data. The algorithm ping-pongs
(switches back and forth) between the two buffers, each time switching
which buffer is the input or output for particle emission. Each particle
contains the following information: position, velocity, size, current time,
and lifetime.
The particle system is updated with transform feedback and then rendered
in the following steps:
• In each frame, one of the particle VBOs is selected as the input
and bound as a GL_ARRAY_BUFFER . The output is bound as a
GL_TRANSFORM_FEEDBACK_BUFFER .
GL_RASTERIZER_DISCARD is enabled so that no fragments are drawn.
• The particle emission shader is executed using point primitives (each
particle is one point). The vertex shader outputs new particles to
the transform feedback buffer and copies existing particles to the
transform feedback buffer unchanged.
GL_RASTERIZER_DISCARD is disabled, so that the application can draw
the particles.
• The buffer that was rendered to for transform feedback is now bound
as a GL_ARRAY_BUFFER . Another vertex/fragment shader is bound to
draw the particles.
• The particles are rendered to the framebuffer.
• In the next frame, the input/output buffer objects are swapped and
the same process continues.
Particle Emission with Transform Feedback
Example 14-9 shows the vertex shader that is used for emitting particles.
All of the output variables in this shader are written to a transform
feedback buffer object. Whenever a particle's lifetime has expired, the
shader will make it a potential candidate for emission as a new active
particle. If a new particle is generated, the shader uses a randomValue
function (shown in the vertex shader code in Example 14-9) that generates
a random value to initialize the new particle's velocity and size. The
random number generation is based on using a 3D noise texture and using
the gl_VertexID built-in variable to select a unique texture coordinate
 
 
 
Search WWH ::




Custom Search