Renderman Shaders and Houdini

Multipass
Renderman Render From Houdini

By

Mauricio
Villamil

This short tutorial will show you how to produce multiple passes (ambient, specular,
normal, diffuse, beauty, etc…) using Renderman from Houdini (in one go) writing your own shaders in RSL (Renderman Shading Language) that support Arbitrary Output Variables – AOV-.

I was motivated to write this tutorial as I felt it would fill the gap there
is in documentation about the Renderman-Houdini pipeline, and the lack of
tutorials on the net about the issue, so idecided to give my little contribution
to the community, after feeling terribly frustrated by not finding any information
about it, not in the Houdini help files or anywhere else. Multipass rendering
being a fundamental step in producing quality CG imagery, that allows for
maximum control of all aspects of the image at compositing time.

I should try to give a comprehensive overview of what is going on and how things
happen, for that we should delve in the intricacies of Renderman shader writing
for a bit, as all the magic happens there. Then we will move into the Houdini
part and see how to get your passes done. If you have no experience in programming
or shader writing you should not be put off by this, as I can assure you it
all makes sense, keep reading and all will click into place in the end. I
have tried to devise this tutorial in a way that “talks” to audiences
that are at different levels of experience and knowledge with respect to Renderman,
shader writing and Houdini, some of you may want to skip ahead, some of you
may want more details about certain steps, so take what you need and leave
want you don’t.

Finally I hope this will serve as motivation to learn to write shaders in the Renderman
Shading Languaje (RSL), it is fun.

So let’s get started then. I will start by drawing your attention to the parallel
that exists whether you are rendering in a Renderman compliant renderer from
the command line or from Houdinis Renderman ROP (Render Operator), the parallel
is this:

When rendering a single output image by rendering a RIB file from the command line,
your Rib file has a Display line that looks like this:

Display “My_image.tif” “tiff” “rgba”

This tells the renderer to render one image file in the tif format, that has four
channels: red, green, blue and alfa.

Now when you render a single image from Houdini using the Renderman ROP you have
the output picture window where you define the image you want to render and
the path to where to render it.

The two do the same thing.

Now, when you want to render “additional aspects” of the image or passes,
from your Rib file you need to add additional Display lines that tell the
renderer which specific aspects of the image it should render, this is what
is called Arbitrary Output Variables in the Renderman standard, and what we
would address as
passes: Specular, diffuse, ambient, normal, etc.

If rendering from the command line you would add the following lines to your
Rib File:

-first the [+] plus sign in front of the new Display lines path, which means
“this is an additional output image”.

-second the variables in red, that
are pointing the renderer to read the specific output variable THAT MUST BE
PRESENT IN THE SHADER for the objects, in order to be outputted, or rendered.

So if you want a Specular pass for instance, your shaders must have a specular
component, represented by the Ks (or
whatever name you may want to give it, as long as your lighting model calculation
refers to the specular component, right?) otherwise you would not get specular
output, or pass. And that applies to all aspects of the image, variables and
therefore passes you may want.

The correspondent feature in Houdini, takes shape under the AUX FILES in the Renderman
ROP (this is the only tab of the Renderman ROP that is not documented in the
Houdini help, for some reason…).

If you have a look at this tab, you will find that it has as a standard six slots
to obviously out put six AUXILIAR FILES, but you can create more if you ever
need to, or delete some if you want to. This is where you create your passes.

screen capture one.

If you check the windows you will see they allow you to enter values similar
to the ones I mentioned above for the additional display lines in the Rib
file, you have:

– Filename for the path to save your image.

–Devise where you specify if you want your image
displayed on screen (framebuffer) or saved as a file (tiff).

–Variable, as I mentioned above tells the renderer
what specific aspect of the image (exported from the shader) to render into
this additional file.

–Type (Variable) which refers obviously to the type of the varible supported by
the Renderman standard. For most widely used passes (specular,diffuse,ambient,normal)
the varying colour is what you want, but the Renderman standard allows you
to create your own variables so you may want to create a really out of the
box new kind of render pass.

-inline field refers to inline declarations of the type we described above for AOV
in the RIB. of the type:

This will asist the RIB generator in Houdini to do its job (Generating a RIB file).

However, and this is very important: the Arbitrary Output Variables Must be explicitly
exported fom the shader for this to work, equally they must be “declared”
in the RIB file for this to work (this applies for command line or Houdini
render).

For example, in your shader you create and export the following variables:

output varying color Camb = 0;

output varying color Cdif = 0;

output varying normal Nn = 0;

output varying color Cspec = 0

Then still in the shader you define the calculation for the variable (the values that the
variable will carry):

/* here we compute the value that we wish to export */

Nn = normalize(N) ;

Camb = Cs * Ka * ambient();

Cdif = Cs * Kd * diffuse(Nf);

Cspec = specularcolor * Ks * specular(Nf,V,roughness * s);

Finally, after compiling your shader, you need to declare your variables in the RIB file
for it to be able to read them and display them (create an image file for
the pass):

That if rendering from comand line, if you want to render from Houdini, you need to load your
compiled shader into Houdini (additional_tutorial_loading_shaders) and then
enter the values in the AUX FILES tab of the Renderman rop in Houdini output,
as shown in the window above. That is all you need, then press render and
you should have a file.tif for each pass.

Please note one thing; the window above shows the variables (names) as : Ka,Kd,Ks,those names
are the global variable names in the Renderman standard, and if you try to
compile a stock Renderman shader that has those variables, and you try to
get additional Aux Files (passes) you will notice that this would NOT work.
That is because the Ka,Kd,Ks,etc are not Arbitrary Output Variables, and are
not being declared and exported from the shader as such.

So if you want to use a stock Renderman shader, you will need to open the shaders.sl source
file for the shader, create the variables (as shown
in green above), re-compile it, load it into Houdini, fill in the values
in the AUX FILES tab, and press render.

screen capture two

One last thing, the additional rendered files are usually 16 bit or floating point,
which means you may not be able to display them in some aplications (Shake,
and photoshop can) but if the render appears all black you may need to re-save
it as 8 bit.

Quantize
will ensure the image is compressed if you like, in a range between 0-255,
that means 8 bit images.

That is all. Additional reading should be the Renderman documantation related to Arbitrary
Output Variables. I hope this has been of help !!

APPENDIX:

(some curious
notes I found while preparing this tutorial that some of you may find of interest,
extracted from the Renderman documentation).

In PRMan 11 the special variable __CPUtime may also be used as a mode for
an arbitrary display:

Display “+costfilename.tif” “tiff” “__CPUtime”

This mode will result in an image that profiles how long it takes to shade
each micropolygon as it renders. The data stored will be the amount of time
it took to shade each micropolygon in seconds.

Arbitrary Output Variables

Several important limitations have been removed from the arbitrary output
variable functionality:

* PRMan no longer requires that the pixel filter be set to 1×1 box for all
Displays when rendering an arbitrary output image, or when rendering a rgbaz
mode image. PRMan will now obey your PixelFilter setting for the main render,
as well as for all additional arbitrary output images. In addition, PRMan
now allows specification of different pixel filters to be applied on a per
display basis via a new extension of the RiDisplay call:

In addition, three special filters (“min”, “max”, “average”)
may be specified for arbitrary outputs. These filters are useful when dealing
with variables which cannot be composited in the normal manner.

* Any number of arbitrary outputs may be specified; you are no longer limited
to nine additional output channels.

* Arbitrary outputs images may now be created from output variables exported
by atmosphere shaders. (Previously, you were limited to surface shaders only.)

As well, bugs which prevented the use of multiple frames, each with arbitrary
output variables, in a single RIB file have been fixed.

Finally, inline declarations now work in arbitrary output displays, so you
may now use:

Display “+image.tif” “tiff” “varying float myvar”

More information on the new AOV functionality may be found in User Manual.

============
In LIne stuff ==============

7.4 Conditional Evaluation

RiIfBegin (RtToken expression)

RiElseIf (RtToken expression)

RiElse

RiIfEnd

These calls form the basis of a simple conditional evaluation mechanism and
allow RIB archives with be constructed with a degree of context sensitivity.
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 in multiple parts of 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.

However, there are certain important situations for which it would be useful
to write out a single archive once, but then allow certain aspects of the
archive to change based on the current context in which it has been instantiated,
as defined by the driver file.

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]

Then, the archive can use the conditional evaluation calls to decide which
shaders to apply: