The Sprite Shader

This is a special shader designed to allow particle-dependent effects to be applied to X-Particles sprites. It will also affect objects produced by the Generator object but particle-dependent effects are not possible with such objects. The shader only affects sprites at render time and its effects are not visible in the editor.

For more details, see the section 'Using the Sprite Shader' below.

Interface

This is the shader's interface:

For the buttons at the bottom of the interface, please see the 'Common interface elements' page.

Parameters

Note: although we talk about colour in the details below, remember that this shader can also be used in channels such as transparency, bump, displacement, etc.

Emitter

This link field accepts an X-Particles Emitter which you drag in from the object manager. The shader obtains data on particle age, etc. from this emitter, so without it you cannot make any changes to the shader. If placed in the colour channel the shader will render sprites white in the absence of an emitter.

Mode

This drop-down menu has five options:

Use Particle Color

The sprites will have the same colour as the particle. This is particularly useful if the particles were emitted from a texture and took their colour from that texture.

Random Color

The sprites will each have a randomly-selected colour.

Note: if you select this option the sprites may have an odd speckled colour if rendered in the preview render (i.e. the interactive renderer). This is only in the preview render and is not seen if you render the scene to the editor or picture viewer.

Random (From Gradient)

This option will enable the Color gradient and will randomly colour the sprites using a colour taken from the gradient.

Parameter-Dependent

Sprites will be coloured using colours taken from the Color gradient, the colour depending on the particle parameter selected.

Modifier Sets Value

In this mode the color values are set by the Sprite Shader modifier. For more details, see the explanation below.

Color Gradient

The colour is chosen from this gradient when 'Mode' is set to 'Random (From Gradient)' or 'Parameter-Dependent'.

Particle parameter

This enables you to select the parameter used for determining the colour from the Color gradient. There are five options:

Particle Life

This is the most commonly-used option. It selects a gradient colour using the age of the particle compared to its lifespan. Brand-new particles are coloured with the colour from the left of the gradient, while particles at the end of their life are coloured with a colour from the right of the gradient.

Age

This is a simple cutoff switch which changes the particle colour when it reaches the age give in the Minimum age setting (see below). As an example, if you had a blue-to-white gradient, and entered '40' into the 'Minimum Age' field, particles with an age of less than 40 would be coloured blue, while those of age 40 or above would be coloured white. There is no transition, just a one-step change.

Age Range

This is similar to Particle life, but instead of the colour changing over the entire life of the particle, the colour changes between the values in the Minimum age and Maximum age settings. So with the blue-to-white gradient, if 'Minimum Age' is set to 30 and 'Maximum Age' to 60, all particles with age under 30 would be blue, all particles aged over 60 would be white, and those from 30 to 60 would be coloured with a colour from the gradient depending on their age.

Speed

Similar to Age, but using particle speed instead. Particles with a speed less than that in the 'Minimum Speed' field are coloured using the colour at the left-hand edge of the gradient, those with a speed greater than this with the colour from the right-hand edge of the gradient. There is no transition, just a one-step change.

Speed Range

Similar to 'Age Range' but using speed instead. The speed range is obtained from the 'Minimum Speed' and 'Maximum Speed' values.

Invert Effect

This button simply reverses the colour selection from the gradient so that when the colour would normally be taken from the left of the gradient, when this button is checked the colour from the right of the gradient is used instead, etc.

Minimum Age, Maximum Age

Used for the Age and Age Range parameters (see above).

Minimum Speed, Maximum Speed

Used for the Speed and Speed Range parameters (see above).

Texture

This is only available when the Parameter-Dependent mode is selected. You can put any other Cinema 4D channel shader, or a bitmap, in here. The colour returned from this shader or bitmap will blend with the Gradient color according to the Blend mode setting.

A common way of using this setting is to set the Gradient color to a black-to-white gradient and the Blend mode setting to multiply. This will cause the colour to get brighter as the particle ages (if you chose the Particle Life parameter, for example). If you just want to use the colour from the texture without blending with the gradient, just set the gradient to be plain white and Blend to multiply. But then, of course, you lose all the parameter dependent effects so you needn't have bothered with the sprite shader in the first place!

Blend Mode

This setting selects how the Texture blends with the Color gradient. There are three modes, which are the same as in other Cinema 4D shaders:

  • Multiply: the most common setting; the two colours are multiplied together.
  • Add: the colours are added together. The result will be clamped at white.
  • Subtract: the gradient colour is subtracted from the texture colour. The result will be clamped at black.

Using the shader

This shader gives you extensive control over the material applied to a sprite. It does this by varying the colour (or transparency, or whichever channel you choose) according to selected attributes of each particle.

For example, you can easily change the sprite colour over the particle’s lifetime, or change its transparency over a specified age range, or its alpha channel when a particle exceeds a certain speed.

To use the shader, add it to any material channel which can take shaders. You will find it in the ‘X-Particles’ sub-menu in the material editor interface's shader list. You can also add it to a Cinema 4D Layer or Filter shader or any other shader you like.

Because the shader depends on data from the particle emitter which is not available until the animation is played, the particles will appear white in the editor; the colours used will only appear when each frame is rendered.

Using 'Modifier Sets Value'

Using this mode can be a little confusing. What happens is that the Sprite Shader Modifier changes the colour value to use, but it needs to be set up correctly in order to work

Assume you have a scene with a sprite object, a material applied to it with a Sprite Shader in the Color channel, mode set to 'Modifier Sets Value' and a Sprite Shader Modifier in the scene with the mode is set to 'RGB'. When you play and render the animation, the sprites will be plain white with no colour change over time. Why?

The default colour set by the Sprite Shader is white. The modifier will, by default, increment the colour. However (again by default) the colour is clamped to white in the modifier. Since the sprite colour is already white, nothing happens. In the modifier, now set the Green and Blue rates of change to zero, and the Red to -2%. Then set 'Clamp To' to black. When you render, you will see that the sprite colour changes from white to cyan, as the red is reduced to zero leaving only green and blue.

If you want to set the rates of change to a positive value, to have any effect the colour must start out less than white. So, change the Red rate of change to 2%, change the 'Clamp To' colour to white, and in the Sprite Shader add a Color shader to the 'Texture' slot. Set this colour to black. This will mean that the sprites start black, and the red component increases so that the sprites turn bright red.