Light Path Expressions#

Light Path Expressions (LPEs) select the light-transport paths accumulated into a RenderVar. Use them to split a Path Tracing image into compositing passes such as diffuse reflection, glossy reflection, emission, direct light, or caustics.

Beauty, diffuse reflection, glossy reflection, glossy transmission, and caustics outputs from one scene

One Path Tracing image separated into beauty and four LPE outputs. Each LPE contains only the light-transport paths matched by its expression.#

LPEs are available in PathTracing mode. Author each expression as the sourceName of a RenderVar, set its sourceType to lpe, and target the RenderVar from the RenderProduct’s orderedVars relationship.

Author LPE Outputs#

The RenderProduct in the snippet below requests the beauty output plus diffuse- and glossy-reflection LPEs. Disable radiance caching when LPE outputs must contain all contributions by adding bool omni:rtx:pt:radianceCache:enabled = false to the RenderProduct. Cached contributions do not retain their path history and are omitted from LPE outputs even though they remain present in the beauty output.

def "Render"
{
    def RenderProduct "Camera" (
        prepend apiSchemas = ["OmniRtxSettingsPtAdvancedAPI_1"]
    )
    {
        rel camera = </World/Camera>
        token omni:rtx:rendermode = "PathTracing"

        # Cached radiance has no path history, so omit it from an LPE workflow.
        bool omni:rtx:pt:radianceCache:enabled = false
        rel orderedVars = [<HdrColor>, <DiffuseReflection>, <GlossyReflection>]

        def RenderVar "HdrColor"
        {
            string sourceName = "HdrColor"
        }

        def RenderVar "DiffuseReflection"
        {
            # sourceType=lpe makes sourceName an expression instead of a built-in AOV name.
            string sourceName = "E<RD>.*L"
            token sourceType = "lpe"
        }

        def RenderVar "GlossyReflection"
        {
            string sourceName = "E<RG>.*L"
            token sourceType = "lpe"
        }
    }
}
render_product = UsdRender.Product.Define(stage, "/Render/Camera")
render_product.GetPrim().ApplyAPI("OmniRtxSettingsPtAdvancedAPI_1")
render_product.GetCameraRel().SetTargets(["/World/Camera"])
render_product.GetPrim().CreateAttribute(
    "omni:rtx:rendermode", Sdf.ValueTypeNames.Token
).Set("PathTracing")

# Cached radiance has no path history, so omit it from an LPE workflow.
render_product.GetPrim().GetAttribute("omni:rtx:pt:radianceCache:enabled").Set(False)

hdr_var = UsdRender.Var.Define(stage, "/Render/Camera/HdrColor")
hdr_var.GetSourceNameAttr().Set("HdrColor")

diffuse_var = UsdRender.Var.Define(stage, "/Render/Camera/DiffuseReflection")
diffuse_var.GetSourceNameAttr().Set("E<RD>.*L")
diffuse_var.GetSourceTypeAttr().Set(UsdRender.Tokens.lpe)

glossy_var = UsdRender.Var.Define(stage, "/Render/Camera/GlossyReflection")
glossy_var.GetSourceNameAttr().Set("E<RG>.*L")
glossy_var.GetSourceTypeAttr().Set(UsdRender.Tokens.lpe)

render_product.GetOrderedVarsRel().SetTargets(
    [hdr_var.GetPath(), diffuse_var.GetPath(), glossy_var.GetPath()]
)

Syntax#

An LPE is a regular expression over the events along a light-transport path. Expressions can run from the eye or camera (E) to a light (L), or in the reverse direction. Every expression, including every branch of an alternation, must contain exactly one eye marker and one light marker.

A scattering event combines an interaction type and scattering mode inside angle brackets. For example, <RD> means diffuse reflection, <RG> means glossy reflection, and <TS> means specular transmission. An optional single-quoted label restricts an event to a named scene object, as in <RD'ground'>.

Read E<RD>.*L from left to right as:

  1. Start at the camera (E).

  2. Match a diffuse-reflection event (<RD>).

  3. Match zero or more additional scattering events (.*).

  4. End at any light (L).

Terminal Tokens#

Token

Category

Meaning

E

Path endpoint

Eye or camera vertex.

L

Path endpoint

Any light.

La

Light subtype

Area light. RTX currently produces this marker.

Le

Light subtype

Environment or background light. RTX currently produces this marker.

Lp

Light subtype

Point light. This marker parses but RTX does not currently produce it.

Lm

Light subtype

Matte lookup or backplate light. This marker parses but RTX does not currently produce it.

Lv

Light subtype

Emissive volume. This marker parses but RTX does not currently produce it.

I

Path endpoint

Irradiance marker.

R

Event type

Reflection.

T

Event type

Transmission.

V

Event type

Volume scattering.

D

Scattering mode

Diffuse scattering.

G

Scattering mode

Glossy scattering.

S

Scattering mode

Ideal specular (delta) scattering. Rough specular reflection or transmission is classified as glossy (G).

'name'

Label

A geometry or light label authored in USD.

.

Wildcard

Any ordinary scattering event; it does not match the special E, L, or I markers.

Operators And Quantifiers#

Syntax

Meaning

AB

Match A followed by B.

A|B

Match either A or B. Every branch must contain one E and one L.

A?

Match zero or one occurrence of A.

A*

Match zero or more occurrences of A.

A+

Match one or more occurrences of A.

A{n}

Match exactly n occurrences of A.

A{n,m}

Match between n and m occurrences of A, inclusive.

A{n,}

Match at least n occurrences of A.

(...)

Group a subexpression.

[...]

Match any member of a set, such as [DG].

[^...]

Match anything except members of a set.

^expression

Complement the complete expression. Complement is valid only at the top level.

A & B

Match paths accepted by both expressions.

name: expression

Declare a reusable expression variable.

$name

Use a previously declared expression variable.

Quantifiers bind most tightly, followed by concatenation, then alternation. <TS> is one specular-transmission event; unbracketed TS means two consecutive abbreviated events.

Common Expressions#

Expression

Output

E.*L

All light paths.

E<RD>.*L

Diffuse reflection visible from the camera.

E<RG>.*L

Glossy reflection visible from the camera.

EDG.*L

Caustics.

EL

Directly visible emission.

E.{2,}L

Indirect illumination with at least two scattering events.

Labels#

Labels restrict an event to named scene elements. Author primvars:omni:label as a uniform token on geometry and omni:label as a uniform token on lights. For example, E<RD'ground'>.*L selects diffuse reflection at geometry labelled ground, while E.*<L'key'> selects paths ending at a light labelled key.

Read And Visualize Outputs#

After stepping the RenderProduct, map each LPE output like any other camera RenderVar. LPE outputs use the same linear floating-point image representation as HdrColor. See Python: Light Path Expressions for a runnable example that reads, converts, and displays all requested outputs.

Limitations#

  • A RenderProduct can request at most nine LPE RenderVars. Additional LPEs are ignored.

  • LPE outputs are supported only in PathTracing mode.

  • Leave omni:rtx:pt:radianceCache:enabled disabled when LPE outputs must be complete. When it is enabled, cached contributions remain in beauty but are omitted from LPE outputs because they do not retain path history.

  • Area (La) and environment (Le) light markers are produced. Point (Lp), emissive-volume (Lv), and matte (Lm) markers parse but do not currently match renderer contributions.

  • Volume-scattering events are currently classified as glossy (VG).

Further Reading#