LPEs in Clarisse#
LPEs in Clarisse are based upon Open Shading Language (OSL) implementation. For more information on LPEs and their syntax, we strongly advise you to refer here.
Please note that Clarisse implementation extends the original specifications by introducing some new useful events:
Since the syntax of the LPEs are based on regex, they can be very daunting at first. However, even if LPE syntax seems really painful to learn, "you should not underestimate the power of LPEs". They are definitely worth the extra effort.
This is why we created a special guide to help you understand LPEs. Make sure to read our Introduction to Light Path Expressions
Light Path Expressions are defined by an Expression and an associated Output image buffer. The image buffer Output is the name of the image buffer the raytracer will use to output the resulting AOV from the input Expression.
For more information on creating image buffers, please refer to the Image Buffer Editor.
While you can specify any existing image buffers as output for LPEs , it's best to create a dedicated image buffer for each LPE.
Clarisse already comes with many built-in LPEs that are defined in the
default://lpe context. These LPEs which are defining most common AOVs are already setup and ready to use. They are all gathered inside a builtin group that is by default added to the Layer 3D.
This way it is very easy to add them in your renders since you just have to select which AOV you want using the AOV Set or the AOV Editor.
Don't hesitate to check the builtin LPEs to learn about LPE expression syntax.
Creating a custom LPE#
First you need to create an image buffer to store the result of the LPE. Go to Image > Image Buffers... to open up the Image Buffer Editor.
Create a new image buffer called
myCustomAOV which will be the recipient output of our LPE. For more information on creating image buffers, please refer to the Image Buffer Editor.
Then go to Create > Light Path Expression to create the LPE item. Once created, select the newly created node to reveal its attributes in the Attribute Editor.
As you can see we've just created a new LPE node that has no Expression nor Output set.
Let's say we want to output the diffuse component of all our lights, including the contribution of the emissive materials, and materials in our scene.
To do so, type the
C.*DL|O to the Expression attribute. This expression will gather the total diffuse contribution coming from all direct lights, emissive objects and indirect illumination.
Now let's set Output to
myCustomAOV to output the result of our expression in
myCustomAOV image buffer.
Connecting the LPE#
Now that we've created the LPE item, we need to connect it to the Layer 3d or an AOV Set.
Indeed, there are two different LPEs workflow in Clarisse. The most common one is to connect LPEs to a Layer 3d while the other one is to setup LPEs using the build assembly workflow.
To declare our the LPE to the raytracer we need to connect it to a Layer 3d.
Select the Layer 3d of the Image and add the LPE item to the Light Path Expressions attribute list using the Attribute Editor.
It is possible to use groups to create groups of LPEs. This workflow makes it more manageable when dealing with many LPEs. This way you are not forced to manually add each LPE for each Layer 3d needing them.
To do so, open the AOV Editor.
Select the Layer 3d you wish to output the AOVs from. Select the image buffer
myCustomAOV (which should be displayed in light gray) and drag and drop it to the list located at the right of the editor.
If an image buffer is greyed out on the left list then no item in the Layer 3d is outputting data to it. In other words, no material, AOV Store or LPEs nodes of the Layer 3D is outputting an AOV to the image buffer.
Using the build assembly workflow it is very easy to output LPEs as AOVs.
It is possible to output the variance of LPEs which is very useful if you want to denoise them in denoisers that supports AOVs variance as input.
To output the variance of an LPE you need to set Output Variance to a custom image buffer and Enable Output Variance.
It is not possible to output the variance of an LPE without outputting the LPE in an image buffer.
Both physical lights and materials provide a Light Path Expression Label attribute used to identify items or a group of items in your expressions.These labels are extremely useful to restrict expressions to specific sets of lights or materials.
C<WD['my_material_group']>L|O restricts the expression to materials that have their Light Path Expression Label attribute set to
Now, let's say we want to output only the direct diffuse of a SSS material affected by all lights and the contribution of the emissive materials.
To do this, we have to set the Light Path Expression Label of that material to
my_sss_label, for example, and then write the following expression in our LPE:
Using LPE you can output per light AOVs in a very elegant way by setting the Light Path Expression Label of lights to a custom label.
C.*<L.'right'> restricts the expression to lights defining the label right.
Light Path Expression Constants#
While some materials can define define built-in constants to extract specific information in AOVs, it is also possible to declare custom constants to extract parts of the shading graph of materials.
To create a custom constant, go to Create > Light Path Expression Constant.
Once created, connect it to the Arbitrary Output Variables materials you wish to declare the constant to.
Then plug the texture you wish to export to the Input attribute of the LPE Constant and finally set the Constant Name to the name that will be used to identify it in your LPEs. That's it!
You can now identify the constant in your LPEs using the special token K. For more information about token, please refer to the Token Reference section.
Constants can be very helpful to output specific values such as the depth of the ray in secondary bounces in order to apply in post 2D depth of field of mirror surfaces for example.
To do so, you just need to create a LPE Constant with a Constant Name set to z_depth connected to a Utility texture outputting Z and assign it to the Arbitrary Output Variables attribute of all materials in the scene.
Now to extract the corresponding AOV you just need to use the following expression: