Caffeine Abuse - The Blog

Particle sprites using ICE

Sprites are images or sequences of images which you map onto a surface, usually with an alpha channel, to create the illusion of a three-dimensional object or volume. Typical use of sprites includes populating trees with thousands of leafs or creating fire and smoke effects, as this is much more cost effective than rendering  instances of the actual objects or using volume clouds. And in most situations you wouldn’t be able to spot the difference anyway.

From the Get > Primitive > Polygon Mesh menu choose Grid. From the Simulate > ICE > Create menu choose Emit Particles from Selection. With the PointCloud selected, press [Alt] + [9] to open an ICE Tree View. Open the Emit from Surface node’s PPG and decrease the Rate to 10, set the Shape to Rectangle and the Size to 1. Close the PPG. In order to be able to use different textures for the particles, you need to give each particle an custom attribute telling which texture (or material) to use. Open the Preset Manager View and Get a Randomize Value by Range node. Leave the default values as they are. The Randomize node outputs a scalar value (meaning it also holds decimals) so you need to round the output to the nearest integer. Get a Round node and connect the Value output of the Randomize Value by Range node to the Value input of the Round node. Get a Set Data node, open its PPG and enter Self.SpriteID as the Reference. Connect the Integer output of the Round node to the SelfSpriteID input of the Set Data node. Connect the Set Data node to the Execute on Emit1 input of the Emit from Surface node. Close the ICE Tree View.

Let the animation play for a few frames to emit some particles. With the PointCloud still selected, from the Get > Material menu choose any shader to apply a local material. Press [7] to open an Render Tree.  Get an Integer Attribute node and a Color Multi-Switch node. The Color Multi-Switch node enables you to use multiple textures or materials and switch between them based on the integer value specified in the PPG. Connect the Integer Attribute node to the Switch input of the Color Multi-Switch node and the Color Multi-Switch node to the Surface and Shadow input of the Material node. Open the Integer Attribute node’s PPG and set the Attribute to SpriteID.

Get an Image node and open its PPG. Click the New button and select the Sprite_Zero.tga image from the projects folder. Close the PPG and get a Sprite node. Connect the Image node to the input of the Sprite node and Sprite Output to the Input0 of the Color Multi-Switch node. The Sprite node will automatically use the alpha channel of the image to define its transparency. Repeat the last step three more times and connect the input1, input 2 and input 3 of the Color Multi-Switch node.

The project files used in this tutorial can be found at: http://dl.dropbox.com/u/3834689/CaffeineAbuse/PatrticleSprite_using_ICE.zip

ICE_Sprites_img02

Sprites was invented as a way to composite multiple 2D images on top of each other and originally required a specialized hardware. The technique was early adopted by the games and CGI industry as a cost effective way to give the illusion of 3D by mapping a 2D texture onto a 3D plane.

Quick tip
More often than not you want the sprites to face the camera, aka Billboarding. To do so, open the ICE Tree and get an Align Particle to Camera node. Open its PPG and select the camera you want the sprites to be aligned to and connect the node to the Port2 of the ICETree node.