# forge-ibl-bake
**Drop in an HDRI, get wgpu/Bevy-ready IBL textures. No Blender, no Substance, no C++ build.**
A single static binary (or library) that converts an equirectangular `.hdr` file into the three engine-ready IBL textures required by any PBR renderer. Outputs standard KTX2 — wgpu, Bevy, and any Vulkan/Metal/DX12 loader can consume them directly.
---
## Features
By default, `forge-ibl-bake` builds as a lean, single-threaded binary. You can enable performance and format extensions via feature flags:
* **`parallel`** — Enables multi-core bake processing powered by Rayon. Drops total bake times linearly with your CPU core count.
* **`exr`** — Adds support for parsing OpenEXR (`.exr`) input files in addition to standard Radiance HDR files.
---
## Install
To install the standard single-threaded version:
```bash
cargo install forge-ibl-bake
To install with full multi-core performance and EXR support enabled (recommended):Bashcargo install forge-ibl-bake --features parallel,exr
Requirements: Stable Rust ≥ 1.85 (edition 2024). Zero system dependencies. Cross-compiles out of the box to any Rust target.UsageBashforge-ibl-bake --input env.hdr --out ./baked/
Advanced OptionsBashforge-ibl-bake --input env.hdr --out ./baked/ \
[--specular-size 256] # Cubemap face px for prefiltered specular (default 256)
[--irradiance-size 32] # Cubemap face px for diffuse irradiance (default 32)
[--lut-size 128] # BRDF LUT texture dimension (default 128)
[--samples 1024] # Monte-Carlo samples per texel (default 1024)
[--format ktx2] # Output format: ktx2 (default)
[--sh] # Emit SH9 JSON instead of irradiance cubemap
[--seed 0] # Reserved; v0 bake is fully deterministic (Hammersley)
OutputsFileDescriptionwgpu bindibl_specular.ktx2Prefiltered specular cubemap mip-chain (GGX split-sum, Karis 2013)TextureViewDimension::Cubeibl_irradiance.ktx2Diffuse irradiance cubemap (cosine-weighted convolution)TextureViewDimension::Cubeibl_brdf_lut.ktx2Split-sum BRDF integration LUT, R16G16 (DFG term)TextureViewDimension::D2If --sh is supplied, ibl_sh9.json replaces the irradiance cubemap with 9 RGB Spherical Harmonics coefficients.30-Second DemoBash# Download any HDRI from Poly Haven (e.g. kloppenheim_06_4k.hdr)
forge-ibl-bake --input kloppenheim_06_4k.hdr --out ./baked/ --specular-size 256 --samples 1024
# Load the asset directly in Bevy:
# asset_server.load::<Image>("baked/ibl_specular.ktx2")
Expected Assets & Performance:baked/ibl_specular.ktx2 (~3.1 MB)baked/ibl_irradiance.ktx2 (~24 KB)baked/ibl_brdf_lut.ktx2 (~32 KB)Total wall time: ~10 seconds on a modern multi-core CPU (compiled with --features parallel at 1024 samples).Math & MethodologySpecular Prefilter: GGX importance sampling (Karis, "Real Shading in Unreal Engine 4", SIGGRAPH 2013). Hammersley low-discrepancy sequence used for perfect determinism.Diffuse Irradiance: Cosine-weighted hemisphere convolution calculated via Hammersley sampling.BRDF LUT: Split-sum DFG pre-integration embedded with a Smith G visibility term.SH9: Real spherical harmonics ($l=0..2$) projected precisely using Fibonacci-sphere sampling.All math configurations are completely hand-written from open public references. No proprietary algorithms or opaque dependencies.LicenseDual-licensed under either MIT or Apache-2.0 at your discretion.