Rib & Rsl
Volume Rendering


return to main index



Introduction

Release 15 of prman introduced a new technique for rendering volumes using surface shaders rather than interior (volume) shaders. A description of the technique can be found at,
    RPS docs/volume_rendering.html
The technique can be applied to Blobbies and a new primitive called a "Volume", of which there are four,

    Volume "cylinder"     [-1 1 -1 1 -1 1] [2 2 2]
    Volume "ellipsoid"    [-1 1 -1 1 -1 1] [2 2 2]
    Volume "cone"         [-1 1 -1 1 -1 1] [2 2 2]
    Volume "cylinder"     [-1 1 -1 1 -1 1] [2 2 2]

This tutorial looks at a few of the issues relating to the specification and shading of a "box" volume primitive.


Values Within a Volume

By its very nature, the shape of a Blobby is defined by a 3D "cloud" of floating point values. The envelope that defines the shape of a Blobby encloses the values that are greater than zero. A surface shader rendering a volumetric Blobby has access to those values via a variable called VolumeField - useful for setting volumetric color and opacity.

Unlike a Blobby, the shape of a volume primitive is specified directly as "cylinder", "ellipsoid", "cone" or "box". Therefore, a surface shader assigned to a volume primitive cannot meaningfully use VolumeField, but must instead use values that have been explicitly assigned to the vertices of an imaginary lattice that fills the interior of a volume primitive.


An Example

Listing 1 provides a simple example of a "box" volume primitive that has a width and height of 2 units and a length of 4 units. It has a "lattice" of 3 x 3 x 3 divisions and consequently can have 27 values bound to it. The dark areas in figure 1 show (approximately) the effect of the lattice vertices that have been assigned a "density" value of 0.1.



Figure 1


The code for the simpleSmoke shader used to shade the "box" volume is given in listing 2. Of course a lattice with only 3 x 3 x 3 divisions can hardly be expected to yield interesting images.



Figure 2



Listing 1 (simpleBoxVol.rib)


Option "searchpath" "shader"  "@:../shaders"
Display "untitled" "it" "rgba"
Format 800 600 1
Projection "perspective" "fov" 30
ShadingRate 1
  
Translate  0 0.2 8
Rotate -27 1 0 0
Rotate 45  0 1 0
Scale 1 1 -1
WorldBegin
    TransformBegin
        LightSource "shadowspot" 1 "float intensity" 25 
                    "from" [1 5 1] "to" [0 0 0]
    TransformEnd
    Surface "simpleSmoke" "float minDensity" 0.09 "float Kfb" 2
    Attribute "shade" "float relativeshadingrate" [1]
    Volume "box" [-1 1 -1 1 -2 2] [3 3 3] 
                "varying float density" [
                 0.1 0.0 0.0  0.0 0.0 0.0  0.0 0.0 0.0 # v1  to v9
                 0.0 0.0 0.1  0.0 0.0 0.0  0.0 0.0 0.0 # v10 to v18
                 0.0 0.0 0.0  0.0 0.0 0.0  0.1 0.0 0.0 # v19 to v27
                ]
WorldEnd



Listing 2 (simpleSmoke.sl)


surface
simpleSmoke( float Kfb = 1;
             float densityMult = 1;
             float minDensity = 0;
    varying  float density = 0)
{
color c = 0;
float d = 0;
  
illuminance(P) {
    c += Cl;
    }
  
if(density > minDensity)
    d = density * densityMult;
  
Oi = Os * d;
Ci = Oi * Cs * c * Kfb;
}

Although the archive (pre-baked) rib shown above is trivial, it does conform to the format of a correctly structured file. Apart from being much more complicated, archives generated by professional 3D applications such as Maya/RfM Pro or Houdini follow the same format. They also include commented text at the head of their archive files.


Rib File Using an Archive


Display "untitled" "framebuffer" "rgb"
Format 427 240 1
Projection "perspective" "fov" 40
ShadingRate 1
  
LightSource "distantlight" 1 "intensity" 1.5 
                    "from" [0 0 0] "to" [0 0 1]
  
Translate  0 -1 5
Rotate -30 1 0 0
Rotate 0   0 1 0
Scale 1 1 -1
  
WorldBegin
    Surface "plastic"
    TransformBegin
        Translate -1 0 0    
        ReadArchive "archive.rib"
    TransformEnd
    TransformBegin        
        Translate 0 0 0    
        ReadArchive "archive.rib"
    TransformEnd
    TransformBegin        
        Translate 1 0 0    
        ReadArchive "archive.rib"
    TransformEnd
WorldEnd







© 2002- Malcolm Kesson. All rights reserved.