Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

feat: add physical sky ozone, sun disc, and motion tracks (#705) (#736)

Nguyen Xuan An7505916c79b5
diff --git a/changes/705.md b/changes/705.md
new file mode 100644
index 00000000..84229703
--- /dev/null
+++ b/changes/705.md
@@ -0,0 +1 @@
+- Add `ozone`, `sunDisc`, and time-of-day `environment` motion tracks for `environment.sky` (`type: "physical"`).
diff --git a/changes/705.size.md b/changes/705.size.md
new file mode 100644
index 00000000..184550ef
--- /dev/null
+++ b/changes/705.size.md
@@ -0,0 +1 @@
+- scene:agent-scene+lazy: ozone absorption, solar disc, and physical-sky environment motion tracks in src/physical-sky.js and src/agent-motion.js.
diff --git a/docs/agent-look.md b/docs/agent-look.md
index 8e24b55d..d8fbca15 100644
--- a/docs/agent-look.md
+++ b/docs/agent-look.md
@@ -123,7 +123,7 @@ Sky colors use display RGB, matching the renderer's existing environment contrac
| `ground` | on | Absent unless set. `false` removes the preview's automatic floor and contact shadow |
| `resolveCoplanar` | off | `'offset'` puts the smaller part of each coplanar pair (see the `coplanar-overlap` warning) on the next depth layer, drawn with a polygon offset; `false` or absent leaves parts as authored. Geometry never moves. Parts that set `decal` or `depthLayer` keep their own |
| `objectReflections` | on | Absent unless set. Each smooth metal part (`metallic` 0.5 or more, `roughness` 0.6 or less; at most 8 such parts) gets a reflection probe of the scene around it, so a chrome sphere shows the floor and its neighbours. `false` turns it off. Probes are traced at rest, so a part that moves reflects the scene as it started. `scene_inspect` names them in `reflections` |
-| `sky` | absent | Absent unless set. `{ type: 'physical', sunElevation, sunRotation, turbidity, groundAlbedo, aerialPerspective }`: one time-of-day control. `sunElevation` -90 to 90 degrees (default 45), `sunRotation` degrees clockwise from -Z seen from above (0), `turbidity` 1 to 10 haze (3), `groundAlbedo` 0 to 1 (0.3), `aerialPerspective` 0 to 4 scales the distance haze (1; 0 for none). The sky sets `lightDirection`, `keyColor` (the sun reddens and dims with air mass and sets below the horizon), `skyTop`, `skyBottom`, `fogColor` and `fogDensity`, and replaces the setup's environment map with the sky, so those fields no longer take your values while a sky is set. A `set-environment` patch changes the fields it names and keeps the rest; `sky: null` in a patch keeps the last derived values as plain fields. It is an analytic single-scattering approximation (Rayleigh and aerosol, Kasten-Young air mass), not Blender's Nishita integration: no ozone, no sun disc, no clouds. Raster first: the path tracer backends read the same environment map and key light, but are not yet checked against it. |
+| `sky` | absent | Absent unless set. `{ type: 'physical', sunElevation, sunRotation, turbidity, groundAlbedo, aerialPerspective, ozone, sunDisc }`: one time-of-day control. `sunElevation` -90 to 90 degrees (default 45), `sunRotation` degrees clockwise from -Z seen from above (0), `turbidity` 1 to 10 haze (3), `groundAlbedo` 0 to 1 (0.3), `aerialPerspective` 0 to 4 scales the distance haze (1; 0 for none), `ozone` 0 to 10 Chappuis-band absorption (1), `sunDisc` boolean (true). The sky sets `lightDirection`, `keyColor` (the sun reddens and dims with air mass and sets below the horizon), `skyTop`, `skyBottom`, `fogColor` and `fogDensity`, and replaces the setup's environment map with the sky, so those fields no longer take your values while a sky is set. `environment` motion tracks can animate `sunElevation`, `sunRotation`, `turbidity`, `groundAlbedo`, `aerialPerspective` and `ozone` for time-of-day arcs. A `set-environment` patch changes the fields it names and keeps the rest; `sky: null` in a patch keeps the last derived values as plain fields. It is an analytic single-scattering approximation (Rayleigh, aerosol and ozone, Kasten-Young air mass), not Blender's Nishita integration: no clouds. Raster first: the path tracer backends read the same environment map and key light, but are not yet checked against it. |
| `floorSkyTrace` | on | Absent unless set. A closed room a sun lights gets the sky each floor texel sees traced into its floor (`applyFloorSkyVisibility`, strength 0.2), so shadowed floors under a roof or between walls get less world and sky light; it makes the dark end of halls closer to Cycles. Open scenes and rooms lit by lamps alone are left as they are. `false` turns it off; a value that is not a boolean is refused. It loads lazily with a recipe that names its sun (`keyColor` or `keyIntensity`), costs about 1 s of trace when the scene is built and adds triangles to the floor (0.1 to 0.4 ms per frame in the reference halls). |
| `specularAntiAliasing` | `1` | Absent unless set. `0` to `4`. Widens highlights where the shading normal or normal map detail changes within a pixel (geometric specular anti-aliasing plus a Toksvig term read from the filtered normal map length), so grainy or scanned metal stops sparkling from frame to frame at grazing angles. `0` gives a highlight that follows every texel; above `1` is softer. |
| `sunBounce` | `1` | Absent unless set. A number of 0 or more. A closed room a sun lights gets a few point lights at its sunlit patches (`withSunBounce`, found when the scene is prepared), so the floor, walls and pillars around a patch are lit by the light it bounces and the far end of the room less. `0` turns it off and gives the look without it; `1` is fitted to Cycles; above `1` is stronger. A value that is not a number of 0 or more is refused. Open scenes and rooms with no sun are left as they are. It loads lazily with the sun, and the lights take up to 6 of the 16 point light slots. |
diff --git a/docs/parity.md b/docs/parity.md
index 5e75fe62..8190e42c 100644
--- a/docs/parity.md
+++ b/docs/parity.md
@@ -193,7 +193,7 @@ To move to a new Blender release, run `node scripts/parity-manual-snapshot.mjs`.
| Rendering > Cameras | partial | Perspective, orthographic views, focal length, animated paths, depth of field from depth and camera motion blur, both repeatable per frame. Object motion blur and bokeh shapes are missing. | [camera-path](../tests/camera-path.test.js), [camera](../tests/camera.test.js), [render-passes](../tests/render-passes.test.js) | #54 |
| Rendering > Lights > Light Objects | partial | One directional light with a shadow, 16 point lights, 8 spot lights and 7 rectangular area lights. Point and spot lights can cast shadows from one 24-tile atlas (a point light takes 6 tiles, a spot light 1). Area lights use a representative point and cast a soft shadow with `castShadow: true`. The directional shadow is a single map, or up to four cascades through `addons/cascaded-shadows` (`shadowCascades` on the renderer and `environment.shadowCascades` in recipes, three by themselves when `shadow.extent` is above 40): scene `long-street` scores 0.1555 against Cycles with one map and 0.1398 with three cascades, for about 0.2 ms more a frame on an RTX 3060 when the camera moves. | [lighting](../tests/lighting.test.js), [cascades](../tests/cascaded-shadows.test.js), `npm run reference` scenes `spot-area` and `long-street` | #52 |
| Rendering > Lights > Light Linking | partial | `addons/light-linking`: a light's `affects` list (and `environment.keyAffects` for the sun) limits it to the named parts through `applyLightLinks`, as a Blender receiver collection does; the shader skips a light whose bit in the part's mask is clear. Linking changes what a light adds, not what it shadows. The path tracer (issue #215) and the light bake honour it, and recipes reach it through `affects` and `environment.keyAffects` (`lightLinking` in `scene_capabilities`). There is no blocker list. Scene `light-linking` scores 0.0998 against Cycles. | [light-linking](../tests/light-linking.test.js), `npm run reference` scene `light-linking` | #52 |
-| Rendering > Lights > World Environment | partial | `environment.sky` `{ type: 'physical', sunElevation, sunRotation, turbidity, groundAlbedo, aerialPerspective }` drives the key light, background and distance haze from the sun (an analytic approximation of Blender's sky texture: no ozone, sun disc or clouds; [physical sky](../tests/physical-sky.test.js)). Recipes pick a named setup (`daylight`, `overcast`, `sunset`, `studio`) that carries a procedural environment map, with opt-in screen-space ambient occlusion. Code can load any HDRI; recipes reach only the named maps, with no URLs or files. No reflections between objects yet. The MCP preview adds an automatic floor with a contact shadow (`environment.ground: false` removes it). Cold-run reference-free score for sitting on a surface, summed over six tasks and 0 to 3 each: 0 before, 6 with the floor and 7 after a lone flat object (a gear) stopped being read as a floor; the front and side cameras see it edge-on, so only the three-quarter view shows it. A blind pairwise Sonnet judge (`default-judge.mjs`, six cold recipes, two cameras, 18 calls) prefers the floor to none 18 of 18 (p 0.0000076) and the darker floor now used (0.22) to the first one (0.6) 18 of 18; its control, one image against itself, picks the first 17 of 18. | [environment](../tests/environment.test.js), [default look](../tests/default-look.test.js) | #53, #705 |
+| Rendering > Lights > World Environment | partial | `environment.sky` `{ type: 'physical', sunElevation, sunRotation, turbidity, groundAlbedo, aerialPerspective, ozone, sunDisc }` drives the key light, background and distance haze from the sun, with `environment` motion tracks for time-of-day arcs (an analytic approximation of Blender's sky texture: no clouds; [physical sky](../tests/physical-sky.test.js)). Recipes pick a named setup (`daylight`, `overcast`, `sunset`, `studio`) that carries a procedural environment map, with opt-in screen-space ambient occlusion. Code can load any HDRI; recipes reach only the named maps, with no URLs or files. No reflections between objects yet. The MCP preview adds an automatic floor with a contact shadow (`environment.ground: false` removes it). Cold-run reference-free score for sitting on a surface, summed over six tasks and 0 to 3 each: 0 before, 6 with the floor and 7 after a lone flat object (a gear) stopped being read as a floor; the front and side cameras see it edge-on, so only the three-quarter view shows it. A blind pairwise Sonnet judge (`default-judge.mjs`, six cold recipes, two cameras, 18 calls) prefers the floor to none 18 of 18 (p 0.0000076) and the darker floor now used (0.22) to the first one (0.6) 18 of 18; its control, one image against itself, picks the first 17 of 18. | [environment](../tests/environment.test.js), [default look](../tests/default-look.test.js), [physical sky](../tests/physical-sky.test.js) | #53, #705 |
| Rendering > Materials > Components | partial | Surfaces with PBR factors and five maps, a clear coat, transmission with thickness, attenuation and IOR, sheen, and specular weight and tint. Anisotropic highlights and a thin-film iridescence layer, as in the glTF extensions, are compiled in only when a part uses them. Subsurface scattering (the `subsurface` block: weight, radius, scale, color; sun light only in the rasterizer, compiled in only when a part uses it) approximates skin, wax and leaves; the CPU path tracer traces it as a bounded Random Walk (at most 32 scattering events, thin cards as translucency), and so does the GPU tracer. In the `subsurface` reference scene, scored against the Cycles render with subsurface on, the path tracer gets 0.0795 with weight 1 and 0.0875 with weight 0 (64 samples, 28.8 s against 20.7 s; the GPU tracer 0.0795 and 0.0876), the rasterizer 0.1180 and 0.1229. There is no volume material or displacement. | [texture-set](../tests/texture-set.test.js), [material-layers](../tests/material-layers.test.js) | #50, #51 |
| Rendering > Materials > Assignment | done | A node names one material. | [agent-scene](../tests/agent-scene.test.js) | |
| Rendering > Materials > Preview | out of scope | Interface for a person. Agents use `scene_look`. | | |
diff --git a/src/agent-motion.js b/src/agent-motion.js
index 885231fc..2a28dfc9 100644
--- a/src/agent-motion.js
+++ b/src/agent-motion.js
@@ -9,6 +9,9 @@ import { normalizeClipLayers } from './agent-clip-layers.js';
import { normalizeKeyframeEasing } from './easing.js';
import { normalizeFootLock } from './foot-lock.js';
import { bounded, denseArray, finite, knownKeys, valueFrom } from './motion-validation.js';
+import { agentSceneModule } from './agent-scene-modules.js';
+
+const PHYSICAL_SKY_TRACK_PROPERTIES = new Set(['sunElevation', 'sunRotation', 'turbidity', 'groundAlbedo', 'aerialPerspective', 'ozone']);
const PROPERTIES = {
// visible is 1 or 0 and defaults to STEP interpolation; a hidden node and its children draw and cast nothing.
@@ -23,7 +26,11 @@ const PROPERTIES = {
sun: { direction: 3, color: 3, intensity: 1 },
// Sky, fog and ambient values of the environment. volumeFogDensity is environment.volumeFog.density; environmentIntensity and
// environmentRotation (radians) dim and turn the sky map that shows when environment.world is true.
- environment: { skyTop: 3, skyBottom: 3, fogColor: 3, fogDensity: 1, volumeFogDensity: 1, ambientIntensity: 1, fillIntensity: 1, environmentIntensity: 1, environmentRotation: 1 },
+ environment: {
+ skyTop: 3, skyBottom: 3, fogColor: 3, fogDensity: 1, volumeFogDensity: 1,
+ ambientIntensity: 1, fillIntensity: 1, environmentIntensity: 1, environmentRotation: 1,
+ sunElevation: 1, sunRotation: 1, turbidity: 1, groundAlbedo: 1, aerialPerspective: 1, ozone: 1,
+ },
// Frame effects: exposure, and the focus distance of the depth of field (needs effects.depthOfField.blur above 0).
effects: { exposure: 1, focusDistance: 1 },
};
@@ -38,6 +45,7 @@ const LOOK_RANGES = {
environment: {
skyTop: [0, 1], skyBottom: [0, 1], fogColor: [0, 1], fogDensity: [0, 10], volumeFogDensity: [0, 1000],
ambientIntensity: [0, 100], fillIntensity: [0, 100], environmentIntensity: [0, 100], environmentRotation: [-100, 100],
+ sunElevation: [-90, 90], sunRotation: [-360, 360], turbidity: [1, 10], groundAlbedo: [0, 1], aerialPerspective: [0, 4], ozone: [0, 10],
},
effects: { exposure: [0.01, 16], focusDistance: [0.01, 100000] },
};
@@ -146,6 +154,9 @@ function checkLookTarget(track, recipe) {
if (kind === 'effects' && property === 'focusDistance' && !(recipe.effects.depthOfField?.blur > 0)) {
throw invalidField('motion.tracks.property', 'effects.focusDistance', 'a track only when effects.depthOfField.blur is above 0, such as blur 2; a camera with an fStop focuses on its target, so move the camera target track instead');
}
+ if (kind === 'environment' && PHYSICAL_SKY_TRACK_PROPERTIES.has(property) && recipe.environment.sky?.type !== 'physical') {
+ throw invalidField('motion.tracks.property', `environment.${property}`, 'a track only when environment.sky is { "type": "physical" }');
+ }
}
function nodeIdFrom(value, nodes, label) {
@@ -597,6 +608,16 @@ export function motionEnvironment(environment, sampled) {
}
if (sampled.environment) {
const { volumeFogDensity, ...fields } = copiedPatch(sampled.environment);
+ const skyPatch = {};
+ for (const property of PHYSICAL_SKY_TRACK_PROPERTIES) {
+ if (fields[property] !== undefined) {
+ skyPatch[property] = fields[property];
+ delete fields[property];
+ }
+ }
+ if (environment.sky && Object.keys(skyPatch).length > 0) {
+ agentSceneModule('physicalSky').applyPhysicalSky({ ...environment.sky, ...skyPatch }, environment, invalidField);
+ }
Object.assign(environment, fields);
if (volumeFogDensity !== undefined) environment.volumeFog.density = volumeFogDensity;
}
diff --git a/src/physical-sky.js b/src/physical-sky.js
index 13259b9c..31bacd09 100644
--- a/src/physical-sky.js
+++ b/src/physical-sky.js
@@ -5,24 +5,29 @@ import { createEnvironmentMap } from './environment.js';
// The normalized recipe stores the resolved sun, so the key light, the sky map, the background gradient and the
// aerial perspective of distant geometry always agree.
-export const PHYSICAL_SKY_FIELDS = Object.freeze(['type', 'sunElevation', 'sunRotation', 'turbidity', 'groundAlbedo', 'aerialPerspective']);
+export const PHYSICAL_SKY_FIELDS = Object.freeze(['type', 'sunElevation', 'sunRotation', 'turbidity', 'groundAlbedo', 'aerialPerspective', 'ozone', 'sunDisc']);
-const DEFAULTS = Object.freeze({ sunElevation: 45, sunRotation: 0, turbidity: 3, groundAlbedo: 0.3, aerialPerspective: 1 });
+const DEFAULTS = Object.freeze({ sunElevation: 45, sunRotation: 0, turbidity: 3, groundAlbedo: 0.3, aerialPerspective: 1, ozone: 1, sunDisc: true });
const LIMITS = Object.freeze({
sunElevation: [-90, 90, 'degrees above the horizon, such as 15'],
sunRotation: [-360, 360, 'degrees clockwise from -Z seen from above, such as 120'],
turbidity: [1, 10, 'haze from 1 (very clear) to 10 (thick haze), such as 3'],
groundAlbedo: [0, 1, 'a reflectance from 0 to 1, such as 0.3'],
aerialPerspective: [0, 4, 'a scale from 0 (none) to 4, such as 1'],
+ ozone: [0, 10, 'ozone absorption from 0 (none) to 10, such as 1'],
});
const MAP_WIDTH = 128;
const MAP_HEIGHT = 64;
-// Per-channel (red, green, blue) optical depth of the air at the zenith, and the aerosol depth per unit turbidity.
+// Per-channel (red, green, blue) optical depth of the air at the zenith, the aerosol depth per unit turbidity, and the
+// Chappuis-band ozone absorption depth per unit ozone (strong in orange-green, weak in blue).
const RAYLEIGH_DEPTH = [0.04, 0.1, 0.24];
const AEROSOL_DEPTH_PER_TURBIDITY = [0.0125, 0.015, 0.0175];
+const OZONE_DEPTH = [0.02, 0.014, 0.0005];
const SUN_STRENGTH = 3.4;
const SKY_STRENGTH = 2.2;
+const SUN_DISC_STRENGTH = 18;
+const SUN_DISC_COSINE = 0.9994;
const MAXIMUM_AIR_MASS = 20;
const AEROSOL_ANISOTROPY = 0.76;
@@ -40,6 +45,11 @@ export function resolvePhysicalSky(input, fail) {
}
resolved[field] = value;
}
+ const sunDisc = input.sunDisc ?? DEFAULTS.sunDisc;
+ if (typeof sunDisc !== 'boolean') {
+ throw fail('environment.sky.sunDisc', sunDisc, 'true or false');
+ }
+ resolved.sunDisc = sunDisc;
return resolved;
}
@@ -48,8 +58,8 @@ function airMass(elevationRadians) {
return Math.min(MAXIMUM_AIR_MASS, 1 / (Math.sin(Math.max(elevationRadians, 0)) + 0.15 * Math.pow(degrees + 3.885, -1.253)));
}
-function opticalDepth(turbidity) {
- return RAYLEIGH_DEPTH.map((rayleigh, channel) => rayleigh + AEROSOL_DEPTH_PER_TURBIDITY[channel] * turbidity);
+function opticalDepth(turbidity, ozone = 1) {
+ return RAYLEIGH_DEPTH.map((rayleigh, channel) => rayleigh + AEROSOL_DEPTH_PER_TURBIDITY[channel] * turbidity + OZONE_DEPTH[channel] * ozone);
}
/** The unit direction toward the sun; azimuth turns clockwise seen from above, from -Z. */
@@ -62,14 +72,15 @@ export function physicalSunDirection(sky) {
function sunColor(sky) {
const elevation = sky.sunElevation * Math.PI / 180;
const mass = airMass(elevation);
- const depth = opticalDepth(sky.turbidity);
+ const depth = opticalDepth(sky.turbidity, sky.ozone ?? 1);
// The disc sinks under the horizon over about three degrees.
const setting = Math.min(1, Math.max(0, (sky.sunElevation + 1) / 3));
return depth.map(channelDepth => SUN_STRENGTH * Math.exp(-channelDepth * mass) * setting);
}
function skyRadiance(sky, direction, sun) {
- const depth = opticalDepth(sky.turbidity);
+ const ozone = sky.ozone ?? 1;
+ const depth = opticalDepth(sky.turbidity, ozone);
const fullSunMass = airMass(Math.asin(Math.max(-1, Math.min(1, sun[1]))));
const sunCosine = direction[0] * sun[0] + direction[1] * sun[1] + direction[2] * sun[2];
const rayleighPhase = 0.75 * (1 + sunCosine * sunCosine);
@@ -82,11 +93,11 @@ function skyRadiance(sky, direction, sun) {
const rayleigh = RAYLEIGH_DEPTH[channel];
const aerosol = AEROSOL_DEPTH_PER_TURBIDITY[channel] * sky.turbidity;
const scattered = (rayleigh * rayleighPhase + aerosol * aerosolPhase * 1.5) / (rayleigh + aerosol);
- const inScatter = 1 - Math.exp(-channelDepth * viewMass);
+ const inScatter = 1 - Math.exp(-(rayleigh + aerosol) * viewMass);
// Light scattered near the sun and low in the sky crossed the whole air mass toward the sun; the rest of the sky saw a short path.
const nearSun = Math.max(0, sunCosine) ** 2 * (1 - Math.max(0, direction[1]));
const sunMass = Math.min(4, fullSunMass) * (1 - nearSun) + fullSunMass * nearSun;
- const lightReaching = Math.exp(-channelDepth * sunMass * 0.45);
+ const lightReaching = Math.exp(-channelDepth * sunMass * 0.45 - OZONE_DEPTH[channel] * ozone * viewMass * 0.35);
return SKY_STRENGTH * scattered * inScatter * lightReaching * setting;
});
}
@@ -138,14 +149,19 @@ const MAXIMUM_CACHED_MAPS = 8;
function buildMapData(sky) {
const { sun, color, zenith } = colorAtZenithAndHorizon(sky);
+ const drawDisc = sky.sunDisc !== false && sky.sunElevation > -1.5;
const data = new Float32Array(MAP_WIDTH * MAP_HEIGHT * 3);
for (let row = 0; row < MAP_HEIGHT; row++) {
const polar = ((row + 0.5) / MAP_HEIGHT) * Math.PI;
for (let column = 0; column < MAP_WIDTH; column++) {
const azimuth = ((column + 0.5) / MAP_WIDTH - 0.5) * 2 * Math.PI;
const direction = [Math.sin(polar) * Math.sin(azimuth), Math.cos(polar), -Math.sin(polar) * Math.cos(azimuth)];
+ const sunCosine = direction[0] * sun[0] + direction[1] * sun[1] + direction[2] * sun[2];
+ const discWeight = drawDisc && direction[1] > 0 && sunCosine > SUN_DISC_COSINE
+ ? ((sunCosine - SUN_DISC_COSINE) / (1 - SUN_DISC_COSINE)) ** 2 * SUN_DISC_STRENGTH
+ : 0;
const radiance = direction[1] >= 0
- ? skyRadiance(sky, direction, sun)
+ ? skyRadiance(sky, direction, sun).map((component, channel) => component + color[channel] * discWeight)
: groundRadiance(sky, color, zenith, sun).map((component, channel) => component + skyRadiance(sky, [direction[0], 0, direction[2]], sun)[channel] * 0.35 * (1 - sky.groundAlbedo));
data.set(radiance, (row * MAP_WIDTH + column) * 3);
}
diff --git a/tests/physical-sky.test.js b/tests/physical-sky.test.js
index 6fc3645c..c9d039d7 100644
--- a/tests/physical-sky.test.js
+++ b/tests/physical-sky.test.js
@@ -77,3 +77,44 @@ test('set-environment changes one sky field and keeps the others', () => {
assert.equal(sky.turbidity, 5);
assert.ok(Math.abs(lightDirection[1] - Math.sin(10 * Math.PI / 180)) < 1e-9);
});
+
+test('ozone deepens twilight blue and sunDisc adds the solar disc to the sky map', () => {
+ const noOzone = skyEnvironment({ sunElevation: 4, ozone: 0 });
+ const heavyOzone = skyEnvironment({ sunElevation: 4, ozone: 6 });
+ assert.ok(heavyOzone.keyColor[0] < noOzone.keyColor[0]);
+ assert.ok(heavyOzone.skyTop[2] / Math.max(heavyOzone.skyTop[0], 1e-6) > noOzone.skyTop[2] / Math.max(noOzone.skyTop[0], 1e-6));
+
+ const withDisc = agentEnvironmentMap(skyEnvironment({ sunElevation: 30, sunDisc: true }));
+ const withoutDisc = agentEnvironmentMap(skyEnvironment({ sunElevation: 30, sunDisc: false }));
+ const peak = values => Math.max(...values);
+ assert.ok(peak(withDisc.data) > peak(withoutDisc.data) * 1.2);
+ assert.throws(() => skyEnvironment({ ozone: -1 }), /environment\.sky\.ozone/);
+ assert.throws(() => skyEnvironment({ sunDisc: 1 }), /environment\.sky\.sunDisc/);
+});
+
+test('environment motion tracks animate physical sky sunElevation, sunRotation and turbidity', () => {
+ const session = createAgentScene({
+ format: '67js.scene', schemaVersion: 1, geometries: [], materials: [], nodes: [],
+ environment: { sky: { type: 'physical', sunElevation: 60, sunRotation: 0, turbidity: 2 } },
+ motion: {
+ duration: 2,
+ tracks: [
+ { kind: 'environment', property: 'sunElevation', keyframes: [{ time: 0, value: 60 }, { time: 2, value: 5 }] },
+ { kind: 'environment', property: 'sunRotation', keyframes: [{ time: 0, value: 0 }, { time: 2, value: 90 }] },
+ { kind: 'environment', property: 'turbidity', keyframes: [{ time: 0, value: 2 }, { time: 2, value: 8 }] },
+ ],
+ },
+ });
+ session.sampleMotion(2);
+ const sampled = session.environment;
+ assert.equal(sampled.sky.sunElevation, 5);
+ assert.equal(sampled.sky.sunRotation, 90);
+ assert.equal(sampled.sky.turbidity, 8);
+ assert.ok(Math.abs(sampled.lightDirection[1] - Math.sin(5 * Math.PI / 180)) < 1e-6);
+ assert.ok(sampled.fogDensity > 0.0025 * 2);
+
+ assert.throws(() => createAgentScene({
+ format: '67js.scene', schemaVersion: 1, geometries: [], materials: [], nodes: [],
+ motion: { duration: 1, tracks: [{ kind: 'environment', property: 'sunElevation', keyframes: [{ time: 0, value: 45 }] }] },
+ }), /environment\.sky/);
+});