ParticleBuffer
Description
- Derived from
-
Disposable abstract
ICapacity
IUpdateableFrameTime
A particle buffer stores per-particle information and updates particle data in a background thread.
The following steps are necessary to setup and run a particle buffer:
-
Create an instance of IParticleUpdater. This object will be used by the particle buffer to update per-particle data. Often this is a composite object created with IParticleUpdater.Append, to combine existing updater implementations, for example gravity, wind or velocity damping.
-
Choose the capacity of the particle buffer and the update rate of its particles. These values depend on the intended use case (big and slow-moving smoke particles vs. tiny high-speed spark particles) and should be chosen accordingly. For rendering, per-particle data is interpolated from fixed time-step values, so animation smoothness is independent of the update rate.
-
Create an instance of ParticleBuffer, passing the data arrays, the updater and the update rate. The particle buffer processes per-particle data in a background thread and sleeps if there are no particles to process.
-
Periodically call IUpdateableFrameTime.UpdateFrameTime, in order to advance the simulation time for particles. The background processing thread will sleep if no per-particle data needs to be processed.
-
Use CreateBegin to begin creation of particles. For each particle, update the particle data in Data. Once complete, call CreateEnd to submit the initialized particles.
The particles in the buffer are arranged as a ring buffer and a sliding window of active particles is maintained (the active region, see Count): new particles are inserted at the end of the sliding window and dead particles are removed from the beginning. There may be dead particles in the middle, these will be removed when the sliding window moves past them. To actually use the particles in a buffer, perform these steps:
-
Create an instance of IParticleOutput, for example an InstanceOutput object, which generates a 3D model instance for each non-dead particle in the active region.
-
Use IParticleOutput.Prepare to create a snapshot of the data in the particle buffer, which is updated at a fixed rate by a background thread.
-
Use IParticleOutput.Output to generate GPU data for rendering the buffered particles, using time-based interpolation to get smooth animation, even if the particles are updated at a low rate.
-
Render the particles, as explained by the documentation of the IParticleOutput implementation class.
The particle effect framework of an application usually has a small number of particle buffers and a variety of IParticleOutput objects, which produce GPU data for rendering. The visual appearance of a particle may be controlled with these data arrays:
Particle movement is captured by these data arrays:
The Age data array is used by the particle buffer to compute the active region and may also be used to apply variations to particle data, based on the particle age.
Public / Constants
Acceleration
The acceleration vector, in world-units per square second.
Name: 'Acceleration'
Tuple size: 3
Tuple type: TupleType.Float
Age
The particle age, in seconds.
Name: 'Age'
Tuple size: 2
Tuple type: TupleType.Float
The current age (see TupleComponent.X) will be greater than or equal to zero for all particles in the active region (see Count) and will be 0
for all other particles.
The maximum age (see TupleComponent.Y) will be greater than zero for all particles in the active region (see Count) and will be 0
for all other particles.
Color
The overall particle color, given as 32-bit ARGB sRGB color value with alpha (see Colors.Encode_A8R8G8B8).
Name: 'Color'
Tuple size: 1
Tuple type: TupleType.Int
GeometryId
The geometry identifier of the particle.
Name: 'GeometryId'
Tuple size: 1
Tuple type: TupleType.Int
Intensity
The high-dynamic range scale to apply to the overall particle color.
Name: 'Intensity'
Tuple size: 1
Tuple type: TupleType.Float
Orientation
The orientation quaternion (unit-length) of the particle.
Name: 'Orientation'
Tuple size: 4
Tuple type: TupleType.Float
- See also
Size
The overall particle size, where 1
represents the original particle size.
Name: 'Size'
Tuple size: 1
Tuple type: TupleType.Float
VelocityAngular
The angular velocity vector, in radians per second.
Name: 'VelocityAngular'
Tuple size: 3
Tuple type: TupleType.Float
VelocityLinear
The linear velocity vector, in world-units per second.
Name: 'VelocityLinear'
Tuple size: 3
Tuple type: TupleType.Float
Public / Methods
SnapshotBegin
Acquires a snapshot of the current particle simulation.
The background thread will be inactive when this method returns.
- See also
Public / Attributes
Time
Returns the accumulated simulation time that has been provided via IUpdateableFrameTime.UpdateFrameTime.