I created a small pdf - "LPE in KATANA and Maya". This will help TDs to understand Renderman's Light Path Expressions and how to use them in KATANA and Maya as well
2. Structure of the book
Overview
The following documentation will give better understanding of the below topics. After
this, one can understand Renderman LPEs, AOVs , creating custom LPEs in Katana and
Maya.
AOVs
LPE and OSL
LPEs in Katana
LPEs in Maya
Prerequisite
Knowledge of Katana/Maya/Renderman to understand how to write LPE
3. Multipass rendering
Multipass rendering is a widely used technique in our industry. We can control the final
look of an image in compositing rather re-rendering any scene again. We will get more
control over different components of the image.
Whenever we hit render in any renderer it creates 2D image from 3D scene file.
Renderer calculates all lights in the scene along with material properties of objects and
calculates indirect illumination, saves the per pixel color information then it creates an image.
The final image is usually called Beauty.
Beauty image is addition of different components of the scene and global settings. We
can render different components like diffuse, specular etc. seperately.
Beauty = SpecularDirect SpecularDirectShadow + SpecularIndirect +
SpecularEnvironment + Ambient + DiffuseDirect DiffuseDirectShadow
+ DiffuseIndirect + DiffuseEnvironment + Subsurface + Refraction
etc.
If we have a scene file without any indirect contribution and only diffuse and specular
then,
Beauty = specularDirect+DiffuseDirect
diffuseDirect = diffuse contribution from all lights (light1+light2
etc.)
We can separate the channels from beauty and combine them in compositing software
to get the result.
Arbitrary Output Variable
Often we say secondary channels, secondary outputs or AOVs in multipass
compositing. AOV's allow a user to access that extra information and output it in a file. In
every renderer there are defined AOVs like specularDirect, diffuseDirect etc. but we can
create our own custom AOVs as well.
There are different ways to create custom AOVs in different renderers/softwares. Here
we are mainly looking at Renderman RIS.
In Renderman for Maya we can get different AOVs, which can be created in
4. Hypershade using Pxr nodes.
Open Shading Language
We are looking at OSL because there are different renderes capable of using it and
LPEs are adopted from OSL. Open Shading Language (OSL) is a small but rich language for
programmable shading in advanced renderers and other applications, ideal for describing
materials, lights, displacement, and pattern generation.
OSL was originally developed by Sony Pictures Imageworks for use in its in- house
renderer used for feature film animation and visual effects, released as open source so it
could be used by other visual effects and animation studios and rendering software vendors.
Now it's the standard shading language for VFX and animated features, used across the
industry in many commercial and studio- proprietary renderers. Because of this, its designer
won an Academy Award for Technical Achievement in 2017, for the work on OSL.
OSL has syntax similar to C, as well as other shading languages. However, it is
specifically designed for advanced rendering algorithms and has features such as radiance
closures, BSDFs, and deferred ray tracing as first-class concepts.
5. Renderers and other tools with OSL support
Sony Pictures Imageworks: in-house "Arnold" renderer
Blender/Cycles
Chaos Group: V-Ray
Pixar: PhotoRealistic RenderMan RIS
Isotropix: Clarisse
etc.
We can call our own OSL shader through PxrOSL which is similar to RSL. We are
not going deep inside OSL but we need to know that Render outputs (AOV's) can be created
using "light path expressions."
6. Light Path Expressions
Light path expressions (LPEs) is a regular expression which describes light paths.
LPEs are adopted from Open Shading Language. Specify what light transport paths to output
to a display channel. We don't have to modify the shaders or plugins to output a custom AOV
that uses the LPE. It allows us to isolate specific type of ray and objects. LPEs are used in
different renderers which supports it like Iray,FluidRay ,Mentalray 3.11 etc (Maya and Max
both)
In renderman we have AOV channel name available to describe and get the output.
Like :
diffuse
specular
refraction
shadowcollector
etc
LPEs can be defined by using prefix lpe:. The above channel names can be used
with lpe: prefix to get the AOV out, with proper syntex.
lpe:diffuse
lpe:specular
etc
Same AOVs can be defined with light path expressions as well.
lpe:diffuse = lpe:CD<L.>
lpe:specular = lpe:CS<L.>
lpe:refraction = lpe:(C<T[S]>[DS]+<L.>)|(C<T[S]>[DS]*O)
LPEs are based on light and geometric object also. LPE should begin with light source
event and end with eye event or vise versa. An interaction event is enclosed with angle
brackets. Below are the different types of events, which can be described using LPEs.
Event Mode
C Camera
D - Diffuse (D2 for diffuse lobe2 , D3 for diffuse lobe 3)
S Specular (S2 for specular lobe2 , S3 for specular lobe 3)
L - Light
R reflection
T transmission
O Emissive object
V volume
< > specifies event type ( D diffuse S specular)
7. If we combine these then we can think of below types of outputs
Diffuse Reflection/Tramission Direct or indirect
Gloss/Specular - Reflection/Tramission Direct or indirect
Now lets understand these with visuals using given LPEs
lpe:C[DS]*[<L.>O]
8. The below image describes Camera with Diffuse Reflection and all lights with Emission
lpe:C<RD>[<L.>O]
lpe:C<RS>[<L.>O]
11. Now lets create our own custom LPEs
IndirectSpecular is a reflection component with diffuse and specular both reflecting.
We can divide both separately. Indirect specular which has diffuse reflection not the specular
reflection.
12. { } brackets tell us which depth we want to render
Custome LPEs based on depth
We have path length or depth of raytracing, default value of it is 10. We can render 1st
depth, 2nd
depth etc. also (1st
bounce or 2nd
bounce ). Below image is Diffuse component of
indirect specular with 1st
path(indirect - depth 1)
13. IndirectSpecular with 1st
Depth, mentioned using { } below.
same indirectSpecular of 2nd
depth or 2nd
bounce or 2nd
ray of indirect
14. Custome LPEs based on Light
We can get light specific AOVs by mentioning light name (not the name in software but
define it in RIS 'AOV light group'). We can create group of key lights, fill lights etc. and
render AOVs specific to those light instead of all lights.
We can mention <L.'lightname'> instead of <L.> (all lights)
1st
depth indirectSpec light-'key'-color lpe:C<RS>{1}[DS]<L.'key'>
1st
depth indirectSpec light 'rim'-color lpe:C<RS>{1}[DS]<L.'rim'>
indirectSpecular for 'key' light- color lpe:C<RS>[DS]<L.'key'>
Custome LPEs based on Geometry
Similarly we can get AOVs specific to geometry as well. We have to define the 'LPE
group in the scene and we can call it in our custom AOVs. Below we have given name
'sphere1' in geometry settings. We can define several objects in same group also or in
several groups and render them seperately.
15. Below, two groups are mentioned for two different spheres. In single LPE script added those
groups and getting single output.
lpe:C<RS'sphere1''sphere2']>[DS]<L.>
16. As a recap, we can customize LPE in different aspects. In one render layer we can
separate different objects, different lights and different channels as well.
17. LPE Tokens (Renderman website)
To better understand how an LPE is constructed, the below tokens are used to define
interactions. For most users, the pre-built LPE are easily selected and explained below.
C Camera
<type event
'group'>
Scattering event specified by
scattering type, scattering event, or
lpe group
C<.[DS]'floor'>[LO] matches all light
paths from the floor lpe group
<L.'group'>
Light, i.e. analytic and geometric
lights
C[DS]*<L.'key'> matches all light paths
from the key light group
O
Emissive object, i.e. camera visible
lights and material glow
C[DS]*O matches all emissive object
light paths
Wildcard
.
A period will match any relevant
event
<.D> where the period represents R or
T
Scattering
Types
R Reflection
C<R[DS]>[DS]*[LO] matches all
reflected light paths
T Transmission or refraction
C<T[DS]>[DS]*[LO] matches all
transmitted light paths
Scattering
Events
D Diffuse lobes (D1 to D4)
CD[DS]*[LO] matches all diffuse light
paths
S Specular/Glossy lobes (S1 to S8)
CS[DS]*[LO] matches all specular light
paths
U
User lobes used to output material
properties (U1 to U12)
CU2L matches the camera visible user2
lobe, typically albedo
Grouping
( )
Parentheses allow grouping of a
sequence of LPE events
CDSL, C(DS)L, and CD(SL) are all
functionally the same
Alternatives
| A vertical bar separates alternatives
CD|(SD)L matches direct diffuse or
specular-diffuse light paths
[ ] Square brackets that match any C[D2D3]L matches direct diffuse2 or
18. one of the enclosed events diffuse3 light paths
[^ ]
Square brackets that match any
one event not contained within the
brackets
C[^D2D3]L matches all light paths
besides diffuse2 and diffuse3 (including
specular and user)
Qualifiers
*
An asterisk will match the preceding
event zero or more times
C[DS]*[LO] matches all light paths,
including emissive
+
A plus sign will match the preceding
event one or more times
C[DS]+[LO] matches direct and indirect
light paths, but not emissive
{n}
Curly brackets that match the
preceding event exactly n times
C<T[DS]>{2}[LO] matches double
transmission light paths
{min,}
Curly brackets that match the
preceding event min or more times
C[DS]{2,}[LO] matches all indirect light
paths
{min,max}
Curly brackets that match the
preceding event at least min but not
more than max times
C[DS]{0,1}[LO] matches direct and
emissive light paths
19. Rendering LPEs in Katana
All the above mentioned LPEs can be created in Katana as well. We have to define
output channel then we have to define render output.
We can define output channel using node prmanOutputChannelDefine. Either we
can use source to put our LPE or in name filed we can use our expression also.
We can define Render output by using node RenderOutputDefine. We can define
name of the output which we want. And channel we take from
prmanOutputChannelDefine.
20. To create seveal AOVs we can create stacks of RenderOutputDefine and
prmanOutputChannelDefine nodes wit different names and LPEs.
Along with the AOV we can set other properties like file type, color space etc using
the node. We can also save these stacks as Macros and reuse. You can also refer my other
PDF Python for Katana to understand about macros and how to create Macros in Katana.
21. We can merge different channels one single EXR file using merge type in
RenderOutputDefine. We can define deep passes also with the help of type.
Make sure to switch the interactiveOutput to all to get the AOVs in preview.
22. Another Method to create LPEs
Another way of creating these output channels in Katana is through AttributeScript.
Attribute Scripts:
Attribute scripts are similar to attribute modifiers, where we can modify the attributes
through python scripts. Through attribute script we can modify attribute at any given location.
We can create attribute scripts which run only on certain type of locations. AttributeSet will be
much faster than AttributeScript if all you're doing is setting attributes. AttributeScript can do a
lot more than set attributes.
Lets create an attributescript which changes the maxTimeSamples using python script.
MaxTimeSamples is an option which is not an object based setting, which is scene based or
layer based. So we need to apply the script at '/root' location. It wont work on any other
location or on object.
Create an AttributeScript node.
Set location to '/root'
Put the below script in script box in the node.
SetAttr('renderSettings.maxTimeSamples',[4])
Similarly we can write different types of attribute scripts which can do lot of
manipulation in the scene/Nodegraph. We can create custom LPEs using AttributeScript. To
create diffuse LPE we need to write the below code. Here we are defining the name of output
as mydiff and values as color lpe:C<RD>[<L.>O]. We can write this in two different ways.
Option 1
SetAttr("renderSettings.outputs.mydif.rendererSettings.channel",
['varying color lpe:C<RD><L.>'])
Option 2
SetAttr("renderSettings.outputs.mydif.rendererSettings.channel",Scen
egraphAttr.StringAttr('varying color lpe:C<RD><L.>'))
23. Our AOVs get out in renderSettings of /root attributes and we are editing it to add
the AOVs using AttributeScript. Similarly we can edit other parameters as well to get the
output.
24. Similarly we can write several LPEs in one AttributeScript.
As discussed above we can name a light using lightGroup attribute in gaffer.
Also we can name a group of objects using lpegroup in PrmanObjectSettings.
There may be other ways also to create custom LPEs. This tutorial is to give basic
idea of creating them in katana.
25. Rendering LPEs in Maya
Similarly the same outputs we can get from Maya as well. We can create the custom
LPEs using Advanced RendermanControls
26. Below image shows the name of AOV and expression used for it.
Using custom tab we can create custom LPEs. Give name of the output in Name box and
define LPE in source box. Once it is created we can select the outputs from Output tab
and edit the source again if we need.
27. To create object specific LPEs, we need to add group name to objects. Select the
Shape node and add renderman Attribute called LPEGroup. Once it is added to shape
node then specify the name of the group. And same group can be called in custom LPEs for
object specif expressions.
Similarly to create light specific LPEs, we need to add group name to lights. Select the
light add the light name in the parameter called AOV light Group. Then the same name
can be used in our custom expressions.
28. This way we can create custom LPEs in Maya by creating different groups of lights
and objects. We can automate all these either using MEL or Python. To know MEL you can
check my PDF MEL for Beginners . Which will give you fair idea how we can automate
things in Maya.
###################
29. references
Python for Katana
/kedarnath7737/python-forkatana
MEL for beginners
/kedarnath7737/mel-for-beginners
OSL
https://github.com/imageworks/OpenShadingLanguage/
LPE
https://rmanwiki.pixar.com/display/REN/Light+Path+Expressions
AOV
https://renderman.pixar.com/resources/RenderMan_20/risAOVs.html#custom-aovs
Please write your suggestions and comments to Email: m_kedar_nath@yahoo.com