captureEnvironment method
Captures the scene's linear HDR lighting at position into a new
EnvironmentMap: renders the scene into six cube faces (with shadows
and analytic lights, without screen-space effects or post-processing),
then prefilters the result like any other environment.
The returned environment reflects the scene at the moment of capture; nothing re-captures it. For a node-anchored probe with parallax-corrected sampling and automatic blending, use ReflectionProbeComponent instead.
The engine resources must be loaded (isReadyToRender); throws StateError otherwise.
Implementation
EnvironmentMap captureEnvironment({
required Vector3 position,
int faceResolution = 128,
int equirectWidth = 512,
int layerMask = 0xFFFFFFFF,
}) {
if (!isReadyToRender) {
throw StateError(
'Scene.captureEnvironment requires the engine resources; await '
'Scene.initializeStaticResources() first.',
);
}
renderScene.rebuildIfDirty();
final lightComponent = renderScene.primaryDirectionalLight;
final spotShadowFrame = collectSpotShadows(renderScene.spotLights);
final punctualLighting = _punctualLightBuffer.build(
directionals: renderScene.directionalLights,
primaryDirectional: lightComponent,
points: renderScene.pointLights,
spots: renderScene.spotLights,
areas: renderScene.rectAreaLights,
items: renderScene.items,
bvh: renderScene.bvh,
spotShadows: spotShadowFrame,
);
return _captureEnvironmentAt(
position: position,
faceResolution: faceResolution,
equirectWidth: equirectWidth,
layerMask: layerMask,
environmentMap: environment ?? Material.getDefaultEnvironmentMap(),
transientsBuffer: uniformTransients,
lightComponent: lightComponent,
punctualLighting: punctualLighting,
spotShadowFrame: spotShadowFrame,
);
}