RSL
Trace Sets


return to main index



Introduction

Several RSL functions, such as occlusion(), have a "subset" parameter ( listing 1, line 12) that forces the renderer to selectively recognize surfaces that have been tagged as members of named groups, known as trace-sets.


Listing 1


surface
rt_occlusion(string bakename = "",
                    subset = "";
             float  samples = 256,
                    coneangle = 80;
    output varying float _occlusion = 0)
{
normal     n = normalize(N);
  
_occlusion = 1 - occlusion(P, n, samples, 
                    "coneangle", radians(coneangle),
                    "subset", subset);
Oi = Os;
Ci = Oi * Cs * _occlusion;
}

Surfaces that are not part of the named group(s) are ignored. A simple scene, listing 2, is used to illustrate the use of trace-sets for occlusion.


Listing 2


DisplayChannel "float _occlusion"
Display "untitled" "framebuffer" "rgb"
Format 384 216 1
Projection "perspective" "fov" 40
  
ShadingRate 1
Translate  0 0 5
Rotate -30 1 0 0
Rotate 0   0 1 0
Scale 1 1 -1  
WorldBegin
    Attribute "visibility" "trace" [1]
    Attribute "visibility" "transmission" ["opaque"  
    AttributeBegin  
        Attribute "grouping" "membership" ["left"]
        Translate -1.05 1 0
        Surface "rt_occlusion" "subset" [""] 
        ReadArchive "nSphere.rib"
    AttributeEnd
    AttributeBegin  
        Attribute "grouping" "membership" ["right"]
        Translate 1.05 1 0
        Surface "rt_occlusion" "subset" [""] 
        ReadArchive "nSphere.rib"
    AttributeEnd
    AttributeBegin
        Attribute "grouping" "membership" ["floor"]
        Scale 10 10 10
        Surface "rt_occlusion" "subset" [""] 
        Polygon "P" [-0.5 0 -0.5   0.5 0 -0.5  
                      0.5 0  0.5  -0.5 0  0.5]
    AttributeEnd
WorldEnd

Membership of a trace set is assigned with this rib statement,

    Attribute "grouping" "membership" ["GROUP_NAME"] 

Using trace-sets can be a little tricky. For example in listing 2 two of the "subset" parameters specify an empty string ie. no group name. In effect, those objects in the scene is "telling" the occlusion shader to ignore the other surfaces. Hence, the all white rendering of figure 1.



Figure 1


In the following code snippet, the group name passed to the "subset" parameter ensures the sphere will only show occlusion caused by objects with that group name.

    Surface "rt_occlusion" "subset" ["NAME_OF_OCCLUDERS "]
    Sphere 1 -1 1 360 

The next four listings and figures show the effects of a variety of subsets.


Listing 3


AttributeBegin  
    Attribute "grouping" "membership" ["left"]
    Translate -1.05 1 0
    Surface "rt_occlusion" "subset" ["floor"] 
    ReadArchive "nSphere.rib"
AttributeEnd
AttributeBegin  
    Attribute "grouping" "membership" ["right"]
    Translate 1.05 1 0
    Surface "rt_occlusion" "subset" ["floor"] 
    ReadArchive "nSphere.rib"
AttributeEnd
AttributeBegin
    Attribute "grouping" "membership" ["floor"]
    Scale 10 10 10
    Surface "rt_occlusion" "subset" [""] 
    Polygon "P" [-0.5 0 -0.5   0.5 0 -0.5  
                  0.5 0  0.5  -0.5 0  0.5]
AttributeEnd




Figure 2
Spheres occluded only by the floor


Listing 4


AttributeBegin  
    Attribute "grouping" "membership" ["left"]
    Translate -1.05 1 0
    Surface "rt_occlusion" "subset" ["floor"] 
    ReadArchive "nSphere.rib"
AttributeEnd
AttributeBegin  
    Attribute "grouping" "membership" ["right"]
    Translate 1.05 1 0
    Surface "rt_occlusion" "subset" ["floor"] 
    ReadArchive "nSphere.rib"
AttributeEnd
AttributeBegin
    Attribute "grouping" "membership" ["floor"]
    Scale 10 10 10
    Surface "rt_occlusion" "subset" ["right"]
    Polygon "P" [-0.5 0 -0.5   0.5 0 -0.5
                  0.5 0  0.5  -0.5 0  0.5]
AttributeEnd




Figure 3
The floor occludes both spheres but is only occluded by the right sphere


Listing 5


AttributeBegin  
    Attribute "grouping" "membership" ["left"]
    Translate -1.05 1 0
    Surface "rt_occlusion" "subset" ["floor"]
    ReadArchive "nSphere.rib"
AttributeEnd
AttributeBegin  
    Attribute "grouping" "membership" ["right"]
    Translate 1.05 1 0
    Surface "rt_occlusion" "subset" ["floor,left"]
    ReadArchive "nSphere.rib"
AttributeEnd
AttributeBegin
    Attribute "grouping" "membership" ["floor"]
    Scale 10 10 10
    Surface "rt_occlusion" "subset" ["left,right"]
    Polygon "P" [-0.5 0 -0.5   0.5 0 -0.5  
                  0.5 0  0.5  -0.5 0  0.5]
AttributeEnd




Figure 4
The sphere on the right is occluded by the left sphere and the floor, but the left sphere ignores the right sphere


Listing 6


Surface "rt_occlusion" "subset" ["all "]
AttributeBegin  
    Attribute "grouping" "membership" ["all,left"]
    Translate -1.05 1 0
    ReadArchive "nSphere.rib"
AttributeEnd
AttributeBegin  
    Attribute "grouping" "membership" ["all,right"]
    Translate 1.05 1 0
    ReadArchive "nSphere.rib"
AttributeEnd
AttributeBegin
    Attribute "grouping" "membership" ["all,floor"]
    Scale 10 10 10
    Polygon "P" [-0.5 0 -0.5   0.5 0 -0.5  
                  0.5 0  0.5  -0.5 0  0.5]
AttributeEnd




Figure 5
Now the objects share a common group




© 2002- Malcolm Kesson. All rights reserved.