29
Light Path Expressions in Katana and Maya for Beginners M. Kedarnath

LPEs in KATANA and Maya

Embed Size (px)

Citation preview

Page 1: LPEs in KATANA and Maya

Light Path Expressions

in Katana and Mayafor Beginners

M. Kedarnath

Page 2: LPEs in KATANA and Maya

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

Page 3: LPEs in KATANA and Maya

Multipass rendering

Multipass rendering is a widely used technique in our industry. We can control the finallook of an image in compositing rather re-rendering any scene again. We will get morecontrol 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 andcalculates 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. Wecan 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 specularthen,

Beauty = specularDirect+DiffuseDirect

diffuseDirect = diffuse contribution from all lights (light1+light2 etc.)

We can separate the channels from beauty and combine them in compositing softwareto get the result.

Arbitrary Output Variable

Often we say secondary channels, secondary outputs or AOVs in multipasscompositing. AOV's allow a user to access that extra information and output it in a file. Inevery renderer there are defined AOVs like specularDirect, diffuseDirect etc. but we cancreate our own custom AOVs as well.

There are different ways to create custom AOVs in different renderers/softwares. Herewe are mainly looking at Renderman RIS.

In Renderman for Maya we can get different AOVs, which can be created in

Page 4: LPEs in KATANA and Maya

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 forprogrammable 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.

Page 5: LPEs in KATANA and Maya

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."

Page 6: LPEs in KATANA and Maya

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 outputto a display channel. We don't have to modify the shaders or plugins to output a custom AOVthat 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:diffuselpe:specularetc

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 sourceevent 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 – CameraD - Diffuse (D2 for diffuse lobe2 , D3 for diffuse lobe 3)S – Specular (S2 for specular lobe2 , S3 for specular lobe 3)L - LightR – reflection

T – transmissionO – Emissive objectV – volume< > specifies event type ( D diffuse S specular)

Page 7: LPEs in KATANA and Maya

If we combine these then we can think of below types of outputs

Diffuse – Reflection/Tramission – Direct or indirectGloss/Specular - Reflection/Tramission – Direct or indirect

Now lets understand these with visuals using given LPEs

lpe:C[DS]*[<L.>O]

Page 8: LPEs in KATANA and Maya

The below image describes “Camera” with “Diffuse Reflection” and all lights with Emission

lpe:C<RD>[<L.>O]

lpe:C<RS>[<L.>O]

Page 9: LPEs in KATANA and Maya
Page 10: LPEs in KATANA and Maya
Page 11: LPEs in KATANA and Maya

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.

Page 12: LPEs in KATANA and Maya

{ } 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)

Page 13: LPEs in KATANA and Maya

IndirectSpecular with 1st Depth, mentioned using { } below.

same indirectSpecular of 2nd depth or 2nd bounce or 2nd ray of indirect

Page 14: LPEs in KATANA and Maya

Custome LPEs based on Light

We can get light specific AOVs by mentioning light name (not the name in software butdefine 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.

Page 15: LPEs in KATANA and Maya

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.>

Page 16: LPEs in KATANA and Maya

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.

Page 17: LPEs in KATANA and Maya

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

OEmissive 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

ScatteringTypes

R ReflectionC<R[DS]>[DS]*[LO] matches all reflected light paths

T Transmission or refractionC<T[DS]>[DS]*[LO] matches all transmitted light paths

ScatteringEvents

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

UUser lobes used to output material properties (U1 to U12)

CU2L matches the camera visible user2lobe, 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 alternativesCD|(SD)L matches direct diffuse or specular-diffuse light paths

[ ] Square brackets that match any C[D2D3]L matches direct diffuse2 or

Page 18: LPEs in KATANA and Maya

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 precedingevent zero or more times

C[DS]*[LO] matches all light paths, including emissive

+A plus sign will match the precedingevent 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 notmore than max times

C[DS]{0,1}[LO] matches direct and emissive light paths

Page 19: LPEs in KATANA and Maya

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”.

Page 20: LPEs in KATANA and Maya

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.

Page 21: LPEs in KATANA and Maya

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.

Page 22: LPEs in KATANA and Maya

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 bemuch faster than AttributeScript if all you're doing is setting attributes. AttributeScript can do alot 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”. Tocreate diffuse LPE we need to write the below code. Here we are defining the name of outputas “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",ScenegraphAttr.StringAttr('varying color lpe:C<RD><L.>'))

Page 23: LPEs in KATANA and Maya

Our AOVs get out in “renderSettings” of “/root “ attributes and we are editing it to addthe AOVs using “AttributeScript”. Similarly we can edit other parameters as well to get the output.

Page 24: LPEs in KATANA and Maya

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.

Page 25: LPEs in KATANA and Maya

Rendering LPEs in Maya

Similarly the same outputs we can get from Maya as well. We can create the custom LPEs using “Advanced RendermanControls”

Page 26: LPEs in KATANA and Maya

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.

Page 27: LPEs in KATANA and Maya

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 thelight add the light name in the parameter called “AOV light Group”. Then the same name can be used in our custom expressions.

Page 28: LPEs in KATANA and Maya

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.

###################

Page 29: LPEs in KATANA and Maya

references

Python for Katanahttps://www.slideshare.net/kedarnath7737/python-forkatana

MEL for beginnershttps://www.slideshare.net/kedarnath7737/mel-for-beginners

OSLhttps://github.com/imageworks/OpenShadingLanguage/

LPEhttps://rmanwiki.pixar.com/display/REN/Light+Path+Expressions

AOVhttps://renderman.pixar.com/resources/RenderMan_20/risAOVs.html#custom-aovs

Please write your suggestions and comments to Email: [email protected]