cmgen is a command-line tool for generating spherical harmonics and mipmap levels from environment maps. It processes HDR images to create the data needed for Image-Based Lighting (IBL) in Filament.
Usage
Supported Input Formats
- PNG (8 and 16 bits)
- Radiance (
.hdr) - Photoshop (
.psd, 16 and 32 bits) - OpenEXR (
.exr)
Supported Aspect Ratios
- 2:1 - Latitude/longitude or equirectangular
- 3:4 - Vertical cross (height must be power of two)
- 4:3 - Horizontal cross (width must be power of two)
Common Options
Output Configuration
-
--type, -t <type>- Specify output type (default:cubemap)cubemap- Individual cubemap facesktx- KTX container formatequirect- Equirectangular projectionoctahedron- Octahedral projection
-
--format, -f <format>- Specify output file formatpng,hdr,rgbm,rgb32f,exr,psd,dds,ktx- KTX files are always KTX1 (not KTX2), encoded with 3-channel RGB_10_11_11_REV data
ktxformat implies--type=ktx
-
--size, -s <power-of-two>- Size of output cubemaps (base level), default is 256- Also applies to DFG LUT
Compression
--compression, -c <compression>- Format-specific compression:- KTX: Ignored
- PNG: Ignored
- Radiance: Ignored
- Photoshop:
16(default),32 - OpenEXR:
RAW,RLE,ZIPS,ZIP,PIZ(default) - DDS:
8,16(default),32
IBL Generation
Deployment
--deploy, -x <dir>- Generate everything needed for deployment into specified directory- Automatically generates: SH coefficients, cubemap faces, and pre-filtered reflections
Roughness Pre-filtering
--ibl-ld <dir>- Generate roughness pre-filtered reflection maps into directory- Creates mipmaps for different roughness levels
Spherical Harmonics
--sh-shader- Generate irradiance SH coefficients for shader code- Outputs pre-scaled spherical harmonics suitable for real-time rendering
Sampling
--ibl-samples <numSamples>- Number of samples for IBL integrations (default: 1024)- Higher values produce better quality but take longer
Minimum LOD Size
--ibl-min-lod-size <size>- Minimum LOD size (default: 16)- Must be a power of two
Face Extraction
--extract <dir>- Extract cubemap faces into specified directory--extract-blur <roughness>- Blur the cubemap before saving faces using roughness parameter (0.0 to 1.0)
Processing Options
-
--clamp- Clamp environment before processing- By default, environments are not clamped
-
--no-mirror- Skip mirroring of generated cubemaps- Use for assets with mirroring already baked in
- By default, cubemaps are mirrored
-
--quiet, -q- Suppress all non-error output
Advanced Options
Spherical Harmonics (Advanced)
--sh <bands>- SH decomposition of input cubemap with specified number of bands--sh-output <filename>- SH output filename (extension determines format)- Supported:
.exr,.hdr,.psd,.rgbm,.rgb32f,.png,.dds,.txt,.bin
- Supported:
--sh-irradiance, -i- Generate irradiance SH coefficients--sh-window <cutoff|no|auto>- SH windowing to reduce ringing (default:auto)
IBL Processing (Advanced)
--ibl-is-mipmap <dir>- Generate mipmaps for pre-filtered importance sampling--ibl-irradiance <dir>- Generate diffuse irradiance into directory--ibl-no-prefilter- Use importance sampling instead of pre-filtered importance sampling--ibl-dfg <filename>- Compute the IBL DFG LUT (for internal use)--ibl-dfg-multiscatter- Compute DFG for multi-scattering GGX--ibl-dfg-cloth- Add 3rd channel to DFG for cloth shading
Debug
--debug, -d- Generate extra data for debugging
Examples
Generate IBL for deployment
- Pre-filtered reflection maps at various roughness levels
- Spherical harmonics coefficients for diffuse lighting
- Cubemap faces for skybox
Create pre-filtered reflections with custom settings
Extract blurred cubemap faces
Generate KTX output with spherical harmonics
Process with specific compression
Generate from equirectangular with deployment
UV Grid Generation
If the input file doesn’t exist,cmgen can generate UV grid patterns:
Output Structure
When using--deploy, the tool creates:
Help
--help, -h- Print help message--license- Print copyright and license information