Sky & environment
Every scene has a physical atmosphere that draws the sky and bakes the image-based light from the scene's sun; an octahedral environment map replaces both. Covers the atmosphere's settings, the ways to supply a map, the CPU recipe for an authored one, volumetric fog, and the two path tracers.
There is no skybox object in the renderer, and no sky component. The sky behind the geometry and the image-based light every surface reads its indirect light from come from one source, and always the same one for both: the scene’s physical atmosphere, scene.atmosphere, or an octahedral environment map, scene.lights.environment. A map, when one is set, wins.
scene.lights.environment | scene.atmosphere.enabled | Background | Image-based light |
|---|---|---|---|
a ShadeTexture | either | the map, drawn by shader_background | the map |
undefined | true | the atmosphere as seen from the camera, drawn by shader_background_sky | a 256² octahedral map baked from the atmosphere |
undefined | false | black | black |
GraphicsEngine.set_scene(scene) settles the default: when scene.lights.environment === undefined it calls scene.atmosphere.enable_by_default(), so a scene handed over without a map gets a sky, and sky lighting, from its sun. An enabled you assigned yourself is respected either way, and a scene that arrives with a map keeps it. The bottom row is what is left - the renderer lights with indirect on by default, so a scene with neither source has a black background and no ambient light at all.
The atmosphere
Every Scene carries a SceneAtmosphere (src/shade/renderer/atmosphere/SceneAtmosphere.js) as scene.atmosphere: the parameters of a Hillaire (2020) sky, authored in metres and inverse metres. The planet’s centre sits at (0, -planet_radius, 0), so world y = 0 is sea level and +Y is up.
import { EngineHarness } from "@woosh/meep-engine/src/engine/EngineHarness.js";
const atmosphere = EngineHarness.shadeScene(engine).atmosphere;
// a hazier day: five times the aerosol
atmosphere.mie_scattering = [2e-5, 2e-5, 2e-5];
atmosphere.mie_extinction = [2.2e-5, 2.2e-5, 2.2e-5];
atmosphere.invalidate();
| Field | Default | Meaning |
|---|---|---|
enabled | false | Whether the atmosphere draws the sky and bakes the image-based light while the scene has no environment map. set_scene turns it on through enable_by_default() unless it was assigned; enabled_explicitly says whether it was. |
planet_radius | 6_378_000 | Centre to sea level, metres. |
atmosphere_height | 100_000 | Thickness of the shell above sea level, metres. |
rayleigh_scale_height | 8_000 | Exponential scale height of the molecular density, metres. |
rayleigh_scattering | [5.802e-6, 13.558e-6, 33.1e-6] | Sea-level Rayleigh scattering, RGB, per metre. |
mie_scale_height | 1_200 | Exponential scale height of the aerosol density, metres. |
mie_scattering | [3.996e-6, 3.996e-6, 3.996e-6] | Sea-level Mie scattering, RGB, per metre. |
mie_extinction | [4.44e-6, 4.44e-6, 4.44e-6] | Sea-level Mie extinction, RGB, per metre. Absorption is derived: max(mie_extinction - mie_scattering, 0). |
mie_phase_g | 0.8 | Cornette-Shanks asymmetry of the aerosol phase function, held inside ±0.999 on upload. |
ozone_center_height | 25_000 | Altitude of peak ozone density, metres. |
ozone_half_width | 15_000 | Half-width of the ozone layer’s tent profile, metres. |
ozone_absorption | [0.65e-6, 1.881e-6, 0.085e-6] | Peak ozone absorption, RGB, per metre. |
ground_albedo | [0.3, 0.3, 0.3] | Diffuse reflectance of the planet’s surface, for multiple scattering and the bounce that fills the lower hemisphere. |
reference_altitude | 1 | Altitude above sea level, metres, the image-based light is baked from. Held at least 10 m up (ATMOSPHERE_ALTITUDE_CUTOFF). |
sun_irradiance_scale | 1 | Multiplies the sun’s irradiance as the atmosphere sees it: brightens or dims the sky without touching the light. |
fallback_sun_enabled | true | Light the sky from the fallback sun when the scene has no directional light. |
fallback_sun_direction | (0.2, 1, -0.2), normalised | Unit vector toward the fallback sun. |
fallback_sun_irradiance | [6, 6, 6] | The fallback sun’s RGB irradiance. |
The fields are plain properties and nothing watches them. After changing the medium - the radii, heights, coefficients, phase or ground_albedo - call atmosphere.invalidate() (or set atmosphere.needsUpdate = true); either bumps atmosphere.version, which is what the GPU side compares. Assigning enabled bumps it for you. reference_altitude, sun_irradiance_scale and the fallback sun are read every frame and need no call.
The sun
The atmosphere has no sun of its own. resolve_atmosphere_sun(scene) (src/shade/renderer/atmosphere/resolve_atmosphere_sun.js) finds one each frame, taking the first of:
- The first
DirectionalLightinscene.lights.elements- under the ECS, aLightofLightType.DIRECTION. The sun stands opposite the way the light shines. Its irradiance is the light’s colour scaled to itsintensity(light_pack_color) timessun_irradiance_scale: the light as authored, above the air. - The fallback sun, when
fallback_sun_enabledis true:fallback_sun_directionandfallback_sun_irradiance, again timessun_irradiance_scale. - Nothing. The sky and its image-based light are black.
So the sky follows the light. Rotate the sun and the sky turns with it; raise its intensity and the sky brightens in proportion; a scene with no directional light at all still gets daylight from the fallback. The same light reaches a surface through this atmosphere, dimmed and reddened toward the horizon and black below it - see a directional light is authored above the air - so turning the light is all a day cycle does.
A sun disc is drawn only for a directional light with a radius above zero - its angular radius in radians. make_sunlight sets the sun’s 0.006475; EngineHarness.buildLights leaves its key light at 0, which draws a sky with no disc in it. The fallback sun never draws one. The disc is limb-darkened, dimmed by the atmosphere along the view ray, drawn no smaller than 0.0045 radians, and hidden where the view ray meets the planet.
What is drawn, and what is baked
The background is rebuilt every frame. shader_sky_view_lut (src/shade/renderer/atmosphere/shader_sky_view_lut.js) renders a 192 × 108 sky-view LUT for the camera’s position, and shader_background_sky (src/shade/renderer/deferred/shader_background_sky.js) samples it for every pixel no geometry covered, adding the disc. The camera’s altitude is its world y, held at least 10 m above sea level.
The image-based light is baked. GPULightCollection renders shader_sky_irradiance_lut into mip 0 of the scene’s environment texture - a 256² octahedral map (SKY_IRRADIANCE_LUT_RESOLUTION), skirt included, of the sky as seen from reference_altitude - and then convolves it into irradiance and roughness mips exactly as it does an authored map. Everything that samples the environment reads this map: indirect lighting, probe rays that leave the scene, the GPU path tracer’s misses. It holds the scattered sky and the ground’s bounce, not the disc; the sun’s direct light is the directional light’s.
The bake repeats when atmosphere.version, reference_altitude, or the resolved sun’s direction or irradiance differ from the last one baked, so a moving sun re-bakes and re-convolves the map every frame it moves.
Both read the same two tables. Each GPUSceneContext owns one GPUSky (src/shade/renderer/atmosphere/GPUSky.js), exposed as scene_context.sky and constructed over the scene’s SceneAtmosphere: a uniform buffer of the parameters, a 256 × 64 transmittance LUT and a 32 × 32 multiple-scattering LUT. GPUSky.update() uploads the parameters and rebuilds both LUTs when atmosphere.version has moved, and does nothing otherwise. Its readers are the background, the bake, and volumetric fog.
The environment map
Assign scene.lights.environment and the atmosphere steps aside for both jobs. The map is a single octahedral ShadeTexture: the image-based-lighting source, and what the background pass draws behind the geometry. Replace it and both change together. There is deliberately no set_environment_texture counterpart to set_environment_map - the map already is the visible sky.
Once the G-buffer and ambient occlusion exist and before indirect lighting is added, Renderer records shader_background (src/shade/renderer/deferred/shader_background.js). The pass is depth-tested equal against background depth, so it only touches pixels no geometry covered; for each of those it unprojects through the camera’s inverse view-projection matrix and calls sample_environment_color(tEnvironment, sEnvironment, view_direction), which reads mip 0 of the environment texture with bilinear octahedral filtering. The same texture is separately convolved on the GPU into an irradiance map and a set of roughness mips for the lighting path.
Two consequences worth internalising:
- Whatever you want in the sky has to be in the map. Sun disc, horizon haze, cloud shapes, time of day - nothing of the atmosphere is drawn over a map.
- The background is drawn at the map’s base resolution.
load_cube_environmentbuilds a 128² octahedral map, which is plenty for an ambient source but visibly soft as a backdrop. If the sky is meant to be looked at, build the map larger.
Three constraints apply to the texture:
| Constraint | Enforcement |
|---|---|
Must be a ShadeTexture | Asserted in the LightCollection.environment setter and again in GraphicsEngine.set_environment_map (texture.isShadeTexture === true) |
| Must be square, at least 48² | Asserted in GPULightCollection (width === height and width >> 4 >= 3, so the last of the five filtered levels still has an interior inside its skirt) |
| Must be octahedral-encoded with a one-texel skirt | GPULightCollection asserts octahedral_skirt_matches when CPU texels are on hand (Sampler2D or uncompressed ShadeTexelData). With assertions stripped, an unskirted map renders with seams along the octahedron’s edges; a cube or equirectangular texture samples as garbage |
Getting a texture in
| Call | Import | What you get |
|---|---|---|
load_cube_environment(folder_path, file_extension) | src/engine/graphics3/load_cube_environment.js | Promise<ShadeTexture>. Six sRGB face images, decoded to linear and reprojected to a 128² octahedral f16 map on the CPU at load. |
load_environment_map(url, projection) | src/shade/renderer/light/environment/rgbe/load_environment_map.js | Promise<ShadeTexture>. An RGBE .hdr file. See the download gotcha below. |
your own Sampler2D | - | Any radiance you can evaluate per direction. See the recipe. |
import { load_cube_environment } from "@woosh/meep-engine/src/engine/graphics3/load_cube_environment.js";
// fetches posx.png, negx.png, posy.png, negy.png, posz.png, negz.png
const texture = await load_cube_environment("/textures/sky/", ".png");
engine.graphics.set_environment_map(texture);
The face names and the extension are concatenated straight onto the folder path, so include the trailing slash and the leading dot.
The load_environment_map download gotcha
ProjectionMappingType is exported from the same file as { Equirectangular: 0, Octahedral: 1 }, and projection defaults to Equirectangular. On that branch the function resamples the panorama to octahedral on the main thread and then calls download_env_map(...), which hands the converted buffer to downloadAsFile(..., '<name>.hdr', 'binary'). In other words, loading an equirectangular .hdr triggers a file download in the player’s browser, every time, as a side effect.
Pass a pre-converted octahedral map instead:
import { load_environment_map, ProjectionMappingType }
from "@woosh/meep-engine/src/shade/renderer/light/environment/rgbe/load_environment_map.js";
engine.graphics.set_environment_map(
await load_environment_map("/textures/sky_octahedral.hdr", ProjectionMappingType.Octahedral)
);
The Octahedral branch parses the RGBE payload straight to Float16 and skips the resample entirely, which is both correct and much cheaper. The file that one accidental Equirectangular run downloads is the converted map - run the conversion once during authoring, ship the result, and never take the equirectangular path at runtime.
There is no prefilter step
set_environment_map does no prefiltering. The renderer convolves the map into its irradiance and roughness mips on the GPU, notices when the texture has been swapped, and redoes that work itself. Assignment is the entire API, and it is safe before startup as well as after:
engine.graphics.set_environment_map(texture); // also raises graphics.needDraw
scene.lights.environment = texture; // equivalent, minus the redraw flag
To hand both jobs back to the atmosphere, clear the map on the scene - set_environment_map asserts a texture:
scene.lights.environment = undefined;
scene.atmosphere.enabled = true; // a scene that reached set_scene with a map never had it turned on
Recipe: an authored environment on the CPU
Any sky you can evaluate per direction becomes an environment map through the chain load_cube_environment follows:
Sampling straight into the octahedral grid avoids an intermediate panorama and the orientation problem below:
import { Sampler2D }
from "@woosh/meep-engine/src/engine/graphics/texture/sampler/Sampler2D.js";
import { sampler2d_to_f16 }
from "@woosh/meep-engine/src/engine/graphics/texture/sampler/sampler2d_to_f16.js";
import { octahedral_z_pole_uv_to_direction }
from "@woosh/meep-engine/src/shade/renderer/light/environment/octahedral_z_pole_uv_to_direction.js";
import { sampler2d_octahedral_skirt_fill }
from "@woosh/meep-engine/src/shade/renderer/light/environment/sampler2d_octahedral_skirt_fill.js";
import { ColorSpace }
from "@woosh/meep-engine/src/shade/renderer/texture/ColorSpace.js";
import { ShadeTexture }
from "@woosh/meep-engine/src/shade/renderer/texture/ShadeTexture.js";
import { ShadeImage }
from "@woosh/meep-engine/src/shade/renderer/texture/source/ShadeImage.js";
const RESOLUTION = 512;
const interior = RESOLUTION - 2;
// linear radiance arriving from a unit direction, +Y up: a dusk gradient over dark ground
function sky_radiance(out, offset, direction) {
const up = direction[1];
if (up >= 0) {
const horizon = (1 - up) ** 4;
out[offset] = 0.02 + 0.9 * horizon;
out[offset + 1] = 0.04 + 0.35 * horizon;
out[offset + 2] = 0.12 + 0.1 * horizon;
} else {
out[offset] = 0.02;
out[offset + 1] = 0.018;
out[offset + 2] = 0.015;
}
}
const sampler = Sampler2D.float32(4, RESOLUTION, RESOLUTION);
const direction = [0, 0, 0];
for (let v = 1; v <= interior; v++) {
for (let u = 1; u <= interior; u++) {
// texel centres in the (RESOLUTION - 2)² interior, so the mapping stays symmetric across the folds
octahedral_z_pole_uv_to_direction(direction, (u - 0.5) / interior, (v - 0.5) / interior);
const offset = (v * RESOLUTION + u) * 4;
sky_radiance(sampler.data, offset, direction);
sampler.data[offset + 3] = 1;
}
}
sampler2d_octahedral_skirt_fill(sampler);
const image = ShadeImage.fromSampler2D(sampler2d_to_f16(sampler));
// radiance, not colour: these values never had a transfer curve on them.
// LinearSRGB is already ShadeImage's default; the shipped loaders set it explicitly anyway.
image.color_space = ColorSpace.LinearSRGB;
engine.graphics.set_environment_map(ShadeTexture.from(image));
octahedral_z_pole_uv_to_direction is the CPU port of the exact WGSL decode the GPU samples with, and the source is emphatic that every CPU-side producer of octahedral texels must go through it so the two can never drift apart. The outer one-texel ring is the octahedral skirt that hardware bilinear filtering reads across the octahedron’s edges: sample the (RESOLUTION - 2)² interior and call sampler2d_octahedral_skirt_fill(sampler) rather than filling 0 .. RESOLUTION - 1 directly.
If you go through a panorama, watch the orientation
resample_equirectangular_to_octahedral(sampler, output_resolution) takes a float Sampler2D and writes the skirt itself, so the panorama route works - but the engine holds two equirectangular conventions, and the resampler reads only one of them:
| Longitude | Latitude | |
|---|---|---|
resample_equirectangular_to_octahedral reads (equirectangular_zenith_first_direction_to_uv) | u = (atan2(x, z) + pi) / 2pi | v = acos(y) / pi, so v = 0 is the zenith |
equirectangular_direction_to_uv in src/core/geom/3d/equirectangular/ writes | u = atan2(z, x) / 2pi + 0.5 | v = asin(y) / pi + 0.5, so v = 0 is -Y |
A panorama laid out the second way and fed to the resampler comes out flipped vertically and turned a quarter turn about Y. The result still looks like a sky, which is what makes it easy to miss - check where the sun lands. Either render the panorama in the first convention, or sample into the octahedral grid directly as above.
Volumetric fog and participating media
A ParticipatingMedia component paired with a Transform64 is a box of fog, smoke, dust or cloud that the renderer marches through.
import { EngineHarness } from "@woosh/meep-engine/src/engine/EngineHarness.js";
import { ParticipatingMedia }
from "@woosh/meep-engine/src/engine/graphics3/ParticipatingMedia.js";
import { ParticipatingMediaSystem }
from "@woosh/meep-engine/src/engine/graphics3/ParticipatingMediaSystem.js";
import { Transform64 } from "@woosh/meep-engine/src/engine/ecs/transform/Transform64.js";
import { VolumetricsParticleSpec }
from "@woosh/meep-engine/src/shade/renderer/volumetrics/ParticipatingMediaVolume.js";
import { MIE_PARTICLES_STANDARD_PRECOMPUTED }
from "@woosh/meep-engine/src/core/math/physics/mie/MIE_PARTICLES_STANDARD_PRECOMPUTED.js";
const engine = await EngineHarness.bootstrap({
configuration(config, engine) {
config.addSystem(
new ParticipatingMediaSystem(engine.graphics, EngineHarness.shadeScene(engine))
);
}
});
const medium = new ParticipatingMedia();
medium.particle_spec = VolumetricsParticleSpec.fromMeep(
MIE_PARTICLES_STANDARD_PRECOMPUTED.FOG_DROPLET_SMALL
);
medium.target_extinction = 0.4; // per metre, set after the spec
medium.fade_distance = 1;
const transform = new Transform64();
transform.setTranslation(0, 4, 0);
transform.setScale(7, 5, 7); // the volume is a unit cube, so this is its size in metres
transform.updateMatrix(); // scale reaches the matrix only when it is composed
const ecd = engine.entityManager.dataset;
const entity = ecd.createEntity();
ecd.addComponentToEntity(entity, medium);
ecd.addComponentToEntity(entity, transform);
Set particle_spec before target_extinction: the setter divides by the spec’s extinction to get a density, so assigning the spec afterwards silently changes the strength you asked for.
ParticipatingMediaSystem takes (graphics, scene), declares dependencies = [ParticipatingMedia, Transform64], and calls graphics.set_scene(scene) during startup - it is one of only three systems that do.
The component is the medium; the Transform64 beside it is the box. The renderer’s ParticipatingMediaVolume is a unit cube centred on the origin, posed by that transform, so position, size and orientation are already ECS concepts and the component does not restate them. The transform is taken as world space with no hierarchy applied, exactly as lights are: parenting a fog volume to a moving entity leaves the fog where the child’s own transform puts it.
| Field | Default | Meaning |
|---|---|---|
density | 3e7 | Particles per cubic metre. Physically a count, so the numbers are large; the default is dense fog. What the useful range is depends entirely on particle_spec. |
particle_spec | VOLUMETRIC_PARTICLE_SPEC_FOG | What one particle does to light - a Mie solution (extinction, scattering, radius, g). VolumetricsParticleSpec.fromMeep(entry) converts an entry of the generated MIE_PARTICLES_STANDARD_PRECOMPUTED library (src/core/math/physics/mie/), which has named entries for hazes, fogs, clouds and dusts. |
fade_distance | 0.1 | Metres of soft edge inside the box faces. World space, deliberately not scaled by the transform. Zero gives hard edges, visible as a straight line across the screen wherever the box crosses the view. |
target_extinction | derived | Extinction per metre - density expressed in what it does rather than how many particles it took, and comparable across particle specs. Writing it sets density; it is not stored, so changing particle_spec afterwards changes what reading it back gives. Asserts if the spec extinguishes nothing. |
noise_strength | 0 | Noise on the density, in [0, 1]: how far the medium goes from uniform toward the noise tile’s value. 0 is a uniform medium and costs nothing; 1 is the tile as it is. |
noise_scale | 32 | World size of one repeat of the tile, in metres. The engine’s tile holds four base features an edge, so 32 puts them 8 m apart. |
noise_warp | 0.1 | How far a warp tap may displace the lookup, in tile units. 0 is one tap and a field that only slides. |
noise_velocity | [0, 0, 0] | The medium’s own motion for the noise, metres a second along the world axes, added to the scene’s wind - a draught in a corridor the wind does not reach. |
noise_wind_factor | 1 | How much of the scene’s wind this medium feels, 1 all of it. The wind is the scene’s far field (GPUFluidSystem.far_field_at, the mean wind and its turbulence from its GlobalFluidEffectors - see the scene’s wind), plus wherever a GPU fluid domain departs from it. A scene without a GPUFluidSystem is still air. |
noise_texture | 0 | Which slot of the scene’s noise atlas the tile comes from. 0 is the one the engine bakes. |
The component serialises (ParticipatingMediaSerializationAdapter, typeName = "ParticipatingMedia"), noise settings included, and density is what survives a save, not target_extinction.
Two behaviours to plan around:
- Changes are polled once a frame, not subscribed to. Neither the transform nor a density slider nor a swapped particle spec or noise setting announces itself to this system, so it compares them each frame and uploads only when something differs. A medium with noise also scrolls every frame, by the wind it feels plus its own
noise_velocity. A change becomes visible within a frame rather than instantly, and a fog volume needs not64_announce_changeto follow its transform. - Mutating a
ParticipatingMediaVolumedirectly is invisible.scene.volumetricsis aSceneVolumetrics;addandremovebump itsversionthemselves, but an in-place edit needsscene.volumetrics.invalidate(). Going through the component avoids the question.
There is no feature flag. The renderer builds the volumetrics LUTs whenever the scene holds at least one volume, and composites them over the finished opaque, background and indirect colour in a dedicated pass - before transparency, so transparent surfaces blend over the fog, and before TAA, which then smooths the fog’s per-pixel sampling noise. The fog is already in SceneColor by the time FramePhase.AfterLighting runs, so a render extension at that phase sees it.
The froxels take their sunlight through the atmosphere: each directional light is attenuated by the GPUSky transmittance LUT on its way in, and the multiple-scattering LUT fills in what a single bounce misses. Fog reads those LUTs whatever atmosphere.enabled says, so a scene whose sky is an environment map still fogs through the scene’s atmosphere parameters.
renderer.volumetrics (GPUViewVolumetrics) tunes the main view’s froxel grid: tile_size (default 16, screen pixels per froxel in XY; changing it preserves and resamples temporal history by UVW), resolution_z (default 64, depth slices between camera near and froxel_far; changing it drops temporal history), froxel_far (default Infinity, clamped to camera.far), taa_enabled (default true, 3D temporal reprojection over the scattering volume), and reset_history() (also called by renderer.indicate_view_change()).
Path tracing
Two unrelated path tracers ship, and they are not alternatives to each other.
The GPU path tracer
renderer.feature_path_tracing_enabled (default false) - one of the frame settings - makes renderer.path_tracer replace the rasterized and shaded colour for the frame. The traced result still goes through TAA and tone mapping like any other colour, which is the problem: the tracer accumulates across frames itself, one tile per call, and resets whenever the camera moves, so turn feature_taa_enabled off while this is on or two temporal filters fight over the same image.
const renderer = engine.graphics.renderer; // the escape hatch
renderer.feature_taa_enabled = false;
renderer.feature_path_tracing_enabled = true;
renderer.path_tracer.render_tile_size = 256; // square pixels per call
renderer.path_tracer.min_accumulation_alpha = 0.01; // blend floor
renderer.path_tracer is an AccumulatingPathTracer, constructed lazily on first access. Each render() traces one tile and blends it into the history with weight max(1 / sample_count, min_accumulation_alpha). A path that leaves the scene samples the scene’s environment texture - the authored map, or the one baked from the atmosphere.
The source is direct about what this is for: it binds the GPU TLAS buffer directly, which made it the check that the TLAS builds and traces correctly and the first place a regression in that tree would show. It calls itself prototype-grade rather than a shipping render mode. Do not build a product on it.
The pure-JS CPU path tracer
src/engine/graphics/sh3/path_tracer/ is a complete Monte-Carlo renderer in plain JavaScript, single-threaded, on the CPU. BufferedGeometryBVH builds from a Geometry carrying a position attribute.
| Class | File | Role |
|---|---|---|
PathTracer | PathTracer.js | path_trace(out, ray, min_bounce, max_bounce, random, scene) - one path, one output RGB |
PathTracedRenderer | PathTracedRenderer.js | Drives a tracer over a camera and scene. render(target, camera, scene, progress) is a generator that yields once per pixel, so a scheduler can spread it over frames. Writes tone-mapped, sRGB-encoded bytes into a Sampler2D. |
PathTracedScene | PathTracedScene.js | Two-level BVH (top-level over mesh AABBs, per-mesh for triangles), lights, background sampler. createMesh(geometry, material, transform), addLight(light), optimize() to rebuild the top level. |
PathTracedMesh | PathTracedMesh.js | One mesh instance: geometry, material, transform, per-mesh BVH |
BufferedGeometryBVH | BufferedGeometryBVH.js | Per-geometry BVH |
Russian roulette terminates a path with probability 0.5 after min_bounce bounces, scaling survivors by the reciprocal to keep the estimator unbiased.
The background is a closure on scene.__background_sampler with the signature (out, out_offset, direction, direction_offset): it writes linear RGB for a unit direction. The default is black. This tracer shares nothing with the renderer’s scene, the atmosphere included, so a sky is a function you assign:
// the Ray Tracing in One Weekend gradient
scene.__background_sampler = (out, out_offset, direction, direction_offset) => {
const t = 0.5 * (direction[direction_offset + 1] + 1);
out[out_offset] = 1 - 0.5 * t;
out[out_offset + 1] = 1 - 0.3 * t;
out[out_offset + 2] = 1;
};
populate_path_traced_scene_from_ecd(ecd, scene) exists and walks [ShadedGeometry, Transform64] and [Light, Transform64] (directional and point lights only). It does not work on a scene authored for the renderer as it stands, and its own JSDoc says why: a ShadedGeometry spawned from a loaded model holds a MeshletGeometry, whose triangles are quantized inside meshlet pages, and a ShadeMaterial - while createMesh wants a Geometry and the tracer’s own StandardMaterial. geometry_build_from_meshlet_geometry decodes the first; there is no converter yet for the second. Entities built directly with a Geometry and a StandardMaterial go through unchanged.
Nothing in the engine calls the CPU tracer - there is no SH3 probe baking; see global illumination for the indirect-lighting modes. It is a reference renderer for offline tooling. Being single-threaded JavaScript it is orders of magnitude slower than the GPU path, which is why PathTracedRenderer.render is a generator: drive it from a scheduler and spread it over frames rather than blocking on it.
Related
- Rendering overview - the frame, its phases, and the render-extension surface
- Global illumination -
indirect_lighting_mode, and why IBL from the sky is the default - Lights & shadows - the directional light the atmosphere takes for its sun, and why
LightType.AMBIENTis silently dropped (the environment is the ambient term) - Real-time Global Illumination example - a day cycle with no environment map: the atmosphere draws the sky from one sun light