Rendering Blobby Volumes as Clouds

return to main index



This tutorial demonstrates a technique for converting a polymesh to a Blobby volume primitive for the purpose of rendering cloud-like objects . The code used for the technique is an extension of mel presented in the tutorial,
    "RfM: Polymesh converted to a Blobby"
The Blobbies generated by that tutorial can only be rendered as a regular "surface" primitive - figures 1 and 2.

Figures 1 & 2
Original polymesh converted to a Blobby with jittered (blobby) locations.

The code provided in this tutorial can define a volumetric Blobby that can be rendered at different levels of "density" - figures 3 to 5.

Figures 3, 4 & 5

The User Interface

The code that implements the user interface (UI) and RenderMan Interface (RI) components are contained in the following three scripts that are in the cloudy.zip download.


They should be saved in the readers RfM_mel directory - as explained in the tutorial, "RfM: Customizing". The mesh2CloudUI.rman script defines the interface shown below.

The "Pre Shape MEL" text field references the main proc in the mesh2CloudRI.mel script and as such its text should not be edited.
The "Blobby Size" slider controls the radius of the individual blobs. Its value will largely depend on the scale of the polymesh that defines the distribution of the blobs.
The "Height Offset" slider controls the vertical offset of each blob. When set to 1.0 the blobs are at their "true" position; when set to 0.0 their Y coordinates will be set to zero. This slider controls the extent to which a cloud callapses onto itself.
The "Jitter" slider applies a random XYZ offset to the vertex positions that define the locations of the blobs.
The "Previs" checkbox enables the Blobby to be rendered as a non-volume primitive using prman's defaultsurface shader. The checkbox temporarily overrides the "Convert to Volume" option.

Figure 6

The "Duplicates" slider will cause duplicate rib archives that define the Blobby to be rendered - a fairly useful, albeit expensive, way of increasing the density of the final cloud.

Shading Controls

The "PrimVars" text fields accepts the names and values of primvars. The sample shader given below has three parameters that can be controlled by primvars, namely, "Kd", "freq" and "falloff". The shader also responds to the primitive variables "Cs" and "Os".

Listing 4 (cloudy.sl)

cloudy( float   Kd = 1;
        float   noiseFreq = 2;
        float   noiseContrast = 1.2;
        float   opacityContrast = 1.5;
        string  noiseSpace = "shader")
point pp = transform(noiseSpace, P);
float ns = noise(pp  * noiseFreq);
ns += (noise( pp * noiseFreq * 2) - 0.5) * 0.5;
ns += (noise( pp * noiseFreq * 4) - 0.5) * 0.3333;
ns = pow(ns, noiseContrast);
// Using VolumeField is only meaningful with a Blobby.
// It allows the shader to ramp down the opacity near
// to the edge of the primitive.
color c = 0;
illuminance(P) {
    c += Cl;
float grayscale = (c[0] + c[1] + c[2]) * 0.3333;
grayscale = pow(grayscale, opacityContrast);
Oi = VolumeField * ns * Os * grayscale;
Ci = Oi * Cs * Kd;
// optionally we could use the light color
// Ci = Oi * Cs * c * Kd;

The values of the primvars can be specified singularly or as a range. For example, if the polymesh has 50 vertices the Blobby will have the corresponding number of "blobs". The following text
    "Cs" [1 1 1];
will repeat the sequence of rgb values 50 times, one for each blob. However, if this text is used
    "Cs" [1 1 1] [.9 .9 0.8];
then a sequence of randomized red and green values in the range red 0.9 to 1.0, and blue values in the range 0.8 to 1.0, will be specified for the primvar. Lists of primvars must be separated by semi-colons (";"). The open and close brackets for the primvar values are optional.

Primvars can help to create more visually interesting clouds. For a basic introduction to primvars refer to the tutorial "RIB/RSL: Introduction to Primvars".


1    The scripts given in listings 1, 2 and 3 should be saved in the readers RfM_mel directory
      - see, "RfM: Customizing".
2    Compile the shader given in listing 4.
3    In Maya, create a polymesh, select it and run the following command,
4    In HyperShade load the shader and assign it to the polymesh.
5    Add a spotlight, assign it a deep shadow map and set the map size to 128 pixels.
6    Some experimentation will be required to set the appropriate
      "Blobby Size"and "Jitter"
      for the polymesh.

© 2002- Malcolm Kesson. All rights reserved.