Example 1: Render Passes

This first example allows you to interact with the balance between separate render passes.

Rendering AOV Images

The hb_plastic.sl shader is rearranged from the original plastic:

Oi = Os;

Ci = Os * (Cs * (Ka*ambient() + Kd*diffuse(Nf)) +

specular_color * Ks * specular(Nf,V,roughness) );

To this:

Cambient = Cs*(Ka*ambient());

Cdiffuse = Cs*(Kd*diffuse(Nf));

Cspecular = specular_color*Ks*specular(Nf,V,roughness);

 

Oi = Os;

Ci = Os*(Cambient+Cdiffuse+Cspecular);

Which separates the calculations of the individual components, and allows them to be output as AOV images, as instructed by the shader parameters:

surface hb_plastic(

float Ks=0.5;

float Kd=0.5;

float Ka=1;

float roughness=0.2;

color specular_color=1;

output varying color Cambient=0;

output varying color Cdiffuse=0;

output varying color Cspecular=0;

)

These AOVs need to be declared in prepare.rib:

Declare "Cambient" "varying color"

Declare "Cdiffuse" "varying color"

Declare "Cspecular" "varying color"

 

Display "+ambient.tif" "tiff" "Cambient" "quantize" [0 255 0 255]

Display "+diffuse.tif" "tiff" "Cdiffuse" "quantize" [0 255 0 255]

Display "+specular.tif" "tiff" "Cspecular" "quantize" [0 255 0 255]

Rendering will now create the following three images in addition to the standard image.

ambient.tif

diffuse.tif

specular.tif

Interacting

To interact with these images, we need to write a shader interact.sl to recombine the three AOV image values according to three factors.

surface main( varying color Cambient = 0;

varying color Cdiffuse = 0;

varying color Cspecular = 0;

uniform float Fambient = 1;

uniform float Fdiffuse = 1;

uniform float Fspecular = 1;

)

{

Ci = Cambient*Fambient + Cdiffuse*Fdiffuse + Cspecular*Fspecular;

}

The file interact.rib describes the contents of the interaction scene, relying on a geometry object of type 'image'. The objects filename parameter describes the images to be loaded and their connections to variables in the shader.

Attribute "identifier" "string name" ["mixer"]

 

Surface "interact.sl"

 

Attribute "identifier" "string name" ["geometry"]

 

Geometry "image" "filename" [ "ambient.tif:Cambient"

"diffuse.tif:Cdiffuse"

"specular.tif:Cspecular" ]

Making

All examples come with a Makefile so that all the necessary steps happen in sequence. In these files, the actual commands used and the compiled shader suffix are replaced with variables so they can be used with a number of renderers.

include ../Makeinclude

 

 

run: all

${INTERACT} interact.rib

 

all: prepare.tif

 

 

prepare.tif: hb_plastic.${SLO} prepare.rib

${RENDER} prepare.rib

 

 

hb_plastic.${SLO}: hb_plastic.sl

${SHADER} hb_plastic.sl

So to get the example to run, you just need to go to the example directory and type make run. This will execute the commands to compile the shader, render the AOVs, and start the interaction viewer. With this example and PRMan, it will run:

shader hb_plastic.sl

render prepare.rib

hb_interact interact.rib