Skip to main content

Module environment_map

Module environment_map 

Source
Expand description

Compiles an EnvironmentMap component’s args into a payload bundling two precomputed IBL cubemaps:

  • Irradiance cubemap. Low-resolution (32x32 per face by default) cosine-weighted hemisphere integral of the source. Used by the shader’s diffuse ambient term: diffuse = (1-F)(1-metallic) * irradiance * albedo / π.
  • Prefiltered radiance cubemap. A mip chain where mip 0 = source and mip N = source convolved with the GGX lobe at roughness = N / (mip_count - 1). Used with the Karis env-BRDF analytic fit (already in every fragment shader as env_brdf_approx) for the specular ambient term.

A BRDF LUT is deliberately NOT shipped: the Karis polynomial fit (env_brdf_approx in main_shading.slang) replaces it analytically. That keeps one binding slot free and dodges a build step.

Source format: equirectangular Radiance HDR (.hdr), same as CubemapTexture. Sampling: Hammersley QMC + GGX importance sampling for prefilter, uniform (phi, theta) grid for irradiance.

The convolutions themselves are bake, which decomposes them into independent output rows so a caller can spread the work over its own thread pool. This module is the payload format around them.

Payload format (little-endian): u32 magic = b“ENVM“ = 0x4D564E45 u32 format_id = 0 (RGBA32F) u32 irradiance_face (e.g. 32) u32 prefilter_face (mip 0 size, e.g. 512) u32 prefilter_mips (e.g. 5) u32 _pad … irradiance cube (6 * irradiance_face² * 16 bytes) … prefilter mip 0 (6 * prefilter_face² * 16 bytes) … prefilter mip 1 (6 * (prefilter_face/2)² * 16 bytes) … … prefilter mip (mips-1) (6 * (prefilter_face >> (mips-1))² * 16 bytes)

Face order matches CubemapTexture: +X, -X, +Y, -Y, +Z, -Z.

Re-exports§

pub use bake::CubeBake;
pub use bake::DEFAULT_IRRADIANCE_PHI_SAMPLES;
pub use bake::DEFAULT_IRRADIANCE_THETA_SAMPLES;
pub use bake::FaceRow;
pub use bake::compute_irradiance;
pub use bake::compute_prefilter;
pub use bake::face_rows;
pub use bake::prefilter_mip0;
pub use bake::prefilter_roughness;
pub use schedule::RowScheduler;
pub use schedule::Serial;

Modules§

bake
The IBL convolutions themselves: cube sampling, the two kernels, and the row-sized unit of work they decompose into.
schedule
How a caller runs the independent rows an environment-map convolution decomposes into.
source
Equirectangular sources for the IBL bake: the in-memory image type, the resampler that turns one into the six cube faces the convolutions read, the built-in sky generator, and the full source-to-payload bake. Decoding a source file into an HdrImage is the cook crate’s job; nothing here touches I/O.
stars
The stars equirectangular generator: a night sky of scattered point stars over a near-black background that darkens below the horizon.

Structs§

EnvMapView
Metadata read from a serialised EnvironmentMap payload. The byte ranges point into the payload buffer so the runtime can upload them directly.

Functions§

check_sizes
Check an EnvironmentMap’s baked dimensions: both cube edges must be powers of two inside the range the shader’s mip assumptions hold for, and the reflection clamp must be a finite non-negative gain. Shared by the cook pipeline and the bake builder so a world is refused the same way whichever declared it.
deserialise
Read a packed payload back as byte-range views into bytes.
max_mip_count
Number of mip levels for a square cube face of face_size pixels. The smallest mip is clamped to 4×4 to keep the prefilter convolution sensible at high roughness.
serialise_payload
Pack the baked irradiance and prefilter cubes into a blob payload.