RSL
|
IntroductionThis tutorial presents the code for a shader that generates an animated pattern based on the principles of Conways Game of Life, so-called 2D cellular automata (CA). A full, or even a partial, discussion of cellular automata is beyond the scope of this tutorial. It is, therefore, assumed the reader has at least some familiarity with the basic concepts of CA. A static image of cellular automata is of little visual interest, only when animated does their complex behavior become apparent - figure 1. Cellular automata are generally displayed as a pattern of cells. The cells seen above are represented by the micropolygons into which prman has diced a surface. The 2 by 2 polygon shown above had a ShadingRate of 62 and was rendered using orthographic projection - listing 1. The shading rate yielded a pattern of 32 by 32 cells ie. micropolygons. Listing 1 - celluar.rib
The Rules of the Game of LifeEach cell (ie. micropolygon) can be in one of two states, either alive or dead. White cells are those considered to be alive; black cells are those that are dead. The state of a cell, say at frame 10, depends on the state of the cells that surrounded it on frame 9. In short, a cell lives, dies or a dead cell becomes alive depending on how many of its neighbors, in the previous frame of animation, were alive (possible overpopulation) or dead (possible underpopulation). These are the rules of the game of life. Shading IssuesBecause the renderer cannot be queried about the "previous" condition of a micropolygon it is impossible, without some trickery, to implement a shader that mimics the behavior of cellular automata. However, point clouds provide an opportunity to record the condition of a micropolygon so that it can be queried in a subsequent frame of animation. The technique presented here relies on the use of two point clouds. From one point cloud, "old.ptc", it reads data that was baked during the previous frame of an animation. Into the other point cloud, "new.ptc", it writes data that will be used in the next frame of animation. AlgorithmOn the first frame of an animation the shader, for each micropolygon,
On all subsequent frames, again for each micropolygon, the shader,
After each frame of animation the data in "old.ptc" is overwritten by
"new.ptc".
Data written to a point cloud is "bound" to the shading point
float stepSize = sqrt(area(P)); but it gave poor results. |
Listing 2 - cellular.sl
|
Trial and Error
Determining the value of the "count" shader parameter
for a particular Format 300 300 1
generates an image with 40x40 cells.
A sample keyframe file is shown below. Don't forget to set
Listing 3 - cellular.key
The animation generated by cellular.key is shown below. |
© 2002- Malcolm Kesson. All rights reserved.