---
title: "Advanced Light Path Expressions"
canonical: "https://documentation.chaos.com/space/VRAYHOUDINI/113279134/Advanced%20Light%20Path%20Expressions"
format: markdown
---
Now that we've looked at how LPEs work and know the basics, let's look at some advanced concepts and more ways to use LPEs.


## **Operations**

---

Light path expressions may also include the modifiers placed after event symbols:

**?** for 0 or one repetition (or an optional event)

**+** for 1 or more repetitions (or indirect). *See the **[+ modifier example ](#ExamplePlusMod)**below.*

***** for 0 or more repetitions (any)

These can be used in combination with the **.** symbol. It can signify an arbitrary ray spawn event or an arbitrary scattering type, simply put it stands for any symbol.


Symbols in an expression can be grouped.

**[] **groups event, scatterings and labels

**<> **groups event, scatterings and labels

**[^] **inverts events, scatterings and labels

**''** labels for masking objects or materials are placed inside single quotations.

**|** OR (pipe symbol)

**()** groups symbols.


| **Expression** | **Equivalent (Description)** | **Captured ray paths** |
| --- | --- | --- |
| **C.*L** | Full light select | camera (**C**) → any event (**.**) that repeats zero or more times (*****) → light (**L**) |
| **CRL**<br>- *simplified for**** C<R.>L*** | Direct light select | camera → diffuse reflection → light  
camera → glossy reflection → light  
camera → singular reflection → light |
| **CR.+L** | Indirect light select | camera → any event (**.**) that repeats one or more times (**+**) → light |
| **CR?L** | ? | camera → diffuse reflection → light  
camera → glossy reflection → light  
camera → singular reflection → light  
camera → light |
| C<RD>L<br>- ***<>**** groups events R and D* | Lighting (Direct diffuse reflections) | camera → diffuse reflection → light |
| C<R[GS]>L<br>- ***[ ]**** groups scatters G and S* | Specular (Direct glossy and singular reflections) | camera → glossy reflection → light  
camera → singular reflection → light |
| C<RD'1'>L<br>- *object label 1 is placed in single quotations* | Lighting for object label 1 | camera → diffuse reflection for object with label 1 → light |
| C<RD[^'1']>L<br>- ***^**** inverts label '1.'Тhis part is placed inside ****[ ]*** | Lighting for all objects other than object label 1 | camera → diffuse reflection for objects that don't have label 1 → light |
| C<RD>(.+L|.*[OB])<br>- ***.+L**** means any event, that repeats more than once, until a light hit (****L****)*
- ***.*[OB]**** means any event, zero or more times, until hitting emissive objects (****O****) or the background (****B****)*
- ***|**** asks for .+L ****OR**** .*[OB]*
- ***[ ]**** groups O and B*
- *ending part is in brackets ****( )*** | GI (Indirect diffuse reflections) | `camera → diffuse reflection → any event (.) that repeats one or more times (+) → light`  
`camera → diffuse reflection → any event (.) that repeats zero or more times (*) → emission`  
`camera → diffuse reflection → any event (.) that repeats zero or more time` |


> Macro (anchor)



> Macro (rw-ui-expands-macro)
> 
> > Macro (rw-expand)
> 
> Previously, we looked at **C<T[GS]><RD>L** to capture diffuse reflection behind refraction. This will work behind a single refractive pane, as we only ask for a single refractive hit with **<T[GS]>** that is either Glossy or Singular.
> 
> If the refractive object is (for example) a cube, then the ray needs to enter and exit the cube, hitting the refractive surface twice before reaching the diffuse surface behind.
> 
> In this case, we need to ask for two refraction hits **C<T[GS]><T[GS]><RD>L**. If there's no risk of capturing other random refraction hits, we can use **<T[GS]>+** to ask for **1 or more repetitions of <T[GS]>**
> 
> ** **
> 
> ![image](media://c6992e37-5090-471f-8025-720c3676489d)
> 
> C<T[GS]><T[GS]><RD>L captures the diffuse surface **behind exactly 2** panes of refractive surfaces.
> 
> C<T[GS]>+<RD>L captures the diffuse surface **behind 1 or more** refractive hits.


## **Shadow Mode Prefix**

---

The **shadow; **prefix in LPE collects and returns shadow information.

It causes the light to accumulate the shadowed contribution out of the light contribution on the last bounce of the ray. It can be used to capture the diffuse or/and specular shadows in the render elements.


| **Expression** | **Description** |
| --- | --- |
| <span style="color: #000000">shadow;CDL</span> | <span style="color: #172b4d">Extracts shadow from all lights.</span> |
| <span style="color: #000000">shadow;CGL</span> | Extracts shadow from the reflection occlusion of all lights. |
| <span style="color: #000000">shadow;C.'objectLabel'.*L</span> | Extracts shadows that fall over or are reflected in a specific object that is tagged. You can also use it with a material label. |
| <span style="color: #000000">shadow;CD<L.'lightLabel'></span> | Extracts shadows resulting from a specific labeled light. |
| <span style="color: #000000">shadow;CG<L.'lightLabel'></span> | Extracts shadows resulting from a specific labeled light in the reflection occlusion. |


## **Capture Objects, Materials and Lights**

---

LPEs can be modified to record information for only specific objects or materials by adding a label, or for only specific lights by adding a tag.


### **LPE labels for objects**

---


### **LPE labels for materials**

---


### **Inverting LPE labels**

---

Labels can be easily inverted in expressions by adding **^** in front of them and then placing the inversion symbol and the label inside square brackets **[ ]**.

For example, **C.[^'m1'].*** will give us the Beauty for all materials that do not have material label **1**.

We can invert multiple labels at the same time, for example **CR[^'1''2'].+L **filters the indirect illumination for all objects that do not have the labels** 1** and **2**.


### **LPE tags for lights**

---


## **Boolean operations**

---

Boolean operations allow us to combine expressions. We can complement (**^**), intersect (**&**) or unite (**|**) expressions, or we can subtract (**-**) one expression from another.

Let's look at some examples.

GI can be broken down to different types of light sources: lights, self-illuminating objects, and the environment. If we need to control each of these separately in compositing, we can use the built-in presets, respectively: **C<RD>.+L, C<RD>.*O** and **C<RD>.*B**. The combination of these in compositing (with a plus) replaces the GI channel in a back-to-beauty composite. However, if we only need to grade the GI from Lights, we can render a GI render element and **C<RD>.+L**. Then, we subtract **C<RD>.+L** from the GI in compositing, grade **C<RD>.+L** and add it back to the composite.

Alternatively, we can render GI and an LPE for GI minus **C<RD>.+L**. In this way, we'll only need to add the graded **C<RD>.+L** channel to the GI in compositing, saving us some compositing complexity.

For the purpose of this example, we can do a union of the GI coming from all three types of light sources to get the GI using the pipe symbol for union: **(C<RD>.+L)|(C<RD>.*O)|(C<RD>.*B)**


Boolean operations can also be very useful when using LPEs with object or material labels.

Let's look at a simple example with direct lighting. V-Ray already has a render element for this (Lighting) and the equivalent expression is **C<RD>L**. If we additionally want to capture direct lighting falling onto object(s) labeled **cube**, we need to render an LPE for **C<RD'cube'>L**. We can then subtract** C<RD'cube'>L **from the Lighting channel in compositing, grade it, and add it back in.

Alternatively, we can render the **C<RD'cube'>L** expression and a second one that does the subtraction right in the renderer: **(C<RD>L)-(C<RD'cube'>L)**. We then grade each channel as needed and add them with a plus in the composite.



## **Notes**

---

Light Path expressions (LPEs) that have an equivalent V-Ray Light Select type are automatically translated to Light Selects. You need to set the VRAY_USD_LPE_TO_LS environment variable to enable the automatic translation  with the following values:

0 – conversion is disabled  
1 – conversion for the LIGHT types is enabled  
2 – conversion for all types (LIGHT and SHADOW)