Overview
In this tutorial, you’ll learn how to:- Create PBR materials with metallic-roughness parameters
- Load and display 3D meshes
- Set up image-based lighting (IBL)
- Configure directional lights
- Apply material parameters for realistic rendering
Complete Source Code
The complete example is available insamples/hellopbr.cpp.
Define the Application Structure
Set up the basic application structure:The IBL folder contains precomputed environment maps generated by the
cmgen tool.Configure Application Settings
Set up the application with IBL support:Setting
config.iblDirectory enables FilamentApp to automatically load and configure IBL.Create PBR Material
Build a PBR material with metallic-roughness parameters:This loads a pre-compiled PBR material. The material definition (
aiDefaultMat.mat) specifies:Create Material Instance and Set Parameters
Create a material instance and configure PBR properties:Parameter meanings:
baseColor: Surface color in linear RGB space (0.8 = light gray)metallic: 1.0 = fully metallic, 0.0 = non-metallic (dielectric)roughness: 0.0 = mirror-like, 1.0 = completely roughreflectance: Controls reflections for dielectrics (0.5 = 4% reflectance)
Load 3D Mesh
Load a mesh from embedded binary data:The
MeshReader utility:- Parses the mesh format
- Creates vertex and index buffers
- Builds renderable entities
- Applies the material instance
Position the Mesh
Set up the initial transform:This:
- Positions the mesh at Z = -4 (4 units away from camera)
- Stores the base transform for animation
- Disables shadow casting
- Adds the entity to the scene
Create Directional Light
Add a sun light for direct illumination:Light properties:
SUN: Directional light with parallel rayscolor: Warm white color (converted from sRGB to linear)intensity: 110,000 lux (bright daylight)direction: Light direction vector (not normalized)sunAngularRadius: 1.9 degrees (realistic sun size)
Animate the Mesh
Add rotation animation:This rotates the mesh around the Y-axis (vertical), showing how light interacts with the surface from different angles.
Understanding PBR Parameters
Base Color
The base color represents:- For metals: The color of reflected light (e.g., gold = yellow-orange)
- For dielectrics: The diffuse surface color
Metallic
Controls whether the surface behaves as:1.0: Metal (reflective, no diffuse)0.0: Dielectric/non-metal (has diffuse component)- Values between 0-1 create blended behavior
Roughness
Controls microsurface detail:0.0: Perfect mirror reflections0.5: Moderate roughness (brushed metal)1.0: Completely diffuse reflections
Reflectance
For dielectrics only, controls the amount of specular reflection at normal incidence:0.5: Common dielectrics (~4% reflectance)0.35: Water (~2% reflectance)0.7: Glass (~8% reflectance)
Image-Based Lighting
Generating IBL
Use thecmgen tool to generate IBL from an environment map:
ibl_output_ibl.ktx: Prefiltered environment mapibl_output_skybox.ktx: Skybox cubemap- Spherical harmonics coefficients
IBL Components
FilamentApp automatically loads:- Indirect Light: Prefiltered environment for reflections
- Skybox: Background environment
- Spherical Harmonics: Efficient diffuse irradiance
Light Types
Filament supports several light types:Color Spaces
Filament uses linear color space for lighting calculations:Building and Running
Next Steps
- glTF Viewer - Load complex models with textures and multiple materials
- Custom Materials - Create advanced material shaders
- Learn about Material System for more material options