UsdLux lights: Worked Example — Visualization (NVIDIA-Certified Professional: OpenUSD Development)
UsdLux Lights: Worked Example in OpenUSD Visualization In the NVIDIA-Certified Professional: OpenUSD Development exam, understanding how to implement...
UsdLux Lights: Worked Example in OpenUSD Visualization
In the NVIDIA-Certified Professional: OpenUSD Development exam, understanding how to implement and manipulate UsdLux lights is essential for realistic 3D scene visualization. This worked example demonstrates step-by-step how to create and configure a UsdLux light within a USD stage to illuminate a scene effectively.
Scenario
You are developing a 3D content pipeline and need to add a UsdLux DistantLight to simulate sunlight in a scene. The goal is to position the light, set its intensity and color, and ensure it casts shadows correctly.
Step 1: Create a USD Stage
Begin by creating an in-memory USD stage to hold your scene elements.
Code Snippet
from pxr import Usd, UsdLuxstage = Usd.Stage.CreateNew('SceneWithLight.usda')
Step 2: Define the UsdLux DistantLight
Create a UsdLux.DistantLight prim at the desired path in the stage.
Code Snippet
light = UsdLux.DistantLight.Define(stage, '/World/SunLight')
Step 3: Set Light Parameters
Configure the light's attributes:
- Intensity: Controls the brightness of the light (measured in candela).
- Color: Defines the light color as an RGB tuple.
- Exposure: Adjusts the exposure value to simulate photographic exposure.
- Enable Shadows: Determines if the light casts shadows.
Code Snippet
light.CreateIntensityAttr(100000) # Bright sunlight intensitylight.CreateColorAttr((1.0, 0.95, 0.9)) # Warm sunlight colorlight.CreateExposureAttr(0) # Neutral exposurelight.CreateEnableShadowsAttr(True) # Enable shadows
Step 4: Position and Orient the Light
UsdLux DistantLight is directional and does not have a position but has an orientation defined by its transform. Set the transform to point the light in the desired direction (e.g., from above at an angle).
Code Snippet
from pxr import Gf, UsdGeomxform = UsdGeom.Xform.Define(stage, '/World/SunLight')rotation = Gf.Rotation(Gf.Vec3d(1, 0, 0), -45) # Rotate 45 degrees downward along X-axisxform.AddTransformOp().Set(rotation)
Step 5: Save the USD Stage
Once the light is configured, save the stage to disk.
Code Snippet
stage.GetRootLayer().Save()
Summary
This example demonstrated how to:
- Create a USD stage for a 3D scene.
- Define a UsdLux.DistantLight prim.
- Set key attributes such as intensity, color, exposure, and shadows.
- Apply a transform to orient the light directionally.
- Save the stage for use in rendering or further pipeline processing.
Mastering these steps helps build the understanding required for the NVIDIA-Certified Professional: OpenUSD Development exam's visualization section, specifically the use of UsdLux lights in realistic 3D content creation pipelines.
More in this topic
Ready to test your knowledge?
Put what you've learned into practice with a quick quiz and track your progress.
Test your knowledge →