Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

RiIfBegin ( RtToken expression )
RiElseIf ( RtToken expression )
RiElse
RiIfEnd

These calls form the basis of a simple conditional evaluation mechanism that allow RIB archives to be constructed with a degree of context sensitivity.

Normally the elements in a RIB archive are selected by the application that is authoring the archive. Complex logic and data manipulations are properly the domain of a true programming language with RenderMan Interface binding. When RIB variations are needed in these cases, they are regenerated by the authoring application.

However, sometimes a previously generated RIB archive is reused in a different context and it may need some internal ability to adapt to each context. These RIB archives allow chunks of "frozen" geometry or scene state to be stored and then accessed from a higher level "driver" RIB file. The archive can be reused from multiple places in the same frame or across multiple frames. For example, an object whose shape remains the same across many frames might be placed in an archive, it's position and orientation might be animated by specifying a different transformation matrix in each per-frame driver file before referencing the object's archive. This modularity has many benefits, including the potentially large savings in per-frame RIB generation time when the archived object is very complex.

There are situations in which it is very useful to allow certain internal aspects of an archive to be altered based on the current external driver file state or parameters. For example, the archive might select entirely different surface shaders depending on which "rendering pass" is active. The driver file might define the current pass with a user Attribute setting:

Attribute "user" "string renderpass" ["shadow"]
Procedural "DelayedReadArchive" ["archive.rib"] [0 1 0 1 0 1]

...

The conditional expressions evaluated by IfBegin and ElseIf are similar to those found in C and many scripting languages. The entire expression evalutes to a numeric result, and if the result is non-zero then the associated branch of the If-Else block becomes active. The expression operators work on values that are string or numeric literals, or renderer state variables. A typical set of arithmetic, relational, and logical operators are provided, plus a few additional functions:

State Variableslook up Attribute and Option values$name
Arithmetictake numbers, return numbers+ - * / **
Bit Maskbit-wise integer And, Or, Xor& | ^
Relational

take numbers or strings;
return 1 if the relation holds, 0 if it doesn't;
strings are compared using strcmp()

==  != < <= >= >
String Matchglob-style matching, the pattern can contain '*' and '?' wildcards.string =~ pattern
Logical

treats non-zero as true, zero as false;
return 1 if the logical assertion holds,
0 if it doesn't

&& || !
Grouping

(subexpression)
'string literal'

Variable Existence

returns 1 if the state variable exists,
0 if it doesn't

defined(name)

Concatenationcombines stringsconcat(string , string)
Computed Variable Nameslook up name given by subexpression$(subexpression)

State variable names are looked up by searching the Attribute stack, then the Options, then RendererInfo. The search can be restricted by prepending an additional "namespace" qualifier:

...

prman x.rib main.rib ---> renders a yellow matte sphere

prman y.rib main.rib ---> renders a magenta plastic sphere

x.rib

...

Attribute "user" "string abc" ["x"]

...

y.rib

...

Attribute "user" "string abc" ["y"]

...

main.rib

...

...


 ##RenderMan RIB

...


 version 3.03

...


 FrameBegin 1

...


 Format

...

128 128 1

...


 Display

...

"/tmp/t.tif" "tiff" "rgba"

...


 Projection "perspective" "fov" [45]

...


 WorldBegin
 LightSource "distantlight" 1 "from" [1 1 -1]

...



 Attribute "user" "float x1" [11]

...


 Attribute

...

"user" "float x2" [12]

...


 Attribute "user" "float y1" [101]

...


 Attribute "user" "float y2" [102]

...



 AttributeBegin
 Attribute "identifier" "name" ["mysphere"]

...


 Translate 0 0 2.75

...


 IfBegin "$($abc$Frame) > 100"

...


 Color

...

1 0 1

...


 Surface

...

"plastic"

...


 Else
 Color 1 1 0

...


 Surface "matte"

...


 IfEnd
 Sphere 1.0 -1.0 1.0 360.0

...


 AttributeEnd
 WorldEnd
 FrameEnd