Overview
The glTF viewer demonstrates:- Loading glTF 2.0 files (.gltf and .glb)
- Asynchronous resource loading (textures, buffers)
- Material variants and optimization
- Camera controls and animation
- IBL and lighting setup
- Interactive UI with ImGui
- Debugging tools and visualization
Architecture
The viewer is built with several key components:Complete Implementation
Initialize Asset Loader
Set up the glTF asset loader with material provider:Material sources:
- JIT Shader: Compiles materials on-demand (slower load, optimized shaders)
- Ubershader: Pre-compiled uber-shader (faster load, more shader complexity)
Load glTF File
Read the glTF file and create the asset:The
createAsset function:- Parses the glTF JSON structure
- Creates Filament entities for all nodes
- Sets up materials and renderables
- Does NOT load textures yet (async operation)
Load Resources Asynchronously
Start async loading and monitor progress:Async loading prevents blocking the main thread during texture decompression.
Configure Image-Based Lighting
Set up IBL from the configuration:FilamentApp loads IBL from
config.iblDirectory.Set Up Viewer GUI
Initialize the viewer with UI controls:ViewerGui provides:
- Material editor
- Lighting controls
- Camera settings
- Debug visualization
- Animation controls
Handle Model Scaling
Optionally fit models into a unit cube:This centers and scales the model for consistent viewing, unless
--actual-size is specified.Key Features
Material Optimization
Choose between two material strategies:Camera Modes
Two camera control modes:- Mouse drag: Pan camera
- Scroll wheel: Adjust speed
- W/S: Forward/backward
- A/D: Left/right
- E/Q: Up/down
Feature Levels
Specify rendering feature level:Automation and Testing
Run automated tests:glTF Support
Filament supports glTF 2.0 features:Core Features
- Meshes with multiple primitives
- Node hierarchy and transforms
- PBR metallic-roughness materials
- Normal maps, occlusion, emissive
- Texture transforms
- Multiple UV sets
Extensions
KHR_materials_unlitKHR_materials_emissive_strengthKHR_texture_transformKHR_mesh_quantizationKHR_lights_punctual
Animations
- Translation, rotation, scale
- Morph targets
- Skinning (with normalization)
Performance Tips
Texture Compression
Use KTX2 for faster loading:Material Compilation
Pre-compile materials for your target platform to avoid runtime compilation.Asset Optimization
Optimize glTF files:- Remove unused materials and textures
- Use Draco compression for geometry
- Combine meshes where possible
- Use appropriate texture resolutions
Building and Running
Next Steps
- Custom Materials - Create custom material shaders
- Learn about glTF Extensions for advanced features
- Explore Material System for material customization