A Rendered Candy Cane

Using the renderman shading language it is easy to let the texture follow the surface of an object because all surfaces (except polygons) are parametrized by two coordinates s and t, running from 0 to 1 over the whole surface. The shading language allows you to use arbitrary functions of these (and several other) variables to describe the appearance of the surface. Here is a simple example, a candy cane with two colors spiraling around it.


This image generated from candy.rib uses four geometric primitives: two disks, a torus and a cylinder, each with their own parameter space. My first attempt used two different shaders because the cylinder and the torus have different parametrizations (I had to turn the cylinder by 90 degrees to make it fit to the torus, so the parameters are perpendicular too). Larry Gritz pointed out that it is easier to add another parameter ts to the shader so that only one shader is required: FHSpiral.sl.

Once the parametrization is done properly, you can easily add other features to the surface. The most obvious thing is to change the very smooth, plastic appearance and add a slightly irregular pattern to the normals. This is done with two and a half additional lines in the shader FHSpiral2.sl:


In POVRay you must either use several image_maps (which are difficult to generate in a way so that they connect smoothly on the borders between different parts of the object) or build the object from appropriately colored smaller objects. A candy-cane in POV, contributed by Steve Houchen, uses 360 checker-colored cylinders to produce the spiraling colors:


This gives reasonable results for low resolutions, but an increase in resolution reveals the disadvantages of this approach:

candy4.jpg candy5.jpg

Florian Hars <florian@hars.de>, 2007-10-15 (orig: 1999-02-27)