RfM Ribbox
Volume Primitives (Reyes)


return to main index



Introduction

The current version of RenderMan Studio (4.0) does not provide a direct way of rendering RenderMan volume primitives. This tutorial provides a relatively easy way of rendering a sphere, cone, cylinder or cube (polygonal or nurbs) as a volume - figure 1.


   
Figure 1
A polygonal sphere rendered as a RenderMan Volume ellipsoid.


The TCL Proc

The technique employs a ribbox assigned to the shading group of an object such as a poly sphere. The ribbox calls a TCL proc that queries the name of the shape node to which the shading group is assigned and based on the name, say "pSphereShape1", and the size of its bounding box it generates a few of lines of rib that RfM inserts into a payload of a RenderMan Look File (.rlf). For example,

    #ribbox: BaseVolumeSG
    ArchiveBegin "_ribbox_"        
        Rotate -90 1 0 0 
        IfBegin "$user:pass_class == 'Final'"
            Volume "ellipsoid" [-1.0 1.0 -1.0 1.0 -0.951055 0.951055] [2 2 2]
        Else
            #Volume "ellipsoid" [-1.0 1.0 -1.0 1.0 -0.951055 0.951055] [2 2 2]
        IfEnd
        Attribute "visibility" "camera" 0 
    ArchiveEnd 
    ReadArchive "_ribbox_" 

The code for the proc is given next.


Listing 1 (VolumeUtils.tcl)


# This TCL proc renders a Sphere, Cone, Cylinder or Cube volumetrically.
# 1  Create poly cube.
# 2  Open Slim. Create a base volume node and set its density color to hsv
#     values 1.0 1.0 0.1. Click on the node and choose "Add to Scene".
# 3  Assign the BaseVolume shader to the cube.
# 4  Select the BaseVolumeSG tab and choose,
#        Attributes->RenderMan->Add RIB Box
# 5  Change RIB Box Interpolation from "None" to "TCL".
# 6  Enter the following code into the Rib Box,
#         [volume]
# 7  Render the scene.
proc volume { { deep_shd_vis 0} } {
    upvar OBJNAME tnode 
    set type "cube"
    # Guess what kind of volumetric primitive the user
    # needs based on the name of the transform node.
    if {[string match "*Sphere*" $tnode]}   { set type "ellipsoid" }
    if {[string match "*Cone*" $tnode]}     { set type "cone" }
    if {[string match "*Cylinder*" $tnode]} { set type "cylinder" }        
    set bb [mel "getAttr $tnode.boundingBoxSize"]    
    set w [expr double([lindex $bb 0])/2]
    set h [expr double([lindex $bb 1])/2]
    set d [expr double([lindex $bb 2])/2]
    set gprim "Volume \"$type\" \[-$w $w -$h $h -$d $d\] \[2 2 2\]"
    set cmnt "#" 
    if {$deep_shd_vis} {
        set cmnt ""
        }
    if {[string equal $type "cube"]} {
        set rib ""
    } else {
        set rib "Rotate -90 1 0 0 \n"
        }
    append rib "IfBegin \"\$user:pass_class == 'Final'\"\n"
    append rib "    $gprim\n"
    append rib "Else\n"
    append rib "    $cmnt$gprim\n"
    append rib "IfEnd\n"
    append rib "Attribute \"visibility\" \"camera\" 0 \n"
    append rib "# $tnode\n"
    return $rib
    }


Workflow

Step 1

Create poly cube.

Step 2

Open Slim. Create a base volume node and set its density color to hsv values 1.0 1.0 0.1. Click on the node and choose "Add to Scene"..

Step 3

Assign the BaseVolume shader to the cube.

Step 4

Select the BaseVolumeSG tab and choose,
    Attributes->RenderMan->Add RIB Box

Step 5

Change RIB Box Interpolation from "none" to "TCL".

Step 6

Enter the following code into the Rib Box,
    [volume]

Step 7

Render the scene.



Ribbox Behavior

Prior to RMS version 4 the rib generated by a ribbox was inserted directly into the output rib stream immediately before the geometric description of a surface. This provided a opportunity for a ribbox to generate rib statements customized for each surface that shared a shading group.

With the introduction of RenderMan Look Files the "one shading group, one ribbox but many different shading effects" scenario has been lost. Consequently, if a Maya scene has a single cone, sphere and cube, or multiple copies thereof, then three shading groups must be created, one for each of the shapes or groups of shapes.



Using Multiple Procs

Figure 2 shows a poly cube illuminated by point lights generated by a particle system and rendered volumetrically. The lights are created by a TCL proc given in the tutorial RfM Ribbox: Lights On Particles.



Figure 3


The BaseVolumeSG assigned to the cube had a ribbox containing calls to two TCL procs.

    [activateLights]
    [volume]

In particular, notice that each call is within open and close square brackets.






© 2002- Malcolm Kesson. All rights reserved.