Lighting & Shadows
Filament’s lighting system supports physically-based lighting with image-based lighting (IBL), punctual lights, and realistic shadow rendering.Shadow Rendering
Theshadowtest.cpp sample demonstrates directional light shadows with ground plane receivers.
Key Features
- Directional (sun) light with shadows
- Shadow casting and receiving configuration
- Ground plane shadow receiver
- Sun angular radius for soft shadows
Setting Up Shadow Casting Light
samples/shadowtest.cpp:97-105
The sun angular radius controls the softness of shadow edges. Larger values create softer, more realistic shadows but may impact performance.
Configuring Shadow Receivers
samples/shadowtest.cpp:87-94
Ground Plane Material
samples/shadowtest.cpp:139-181
The ground plane uses a special shadow material that composites shadows onto a simple quad, creating realistic contact shadows.
PBR Lighting
Thehellopbr.cpp and sample_full_pbr.cpp samples demonstrate physically-based rendering with IBL and direct lighting.
Basic PBR Setup
samples/hellopbr.cpp:119-123
Sun Light Configuration
samples/hellopbr.cpp:134-140
Light Parameters
- Color: Linear RGB color, use
Color::toLinear<ACCURATE>()for sRGB input - Intensity: In lux for directional lights (typical sun: 110,000 lux)
- Direction: Normalized direction vector pointing from the light
- Sun Angular Radius: Angular size in degrees (sun ~0.545°, larger for softer shadows)
Advanced PBR with Texture Maps
Thesample_full_pbr.cpp demonstrates a complete PBR workflow with multiple texture maps.
Supported Texture Maps
samples/sample_full_pbr.cpp:65-72
Dynamic Material Generation
The sample dynamically generates a material shader based on available textures:samples/sample_full_pbr.cpp:384-406
Parallax Occlusion Mapping
When a height map is present, the sample implements parallax occlusion mapping:samples/sample_full_pbr.cpp:280-308
Image-Based Lighting (IBL)
IBL is configured through the FilamentApp configuration:IBL Best Practices
- Generate with cmgen: Use Filament’s cmgen tool to preprocess HDR environment maps
- Resolution: 256x256 or 512x512 is sufficient for most use cases
- Intensity: Adjust IBL intensity to balance with direct lighting
- Rotation: Rotate IBL to align with scene lighting direction
Ambient Occlusion
AO can be baked into textures or calculated with SSAO:samples/sample_full_pbr.cpp:243-250
Multi-Bounce Ambient Occlusion
For more realistic results, enable multi-bounce AO:samples/sample_full_pbr.cpp:394-395
Bent normal maps improve specular AO by providing the least-occluded direction for each pixel.
Light Types & Intensities
| Light Type | Unit | Typical Range |
|---|---|---|
| SUN (directional) | lux | 100,000 - 120,000 |
| Point/Spot | lumens | 100 - 10,000 |
| Indoor ambient | lux | 100 - 1,000 |
Related Samples
lightbulb.cpp- Point light demonstrationgltf_viewer.cpp- Complete lighting pipeline with GUI controlsmaterial_sandbox.cpp- Interactive lighting and material editor