---
title: "Advanced Light Path Expressions"
canonical: "https://documentation.chaos.com/space/VC4D/116850700/Advanced%20Light%20Path%20Expressions"
format: markdown
---
## **Overview**

---

Now that we've looked at [how LPEs work](https://docs-chaos.atlassian.net/wiki/spaces/VC4D/pages/116850698) and know the basics let's look at some advanced concepts and more ways to use LPEs.



## **Operations**

---

> 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://40229c2b-f933-47b6-a849-2fd6d7a15008)
> 
> 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.


## **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 into 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**. Combining 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**. This way, we 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 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**); 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.



## **Additional examples**

---

SSS:

- SSS from objects directly visible to the camera **C<TD>+L**
- SSS directly visibly OR occluded (behind reflections and refractions)  **C<[RT][SG]>*<TD>.+L**
- **SSS only from occluded objects  C<[RT][SG]>+<TD>.+L **

Self-reflections by material label 1

- **C<R[GS]'m1'>.'m1'+L**

Emissive

- Emissive (self-illuminating) objects only - direct camera rays **CO**
- The GI coming from emissive objects **C<RD>.*O**
- The union of GI, coming from an emissive object and the directly visible to camera emissive objects **(C<RD>.*O)|(CO)**

GI

- Full GI **C<RD>(.+L|.*[OB])**
- GI from the environment only **C<RD>.*B**
- GI minus GI from environment **C<RD>(.+L|.*[OB])-(C<RD>.*B)**