RfM Ribbox
Lights On Particles (Reyes)


return to main index



Introduction

This tutorial demonstrates how two Ribboxes attached to two shading groups can be used to create an effect that might be difficult or impossible to achieve using Maya's standard tools. The workflow outlined in this tutorial produced an animation of nearly 400 point lights "parented" to a particle system - figure 1.


Figure 1

The reader should review the following tutorials,

    RfM Ribbox: Volumetric Spotlight Effects
    RfM Ribbox: Chain On Curve


Why Use Two Ribboxes?

Instancing a light at particle positions using TCL is not difficult - listing 1. However, because RfM writes the rib information about a particle system into an AttributeBegin / AttributeEnd block it means that lights "created by" the particles have no effect outside of the block. For example,


AttributeBegin
    # List of lights created by a TCL script
    TransformBegin
        Translate x y z # position of particle 1
        LightSource "pointlight" 1
    TransformEnd
    TransformBegin
        Translate x y z # position of particle 2
        LightSource "pointlight" 3
    TransformEnd
    Attribute "visibility" "int camera" [0]
    TransformBegin
        ReadArchive "path_to_particle_archive"
    TransformEnd
AttributeEnd
# WOOPS! Previous lights are now INACTIVE
AttributeBegin
    TransformBegin
        ReadArchive "path_to_an_object"
    TransformEnd
AttributeEnd

Consequently, in order for surfaces to be effected by the "particle lights" they must have a Ribbox assigned to their shading group or groups. The role of the additional Ribbox is to inject into the rib stream a sequence of Illuminate statements that, in effect, re-activate the lights parented to the particle system.


AttributeBegin
    ArchiveBegin "_ribbox_"
        Illuminate 1 1
        Illuminate 2 1
        ditto...   
    ArchiveEnd 
    ReadArchive "_ribbox_" 
    # Now the lights in the particle Attribute block are ACTIVE
    TransformBegin
        ReadArchive "path_to_an_object"
    TransformEnd
AttributeEnd


The Script

The TCL script shown in listing 1 (ParticleUtils.tcl) should be copied to the users custom TCL scripts directory that is sourced by RenderMan Studio. Suggestions on how this can be done can be found in the tutorial,
    "RfM: Customizing"

The following LoadExtension line should be added to the users custom RfM.ini file.


set tclDirectory /Users/$USER/Documents/maya/projects/RfM_tcl
# Load the customed TCL procs for use in Ribboxes
LoadExtension tcl [file join $tclDirectory ParticleUtils.tcl]


Listing 1 (ParticleUtils.tcl)


# M.Kesson
# Oct 2012
#
# "addLight" and "activateLights" must be used in two shadinggroup
# ribboxes. The first is assigned to a particle system. The second
# should be assigned to a surface or surfaces that will be illuminated
# by the lights that "addLight" will instance for each particle
# in the system.
# The shadinggroup ribbox assigned to the particles should have the
# following command,
#   [addLight $OBJNAME 0.005]    
proc addLight { tnode { intensity 0.1 } } {
    global ::count
    set ::count 0
    set num  [mel "particle -q -ct $tnode"]
    set out ""
    for {set n 1} {$n <= $num} {incr n} {
        set str $tnode
        append str ".pt\[$n\]"
        set pnt [mel "getParticleAttr -at position $str"]
        set x   [lindex $pnt 0]
        set y   [lindex $pnt 1]
        set z   [lindex $pnt 2]
        append out "TransformBegin\n"
        append out "    Translate $x $y $z\n"
        append out "    LightSource \"pointlight\" $n \"intensity\" $intensity \"from\" \[0 0 0\]\n"
        append out "    Illuminate $n 0\n"
        append out "TransformEnd\n"
        incr ::count
        }
    append out "Attribute \"visibility\" \"int camera\" 0\n"
    return $out
    }
    
# The shadinggroup ribbox assigned to the surface(s) to be illuminated
# by the particle lights should have the following command in its ribbox.
#   [activateLights]    
proc activateLights { } {
    global ::count
    set out ""
    for {set a 1} {$a <= $count} {incr a} {
        append out "Illuminate $a 1\n"
        }
    return $out
    }
::RMS::LogMsg INFO "Custom TCL procs in ParticleUtils.tcl loaded"


Workflow

Step 1

Create an emitter. Provide the particles with a limited lifetime. Move the timeline and generate a few particles. Select the particles, then choose the transform tab in the Attribute editor.

Step 2

From the Attributes menu select,
    Attributes->RenderMan->Add Custom Shading Group.
The default initialShadingGroup will be automatically assigned.

Step 3

Select the intialShadingGroup tab and from the Attributes menu select,
    Attributes->RenderMan->Add RIB Box
Select RIB Box Interpolation TCL.

Step 4

Enter the following code in the Ribbox,
    [addLight $OBJNAME 0.005]
The pre-defined variable OBJNAME will be automatically substituted by the name of the particle system. The parameter (0.005) will set the intensity of each light that the proc addLight instances for each particle. Some experimentation will be required before an appropriate value is chosen.


Step 5

Find the shading group(s) of the surface or surfaces to be illuminated by the particle lights. From the Attributes menu select,
    Attributes->RenderMan->Add RIB Box
Select RIB Box Interpolation TCL.

Step 6

Enter the following code in the Ribbox,
    [activateLights]

Step 7

Because the particle lights use the classic "pointlight" shader copy its file from,

    RfM_INSTALLATION_DIR/lib/shaders/pointlight.slo

to the project directory that Maya is currently referencing.

Step 8

Open the Outliner and make sure the particle and the emitter appears before the geometry that will be illuminated by the lights created by the particles.



Possible Issues with RfM Batch Render

If the rendered images obtained from using the Batch Render button
     
on the RenderMan shelf are different to the images rendered using the Render button
     
the best way of discovering the cause of the error is to render one of the "root" rib files in the batch render directory. For example, suppose the scene name is foo the "root" rib for frame 1 will be,

    renderman/foo_1122110312/rib/0001/0001.rib

Open "0001.rib" in Cutter and use control+e, alt+e or Apple+e to render the frame. Look for errors reported in Cutter's Process Monitor. For example, a typical error might be,

    Cannot find: slim/shaders/foo_1122110312/BaseVolume.slo

One way to fix such a problem is to edit the path to the shader in the attribute editor. For example, change $STAGE to the explicit name of the scene.









© 2002- Malcolm Kesson. All rights reserved.