Skip to content

EnvironmentSyncSystem ​

Applies the scene-level Environment component to the THREE.js scene: background color, gradient textures, image skyboxes, fog, and the optional lighting block (HDRI environment map, tone mapping, exposure).

Overview ​

EnvironmentSyncSystem runs every frame and is responsible for:

  • Generating canvas-based gradient textures (linear, radial, angular) from the color stops defined in the Environment component and setting them as scene.background.
  • Loading image skyboxes: a flat screen backdrop through THREE.TextureLoader by default, or a 360° panorama when skybox.imageProjection is "equirect" (.hdr and .exr supported).
  • Loading lighting.envMapUrl (HDRLoader for .hdr, EXRLoader for .exr, TextureLoader otherwise), pre-filtering it with PMREMGenerator on WebGL (on WebGPU the equirect texture is assigned as is and WebGPURenderer pre-filters it) and assigning scene.environment, scene.environmentIntensity and scene.environmentRotation. With lighting.useAsBackground it also becomes scene.background with the authored blur, intensity and rotation.
  • Setting renderer.toneMapping and renderer.toneMappingExposure from lighting.toneMapping / lighting.exposure, combined with the post-processing tone-mapping effect as described on the Environment page.
  • Applying solid color backgrounds directly as THREE.Color.
  • Configuring THREE.FogExp2 or THREE.Fog from the fog sub-state (near, far, density, color).
  • Disposing previous textures when the background changes to prevent GPU memory leaks.

Queried components ​

ComponentAccess
EnvironmentRead (background type, colors, fog state)

Behavior notes ​

  • Signature-based change detection: the system keeps one signature each for the skybox, fog and lighting. A part is re-applied only when its own signature changes, so animating lighting.envIntensity never rebuilds the skybox texture.
  • Lighting is opt-in: without a lighting block the system never writes scene.environment or the renderer's tone mapping. Removing the block, or disposing the system, restores the values they had before.
  • Async env maps: a newer envMapUrl always wins over a load still in flight, and the previous PMREM target and source texture are disposed when the new map swaps in.
  • Passthrough: while world.isXrPassthrough() is true the background stays null so the real room shows. Fog and image-based lighting keep applying.
  • Gradient texture: generated on a 512×512 <canvas> element. In server-side or non-DOM environments a single-pixel DataTexture fallback is used instead.
  • Fog clamping: fog near and far values are clamped so far > near + 0.001 and density is clamped to ≥ 0. Invalid values are replaced with safe defaults.
  • Pending image URL: image/HDRI loads are queued via an internal pending URL field; a stale load result is discarded if the component signature changed again before the load finished.

API reference ​