# 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: W, U, _, K, M

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

## Overview#

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.

While you can specify any existing image buffers as output for LPEs , it's best to create a dedicated image buffer for each LPE.

### Built-in LPEs#

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.

Tip

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.

#### Layer 3d#

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.

Tip

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.

Finally, like when using AOV Store items, you need to use the AOV Editor to let the raytracer know which image buffer/AOV you wish to output in your render.

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.

Note

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.

#### AOV Set#

Using the build assembly workflow it is very easy to output LPEs as AOVs.

Just connect the LPE node to the Light Path Expressions attribute of the AOV Set and don't forget to connect the AOV Set to the AOV Set attribute of the Render Scene.

## Outputting Variance#

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.

Note

It is not possible to output the variance of an LPE without outputting the LPE in an image buffer.

## Labels#

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.

For example: C<WD['my_material_group']>L|O restricts the expression to materials that have their Light Path Expression Label attribute set to my_material_group.

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:

C<WD['my_sss_label']>L|O


## Per-Light AOVs#

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.

For example, 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!

C<RS>M<K.'z_depth'>