<Environment/>
The <Environment/> component is used to configure the environment lighting and skybox for a scene. It provides a simple way to set up global lighting, and other effects that affect the entire scene.
With an <Environment/> component in your scene, you can:
- Set the background texture for the scene
- Provides Image-Based Lighting (IBL) for realistic environmental reflections
- Controls sky dome properties, rotation, scale, and positioning
- Manages exposure, luminance, and other global lighting parameters
Usage
Place the <Environment/> component within an <Application/> and add it to the scene. You'll need to load a HDR or environment atlas and provide it to the component.
You only need one <Environment/> component for the entire scene. Using multiple <Environment/> components within the same <Application/> will trigger a warning.
Simply load a HDR and set it as the skybox. You can find great HDR images on HDRI Haven.
const EnvironmentExample = () => {
const { asset: skybox } = useTexture('/env.hdr')
return (
<Environment skybox={skybox} />
{/* The rest of your scene... */}
)
}
The component will affect the entire scene, so you should only use it once. You can specify global lighting parameters like exposure, luminance, and other global lighting parameters. See the Properties section for more details.
You can also use the <Environment/> component to create a dome effect. This is useful for creating a more realistic environment with a ground plane. You can specify the scale, position, rotation, and other properties of the dome.
- Demo
- Code
// ↑ imports hidden
export const EnvironmentExample = () => {
const { exposure, environment } = useControls(vars)
// Load the assets
const { asset: lambo } = useModel('/assets/lambo.glb');
const { asset: skybox } = useTexture(environment);
if (!lambo || !skybox) return null;
return (<>
{/* Environment with controllable settings */}
<Environment
type="dome"
skybox={skybox}
exposure={exposure}
scale={[15, 15, 15]}
center={[0.0, 0.09, 0.0]}
rotation={[0, 290, 0]}
showSkybox={true}
/>
{/* Render the model */}
<Entity name='lambo'>
<Render asset={lambo} />
</Entity>
</>);
}
Properties
| Name | Type | Default |
|---|---|---|
device? | - | |
scene? | - | |
centerArray? | Float32Array<ArrayBuffer> | - |
projectedSkydomeCenterId? | - | |
type? | stringThe type of the sky. One of the SKYMESH_* constants. Defaults to SKYTYPE_INFINITE.
Can be:
- SKYTYPE_INFINITE
- SKYTYPE_BOX
- SKYTYPE_DOME | - |
depthWrite? | booleanWhether depth writing is enabled for the sky. Defaults to false.
Writing a depth value for the skydome is supported when its type is not
SKYTYPE_INFINITE. When enabled, the depth is written during a prepass render pass and
can be utilized by subsequent passes to apply depth-based effects, such as Depth of Field.
Note: For the skydome to be rendered during the prepass, the Sky Layer must be ordered before
the Depth layer, which is the final layer used in the prepass.
Returns whether depth writing is enabled for the sky. | - |
scale? | [number, number, number]The scale of the sky. | - |
position? | [number, number, number]The position of the sky. | - |
center? | [number, number, number]The center of the sky. | - |
rotation? | [number, number, number]The rotation of the sky. | - |
showSkybox? | booleanWhether to show the skybox. | - |
ambientBake? | booleanIf enabled, the ambient lighting will be baked into lightmaps. This will be either the
Scene#skybox if set up, otherwise Scene#ambientLight . Defaults to false. | - |
ambientBakeOcclusionBrightness? | numberIf Scene#ambientBake is true, this specifies the brightness of ambient occlusion.
Typical range is -1 to 1. Defaults to 0, representing no change to brightness. | - |
ambientBakeOcclusionContrast? | numberIf Scene#ambientBake is true, this specifies the contrast of ambient occlusion.
Typical range is -1 to 1. Defaults to 0, representing no change to contrast. | - |
ambientLight? | ColorThe color of the scene's ambient light, specified in sRGB color space. Defaults to black
(0, 0, 0). | - |
ambientLuminance? | numberThe luminosity of the scene's ambient light in lux (lm/m^2). Used if physicalUnits is true. Defaults to 0. | - |
exposure? | numberThe exposure value tweaks the overall brightness of the scene. Ignored if physicalUnits is true. Defaults to 1. | - |
lightmapSizeMultiplier? | numberThe lightmap resolution multiplier. Defaults to 1. | - |
lightmapMaxResolution? | numberThe maximum lightmap resolution. Defaults to 2048. | - |
lightmapMode? | numberThe lightmap baking mode. Can be:
- BAKE_COLOR: single color lightmap
- BAKE_COLORDIR: single color lightmap + dominant light direction (used for bump or
specular). Only lights with bakeDir=true will be used for generating the dominant light
direction.
Defaults to BAKE_COLORDIR. | - |
lightmapFilterEnabled? | booleanEnables bilateral filter on runtime baked color lightmaps, which removes the noise and
banding while preserving the edges. Defaults to false. Note that the filtering takes place
in the image space of the lightmap, and it does not filter across lightmap UV space seams,
often making the seams more visible. It's important to balance the strength of the filter
with number of samples used for lightmap baking to limit the visible artifacts. | - |
lightmapHDR? | booleanEnables HDR lightmaps. This can result in smoother lightmaps especially when many samples
are used. Defaults to false. | - |
root? | EntityThe root entity of the scene, which is usually the only child to the Application
root entity. | - |
physicalUnits? | booleanUse physically based units for cameras and lights. When used, the exposure value is ignored. | - |
updateShaders? | boolean | - |
immediate? | - | |
ambientBakeNumSamples? | numberSets the number of samples used to bake the ambient light into the lightmap. Note that
Scene#ambientBake must be true for this to have an effect. Defaults to 1. Maximum
value is 255.
Gets the number of samples used to bake the ambient light into the lightmap. | - |
ambientBakeSpherePart? | numberSets the part of the sphere which represents the source of ambient light. Note that
Scene#ambientBake must be true for this to have an effect. The valid range is 0..1,
representing a part of the sphere from top to the bottom. A value of 0.5 represents the
upper hemisphere. A value of 1 represents a full sphere. Defaults to 0.4, which is a smaller
upper hemisphere as this requires fewer samples to bake.
Gets the part of the sphere which represents the source of ambient light. | - |
clusteredLightingEnabled? | booleanSets whether clustered lighting is enabled. Set to false before the first frame is rendered
to use non-clustered lighting. Defaults to true.
Gets whether clustered lighting is enabled. | - |
layers? | LayerCompositionSets the LayerComposition that defines rendering order of this scene.
Gets the LayerComposition that defines rendering order of this scene. | - |
lightmapFilterRange? | numberSets the range parameter of the bilateral filter. It's used when Scene#lightmapFilterEnabled
is enabled. Larger value applies more widespread blur. This needs to be a positive non-zero
value. Defaults to 10.
Gets the range parameter of the bilateral filter. | - |
lightmapFilterSmoothness? | numberSets the spatial parameter of the bilateral filter. It's used when Scene#lightmapFilterEnabled
is enabled. Larger value blurs less similar colors. This needs to be a positive non-zero
value. Defaults to 0.2.
Gets the spatial parameter of the bilateral filter. | - |
prefilteredCubemaps? | Texture[]Sets the 6 prefiltered cubemaps acting as the source of image-based lighting.
Gets the 6 prefiltered cubemaps acting as the source of image-based lighting. | - |
skyboxIntensity? | numberSets the multiplier for skybox intensity. Defaults to 1. Unused if physical units are used.
Gets the multiplier for skybox intensity. | - |
skyboxLuminance? | numberSets the luminance (in lm/m^2) of the skybox. Defaults to 0. Only used if physical units are used.
Gets the luminance (in lm/m^2) of the skybox. | - |
skyboxMip? | numberSets the mip level of the skybox to be displayed. Only valid for prefiltered cubemap skyboxes.
Defaults to 0 (base level).
Gets the mip level of the skybox to be displayed. | - |
skyboxHighlightMultiplier? | numberSets the highlight multiplier for the skybox. The HDR skybox can represent brightness levels
up to a maximum of 64, with any values beyond this being clipped. This limitation prevents
the accurate representation of extremely bright sources, such as the Sun, which can affect
HDR bloom rendering by not producing enough bloom. The multiplier adjusts the brightness
after clipping, enhancing the bloom effect for bright sources. Defaults to 1.
Gets the highlight multiplied for the skybox. | - |
skyboxRotation? | QuatSets the rotation of the skybox to be displayed. Defaults to Quat.IDENTITY.
Gets the rotation of the skybox to be displayed. | - |
skybox? | Asset | nullThe skybox asset.
Used to set the skybox of the environment. | - |
envAtlas? | Asset | nullThe environment lighting.
Used to set the lighting of the environment. | - |