Table Of Contents

Previous topic

20.6. The ParticleUpdater Interface

Next topic

20.8. The ParticleSynchronizer Interface

This Page

20.7. The ParticleRenderer Interface

Added SDK 0.28.0

Encapsulates a replaceable element of a particle system responsible for rendering the particles in the system.

This object may be shared amongst many ParticleSystems.

Note

This is a low-level particle system API.

20.7.1. Properties

20.7.1.1. technique

The Technique to be used for rendering particle states on the GPU.

20.7.1.2. parameters

An object defining the parameters required by this specific renderer with their default values.

The ParticleSystem will produce a copy of this object with additional fields added defined in particles-common.cgh which should not be used by this object.

  • center
  • halfExtents
  • projection
  • maxLifeTime
  • modelView
  • textureSize
  • invTextureSize
  • regionSize
  • regionPos
  • invRegionSize
  • mappingSize
  • invMappingSize
  • mappingPos
  • mappingTable
  • vParticleState
  • fParticleState
  • animation
  • animationSize

20.7.2. Methods

20.7.2.1. createGeometry

Summary

Create a ParticleGeometry object compatible with this renderer.

Syntax

var geometry = renderer.createGeometry({
    graphicsDevice: GraphicsDevice,
    maxParticles: 1024,
    shared: false
});
graphicsDevice
The GraphicsDevice object.
maxParticles
The maximum amount of particles renderable with the created geometry object.
shared (Optional)
Whether this geometry is going to be shared amongst many particle systems or not.

20.7.2.2. createUserData

Summary

This function will be called by ParticleEmitters when used in conjunction with the high level ParticleManager to transform archetype userData objects into the real userData integer value.

Syntax

var userData = renderer.createUserData(parameters);

20.7.2.3. createUserDataSeed

Summary

This function will be called by ParticleEmitters, and should return a particle particle userData field, containing randomized seed values if appropriate.

Syntax

var userData = renderer.createUserDataSeed();

20.7.2.4. applyArchetype

Summary

This function will be called by the high level ParticleManager to apply a constructed ParticleArchetype to this renderer.

This function should use the constructed archetype and other parameters to specify all parameters required on system.renderParameters object specific to this renderer.

Syntax

renderer.applyArchetype(textureManager, system, archetype, particleTextures);
textureManager
The TextureManager to look up Textures from paths given in archetype.
system
The ParticleSystem to apply archetype to.
archetype
The renderer specific archetype parameters to be applied.
particleTextures
A function to be used to retrieve packed particle textures from a texture type name (Eg: “texture0”).

20.7.3. The DefaultParticleRenderer Object

Implementation of a ParticleRenderer.

Renders particles as textured quads that are either bill-boarded to face camera, aligned to face along direction of motion, or with a per-particle defined direction.

Particles are rendered based on the default particle animation texture definition, supporting animated rotation, color, scale and a flip-book animation of particle appearances.

On a per-particle basis, particles can opt-in to have their rotation, final orientation, alpha or scale randomized.

On a system wide basis, the amount of randomization can be controlled, and whether each randomization applied is fixed once the particle is created, or changes over the particles life time.

Particle userData storage used

Orientation of particle is controlled with bits [30,32) as a 2-bit integer with 0 specifying a bill-boarded orientation, 1 a velocity-aligned orientation, and 2 a custom orientation.

Custom orientations are specified with bits [0,8) and [8,16) specifying two normalized, spherical angles: theta in the high 8 bits representing values [0,pi) and phi in the low 8 bits representing values [0,2pi).

To randomize the rotation of particles, bit 29 should be set.

To randomize the scale of particles, bit 28 should be set.

To randomize the orientation of particles, bit 27 should be set.

To randomize the alpha of particles, bit 26 should be set.

Bits [16,24) specifies an 8-bit integer seed used to select a path in the noise texture.

Compatibility

The DefaultParticleRenderer is compatible with the DefaultParticleUpdater in the sense that their usages of each particles userData does not conflict.

The DefaultParticleRenderer is assumed when using the DefaultParticleEmitter object.

Additionally any particle animations must use the default system for ParticleBuilder.compile supporting animation of particles rotation, color and scale, and supporting flip-book animations of particle appearances.

20.7.3.1. Methods

20.7.3.2. create

Summary

Create a DefaultParticleRenderer object.

Syntax

var renderer = DefaultParticleRenderer.create(graphicsDevice, shaderManager, alpha);
graphicsDevice
The GraphicsDevice object.
shaderManager
The ShaderManager object. The shader particles-default-render.cgfx must be loaded.
blendMode (Optional)
Rendering shader supports one of 3 blend modes: “alpha” (default), “additive” and “opaque”.

20.7.3.3. createUserData

Summary

Set up particles’ userData storage for creation.

Syntax

var userData = DefaultParticleRenderer.createUserData({
    facing: "custom",
    theta: 0.5,
    phi: Math.PI,
    randomizeOrientation: true,
    randomizeRotation: true,
    randomizeScale: true,
    randomizeAlpha: true,
    seed: seed
});
facing (Default “billboard”)
One of “billboard”, “velocity” or “custom”.
theta (Default 0)
Useful only in conjunction with custom facing. Defines the spherical angle of elevation, with 0 pointing along y-axis and Math.PI pointing along negative y-axis.
phi (Default 0)
Useful only in conjunction with custom facing. Defines the clockwise spherical angle of azimuth, with 0 pointing along x-axis.
randomizeOrientation (Default false)
Specify the particle to which this userData will be applied should have its orientation randomized.
randomizeScale (Default false)
Specify the particle to which this userData will be applied should have its scale randomized.
randomizeRotation (Default false)
Specify the particle to which this userData will be applied should have its rotation randomized.
randomizeAlpha (Default false)
Specify the particle to which this userData will be applied should have its alpha randomized.
seed (Default 0)
The 8-bit integer seed to write to the userData.

Note

The seed parameter should be ignored when creating userData values for ParticleArchetypes, as it is the responsibility of the emitter to initialize the seed to a random value for each emitted particle.

20.7.3.4. setAnimationParameters

Summary

Set up extra shader parameters required to de-normalize attributes of the particles animations when rendering.

Syntax

renderer.setAnimationParameters(system, animationDefn);
system
The ParticleSystem onto which the parameters should be set, affecting its renderParameters object.
animationDefn
The resultant object returned from ParticleBuilder.compile.

20.7.3.5. Parameters

The list of technique parameters exposed by the DefaultParticleRenderer. Unless otherwise stated these are the same as the parameters supported by a ParticleArchetype using this renderer.

noiseTexture

The noise Texture to be used for randomizing appearance of particles. This noise texture should be a 4-channel smooth noise such as textures/noise.dds present in the SDK.

The particles current age will be used to look up randomized values in the texture along a pseudo-random path, therefore a higher frequency noise texture will produce higher frequency fluctuations in the randomized values used to alter the particles appearances.

Vectors are extracted from the noise texture based on treating channels as encoded signed floats (As-per TextureEncode.encodeSignedFloat).

Default value is a procedural texture defined so that no randomization will occur (ParticleSystem.getDefaultNoiseTexture)

Note

For a ParticleArchetype, this field should be a string path to the texture to be retrieved from the TextureManager rather than a real Texture object.

randomizedOrientation (Default [0, 0])

A Vector2 defining the maximum amount of randomization applied to particles orientations in spherical coordinates.

randomizedScale (Default [0, 0])

A Vector2 defining the maximum amount of randomization applied to particles scale (width/height).

randomizedRotation (Default 0)

A number defining the maximum amount of randomization applied to particles spin-rotation.

randomizedAlpha (Default 0)

A number defining the maximum amount of randomization applied to particles alpha.

animatedOrientation (Default false)

A boolean flag defining whether the randomization of particle orientations is fixed, or animated over time.

If true then the randomization will change over time according to the noise texture, otherwise only an initial sample will be made to the noise texture fixing the randomization that is applied.

animatedScale (Default false)

A boolean flag defining whether the randomization of particle scales is fixed, or animated over time.

If true then the randomization will change over time according to the noise texture, otherwise only an initial sample will be made to the noise texture fixing the randomization that is applied.

animatedRotation (Default false)

A boolean flag defining whether the randomization of particle rotations is fixed, or animated over time.

If true then the randomization will change over time according to the noise texture, otherwise only an initial sample will be made to the noise texture fixing the randomization that is applied.

animatedAlpha (Default false)

A boolean flag defining whether the randomization of particle alphas is fixed, or animated over time.

If true then the randomization will change over time according to the noise texture, otherwise only an initial sample will be made to the noise texture fixing the randomization that is applied.

texture

The Texture object, with each animations flip-book of textures packed together.

Note

This parameter is not supported on a ParticleArchetype description.