Skip to content

Engine → Renderer

environment_asset.h

Image-based lighting environments. The bake runs on the CPU inside the importer: equirect .hdr -> sky cubemap with a box-filtered mip chain -> SH9 irradiance -> GGX prefiltered specular cubemap. It is deterministic (fixed Hammersley sequence, fixed evaluation order, bit-identical whether faces are baked inline or on jobs) because the importer output is a cache key. The cooked .cenv holds both cubemaps as RGBA16F plus the SH9.

Structs

File Description
cubemap_data A cubemap with a mip chain, RGBA16F texels stored as packed halves. Faces follow the +X, -X, +Y, -Y, +Z, -Z convention; texels are stored mip-major then face-major, rows top to bottom.
environment_bake_options Bake sizes and their defaults. Tests use small sizes.
equirect_image A linear RGB equirectangular image (the decoded .hdr or JPEG XL).

Classes

File Description
environment_asset
environment_importer The .hdr importer: decodes the equirect image and bakes it (settings: environment_bake_options). A JPEG XL equirect (float, PQ or HLG; equirect_image::decode_hdr) bakes too when its .meta names this importer; the .jxl extension itself belongs to the texture importer.
environment_loader The conjure.renderer.environment loader; the fallback is the uniform grey environment of FALLBACK_ENVIRONMENT_RADIANCE, the same grey the renderer lights a scene without an environment by.

Type Aliases

sh9

using sh9 = std::array<math::vec3, 9>;

Nine spherical harmonics coefficients (bands 0..2) of RGB irradiance.

Constants

Name Type Value Description
ENVIRONMENT_ASSET_TYPE_NAME inline constexpr std::string_view "conjure.renderer.environment"
ENVIRONMENT_BLOB_VERSION inline constexpr u32 1
ENVIRONMENT_EXTENSIONS inline constexpr std::array<std::string_view, 1> {".hdr"}
ENVIRONMENT_IMPORTER_ID inline constexpr std::string_view "conjure.renderer.environment"
ENVIRONMENT_IMPORTER_VERSION inline constexpr u32 3
FALLBACK_ENVIRONMENT_RADIANCE inline constexpr f32 0.25f The grey radiance of both fallback environments: the loader's and the renderer's.
MAX_ENVIRONMENT_RADIANCE inline constexpr f32 std::numeric_limits<f32>::max() / 65536.0f The brightest radiance the bake integrates (about 5.2e33): equirect_image::decode_hdr and equirect_image::sample read +inf and anything brighter as this value. It is the largest float divided by 2^16, so the bake's largest sum, the GGX prefilter's over at most 4096 samples, stays 16 times below the float limit; the 4-texel mip averages and the SH9 coefficients (at most 4 pi x 0.63 times this) stay further below. Real radiance is many orders of magnitude darker (the sun's disc is about 1.6e9 cd/m^2), so a bright sun reaches the SH9 irradiance and the prefiltered mips unclipped; only the stored cubemap texels are clamped, to the half range (bake_environment).

Macros

CONJURE_DECLARE_ASSET_TYPE

CONJURE_DECLARE_ASSET_TYPE(conjure::renderer::environment_asset, "conjure.renderer.environment")

Functions

Public

bake_environment

[[nodiscard]] CONJURE_API core::result<environment_asset> bake_environment(
    const equirect_image &source,
    const environment_bake_options &options,
    core::jobs::job_system *jobs);

Bakes an environment on the CPU: cubemap, mips, SH9, GGX prefilter. Faces are baked through jobs->parallel_for when a job system is given and inline otherwise; the output is bit-identical either way. The mip chain, the SH9 projection and the prefilter run on 32-bit floats of the image's radiance as equirect_image::sample reads it, so a sun far brighter than a half holds still lights the irradiance and the rough mips fully; only the stored texels of both cubemaps are clamped to the finite half range [0, 65504] (NaN reads as 0), so a bright sun never packs to infinity. Fails with INVALID_ARGUMENT for an invalid image or options (sizes not powers of two or below 8, zero samples).

cubemap_texel_direction

[[nodiscard]] CONJURE_API math::vec3 cubemap_texel_direction(
    u32 face,
    u32 x,
    u32 y,
    u32 size) noexcept;

The direction through the centre of a cubemap texel, for a face index in the +X..-Z order and texel coordinates in [0, size).

evaluate_sh9_irradiance

[[nodiscard]] CONJURE_API math::vec3 evaluate_sh9_irradiance(
    const sh9 &coefficients,
    const math::vec3 &normal) noexcept;

Evaluates SH9 irradiance (already convolved with the cosine lobe) in a direction.