Environment
The Environment component holds scene-wide settings:
- Skybox: gradient, solid color, image (flat backdrop or 360° panorama), or none.
- Fog: linear, exponential, or none.
- Gravity: the world gravity vector applied by the physics system (in m/s²).
- Lighting (optional): an HDRI environment map for image-based lighting, plus tone mapping and exposure. See Image-based lighting and HDRI.
It is a singleton there is exactly one Environment entity per scene, owned by the editor.
In the editor, these settings are the Skybox, Fog, Lighting and Gravity sections of World Config. See World Config.
Managed by:
EnvironmentSyncSystem
Get the component from the world
Use world.getEnvironmentComponent(), a convenience method that handles the entity lookup for you:
import { Behaviour } from "@relu-interactives/spatial-ecs";
export default class ReadEnvironment extends Behaviour {
init() {
const env = this.world.getEnvironmentComponent();
if (!env) return;
console.log("skybox type", env.values.skybox.type);
console.log("gravity", env.values.gravity);
}
}env.values is the live state object. Mutating fields on it is enough, EnvironmentSyncSystem reads it every frame and pushes changes into the three.js scene.
Change values at runtime
Switch the skybox
env.values.skybox.type = "gradient";
env.values.skybox.gradient.colors = ["#0b1026", "#3b6dd6", "#f7d488"];
env.values.skybox.gradient.effect = "linear"; // "linear" | "radial" | "angular"
// Or use a solid color:
env.values.skybox.type = "color";
env.values.skybox.color = "#101010";
// Or a 360° panorama that turns with the camera (.hdr, .exr, .jpg, .png):
env.values.skybox.type = "image";
env.values.skybox.imageUrl = "/assets/skies/studio.hdr";
env.values.skybox.imageProjection = "equirect";
// Leave imageProjection unset for a flat backdrop stretched over the screen.
// That mode only loads ordinary images (.jpg, .png, .webp), not .hdr/.exr.
// Or disable it:
env.values.skybox.type = "none";Configure fog
// Linear fog
env.values.fog.type = "linear";
env.values.fog.color = "#aabbcc";
env.values.fog.linear.near = 1;
env.values.fog.linear.far = 50;
// Exponential fog
env.values.fog.type = "exponential";
env.values.fog.exponential.density = 0.05;
// Off
env.values.fog.type = "none";Change physics gravity
// Moon-like gravity
env.values.gravity = { x: 0, y: -1.62, z: 0 };
// Zero-G
env.values.gravity = { x: 0, y: 0, z: 0 };Image-based lighting and HDRI
Without an environment map, PBR materials only see your lights. Metallic surfaces reflect nothing, so a sci-fi kit or a chrome prop renders close to black. An HDRI fixes that: it lights every material from all directions and gives metals something to reflect.
Set values.lighting to turn it on:
import { Behaviour } from "@relu-interactives/spatial-ecs";
export default class StudioLighting extends Behaviour {
init() {
const env = this.world.getEnvironmentComponent();
if (!env) return;
env.values.lighting = {
envMapUrl: "localasset://assets/hdri/studio_small.hdr",
envIntensity: 1, // strength of the image-based light
envRotationY: Math.PI / 2, // turn the HDRI to move the key highlight
useAsBackground: true, // also show the HDRI as the sky
backgroundBlurriness: 0.2,
backgroundIntensity: 1,
toneMapping: "aces", // "none" | "aces" | "agx" | "neutral"
exposure: 1,
};
}
}How each field behaves:
envMapUrlpicks the loader from the file extension..hdrand.exrload as linear HDR. Any other extension loads as an sRGB image. On WebGL the system pre-filters the map with three'sPMREMGeneratorand assigns it toscene.environment; on WebGPU it assigns the equirect texture and the renderer pre-filters it. An empty string removes the map.envIntensityandenvRotationYapply immediately, even while the map is still loading. You can animate them every frame without reloading anything.useAsBackgroundshows the same HDRI behind the scene and replaces the skybox while it is on. Turn it off and the skybox comes back. Use this instead of loading the same file twice as both an equirect skybox and an env map.backgroundBlurriness(0 to 1) softens the background, which keeps a low-resolution HDRI from looking pixelated. It only applies whenuseAsBackgroundis on.toneMappingandexposuresetrenderer.toneMappingandrenderer.toneMappingExposure. Exposure has no visible effect whiletoneMappingis"none". Use"aces"or"agx"with an HDRI: without tone mapping, bright HDR values clip to flat white.
Changing envMapUrl loads the new map in the background and swaps it in when ready. If you change the URL twice in a row, the last one wins even when the first finishes loading later. The system disposes the old map's GPU resources on every swap.
A quick recipe for a dark metallic model:
import { Behaviour } from "@relu-interactives/spatial-ecs";
export default class FixDarkMetal extends Behaviour {
init() {
const env = this.world.getEnvironmentComponent();
if (!env) return;
env.values.lighting = {
...env.values.lighting,
envMapUrl: "localasset://assets/hdri/warehouse.hdr",
envIntensity: 1.5,
toneMapping: "agx",
exposure: 1.1,
};
}
}When the block is absent
Scenes without values.lighting keep working exactly as before: the system never touches scene.environment or the renderer's tone mapping. Removing the block at runtime restores the values the scene and renderer had before it was applied.
Tone mapping and the post-processing stack
Postprocessing.values.toneMapping also controls tone mapping. When both are set, they combine like this:
Environment lighting.toneMapping | Post toneMapping.enabled (and postEnabled) | Operator used | Exposure used |
|---|---|---|---|
absent or "none" | off | none | (no effect) |
"aces" / "agx" / "neutral" | off | the environment's | lighting.exposure |
"aces" / "agx" / "neutral" | on | the environment's | post toneMapping.exposure |
absent or "none" | on | ACES Filmic | post toneMapping.exposure |
In short: the environment picks the operator, the post effect overrides the exposure, and the post effect alone means ACES.
Mixed reality and the editor
In a passthrough session (world.isXrPassthrough()) the background stays hidden so the real room shows through, including an HDRI with useAsBackground. Image-based lighting and tone mapping still apply to your virtual objects.
The editor viewport runs the same system, so the lighting you author is the lighting you see while editing.
Authorable values
| Path | Type | Default | Notes |
|---|---|---|---|
skybox.type | "gradient" | "color" | "image" | "none" | "none" | Active skybox mode. |
skybox.color | string (hex) | "#1e1e1e" | Used when type is "color". |
skybox.imageUrl | string | "" | Used when type is "image". |
skybox.imageProjection | "screen" | "equirect" | absent ("screen") | "equirect" wraps the image around the scene and loads .hdr/.exr. |
skybox.gradient.colors | string[] | ["#464766", "#657ea6", "#0f0e1a"] | Hex color stops. |
skybox.gradient.effect | "linear" | "radial" | "angular" | "linear" | Gradient distribution. |
fog.type | "linear" | "exponential" | "none" | "none" | Fog model. |
fog.color | string (hex) | "#1e1e1e" | Fog color. |
fog.linear.near | number | 1 | Distance where fog starts. |
fog.linear.far | number | 100 | Distance where fog reaches full opacity. |
fog.exponential.density | number | 0.002 | Higher = thicker fog. |
gravity | { x, y, z } | (0, -9.81, 0) | World units per second squared. |
lighting | object | absent | Optional. Absent leaves scene.environment and tone mapping untouched. |
lighting.envMapUrl | string | "" | Equirectangular env map. .hdr/.exr load as HDR. |
lighting.envIntensity | number | 1 | scene.environmentIntensity. |
lighting.envRotationY | number (radians) | 0 | Rotates the env map (and the background when used as one). |
lighting.useAsBackground | boolean | false | Show the env map as the background, replacing the skybox. |
lighting.backgroundBlurriness | number (0 to 1) | 0 | Background blur when useAsBackground is on. |
lighting.backgroundIntensity | number | 1 | Background brightness when useAsBackground is on. |
lighting.toneMapping | "none" | "aces" | "agx" | "neutral" | "none" | Renderer tone-mapping operator. |
lighting.exposure | number | 1 | Renderer exposure. Needs a tone-mapping operator to have an effect. |
API reference
- Class:
Environment - Source:
core/components/Environment.ts

