rememberKTXEnvironment

fun rememberKTXEnvironment(engine: Engine, initialIntensity: Float, key: Any = Unit, onError: (Throwable) -> Unit? = null, skybox: suspend () -> ByteArray? = null, ibl: suspend () -> ByteArray): Environment

Loads an IBL environment (and optional skybox) from KTX1 data and wires it into the scene's indirect-light/skybox state. This is the convenience path over hand-wiring KTX1Loader, texture lifetimes, and IndirectLightState/SkyboxState.

Call it outside rememberFilamentScene { } (its result feeds the scene's parameters), so the engine is hoisted via io.github.erkko68.filament.compose.rememberFilamentEngine and shared with the scene — which is why it is required here rather than defaulted from the composition local: outside a scene there is no engine in scope to default to.

The returned Environment is non-null and stable; its states fill in once the KTX bytes load. Failures (load lambda throwing, or undecodable KTX) are reported once via onError and leave the corresponding state empty.

For raw equirectangular .hdr images (no offline cmgen bake) use rememberHDREnvironment.

Parameters

engine

Engine the environment's textures are allocated on. Leads the parameter list because it is required — the result feeds a scene built on this same engine, and this is called outside rememberFilamentScene { }, so there is never an engine in scope to default to.

initialIntensity

IBL intensity scale, applied to the state on first composition only — mutate environment.indirectLightState.intensity to change it afterwards.

key

Reloads when this changes. Defaults to Unit for static assets.

onError

Invoked once per failure (load threw, or the KTX failed to decode).

skybox

Optional loader for the skybox cubemap KTX. Null = IBL only, no background.

ibl

Loader for the IBL KTX (prefiltered reflection cubemap + irradiance SH).