Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Trace the floor sky by default for closed rooms a sun lights, at strength 0.2 (part of #197)

Nguyen Xuan Anaf5a433c0a28
diff --git a/bench/reference/README.md b/bench/reference/README.md
index f018ab64..013f5e95 100644
--- a/bench/reference/README.md
+++ b/bench/reference/README.md
@@ -1781,3 +1781,34 @@ What was measured:
- Data only, this round (no engine byte changes): a 768 texel graph is not a valid resolution (256, 512 or 1024 only); 1024 is over the work limit of 30,000,000 (52 work units per pixel with 2 noise octaves, about 28 allowed), so a finer bake needs a smaller graph or a faster evaluator. Wider bevels in the scene graph (Blender gets the same graph and was rendered again): joint widths 0.10 to 0.36 and 0.06 to 0.26 gave `brick-graph` 0.0708 and `brick-flat` 0.0544 (excess 0.0164, EEVEE 0.0134 on the new renders), and 0.08 to 0.5 and 0.04 to 0.4 gave 0.0738 and 0.0529 (excess 0.0209, EEVEE 0.0166). The gap to EEVEE stays at 0.003 to 0.006 whichever bevel is used, and EEVEE's own excess moves with it, so changing the scene only moves the target. The scene was left as it is.
What would close it is a finer height-to-normal source than a 512 texel map (an analytic or 1024 texel bake of a graph that fits the work limit), which is engine work and costs memory or bytes; it is outside the data-only brief and the size goals. `brick-graph` is 0.0734 against Cycles, 0.1249 for EEVEE against Cycles on the same scene, so 67js is closer to Cycles than EEVEE is on this wall.
+
+## Sky seen from the floor, on by default for sunlit closed rooms (2026-11-04, part of issue #197)
+
+The opt-in trace above helped halls and studio floors and hurt streets, cities and rooms lit by lamps alone. The split is by what lights the scene, not by geometry: the mean traced visibility of the floor did not separate them (`temple-hall` 0.45, `dark-shaft` 0.54, but also `lit-interior` 0.55, `metal-room` 0.49 and `brick-room` 0.26, measured at strength 1). The rule that does separate them: a closed room (the ray test of the ground bounce) that a sun lights. `applyFloorSkyVisibility(parts, { onlyClosedRooms: true })` traces only closed rooms, at `FLOOR_SKY_ROOM_STRENGTH` 0.2, and returns open scenes unchanged (`report.reason` `open scene`); the reference harness calls it for scenes whose `keyColor` is not zero, so lamp-only rooms and every open scene draw as before. `--no-floor-sky` draws without it, `--floor-sky <strength>` sets one. Nothing in core; `report.meanVisibility` is new.
+
+GPU, 960 x 540, FLIP against the stored Cycles arrays, change from a render of main on the same machine (24 scenes and the 9 grand options; a scene not listed changed by less than 0.002, and all open scenes and lamp-only rooms are identical by construction):
+
+| Strength | `temple-hall` | `temple-hall-a` | `-b` | `-c` | `dark-shaft` | any other scene |
+| --- | --- | --- | --- | --- | --- | --- |
+| 1 | +0.0113 | -0.0085 | -0.0080 | -0.0285 | +0.0176 | `foliage` +0.0068 |
+| 0.5 | -0.0030 | -0.0106 | -0.0209 | -0.0161 | +0.0073 | none past 0.002 |
+| 0.25 | -0.0032 | -0.0063 | -0.0116 | -0.0079 | +0.0025 | none past 0.002 |
+| 0.2 (kept) | -0.0023 | -0.0051 | -0.0096 | -0.0061 | +0.0017 | none past 0.002 |
+
+0.2 is the largest strength that keeps `dark-shaft` within the 0.002 limit; the shaft's walls and floor get sun bounce in Cycles that a sky trace does not hold, so the shaft is the scene that sets the strength (guessed, not isolated).
+
+Box 2, dark end (`shadow-depth.py`, display luminance, 67js before > after / Cycles):
+
+| Scene | p1 | p5 | p25 | contrast (log2) |
+| --- | --- | --- | --- | --- |
+| `dark-shaft` | 0.0437 > 0.0389 / 0.0293 | 0.0437 > 0.0400 / 0.0313 | 0.0468 > 0.0437 / 0.0430 | 2.46 > 2.48 / 1.96 |
+| `temple-hall` | 0.0246 > 0.0207 / 0.0200 | 0.0246 > 0.0235 / 0.0221 | 0.0389 > 0.0350 / 0.0282 | 1.74 > 1.74 / 1.80 |
+| `temple-hall-a` | 0.0487 > 0.0451 / 0.0334 | 0.0557 > 0.0555 / 0.0363 | 0.0669 > 0.0630 / 0.0466 | 1.16 > 1.17 / 1.33 |
+| `temple-hall-b` | 0.0709 > 0.0709 / 0.0339 | 0.0717 > 0.0717 / 0.0370 | 0.0787 > 0.0751 / 0.0449 | 0.78 > 0.77 / 1.80 |
+| `temple-hall-c` | 0.0386 > 0.0338 / 0.0163 | 0.0394 > 0.0347 / 0.0184 | 0.0552 > 0.0515 / 0.0222 | 1.33 > 1.33 / 2.02 |
+
+The dark percentiles move toward Cycles in every row but by small steps (p1 by 0.000 to 0.005, p25 by 0.003 to 0.004; `temple-hall` p1 is now within 0.0007 of Cycles). The lit to shadow contrast does not move (at most 0.02 log2 step), as the opt-in section said: a sky term lowers lit and shadowed tiles together. `temple-hall-b` p1 and p5 do not move because its darkest pixels are lit by its lamps, not by the sky. The contrast gap needs a deeper sun shadow, not sky light, and is still open.
+
+Cost, measured on a loaded machine (another heavy job ran beside, so read these as ranges; `frame-time.mjs --plain`, one run each): `temple-hall` 1.83 ms without and 2.23 ms with, `dark-shaft` 2.38 ms without and 2.11 ms with. The trace takes 1.2 s and 0.6 s when the scene is prepared. Size: `entry:floor-sky-visibility` +93 bytes gzip, no other entry changes.
+
+The full suite (`npm run reference`, then `--grand`, with Blender 5.2.2 and fresh Cycles renders) ran once on this change and reproduced the numbers above (`temple-hall` 0.0617, `dark-shaft` 0.0576). It also moved rows this change does not touch (fresh Cycles renders against a newer main), so `baseline.json`, `grand.json` and the sheet images are left as they were; the rows of `temple-hall`, `dark-shaft` and the three temple options are stale by the changes above until the next refresh.
diff --git a/bench/reference/frame-time.mjs b/bench/reference/frame-time.mjs
index 50cf44d3..5cb23d4d 100644
--- a/bench/reference/frame-time.mjs
+++ b/bench/reference/frame-time.mjs
@@ -1,5 +1,5 @@
// Frame time of a reference scene: plain, with the light bake, with reflection probes, and with both.
-// node bench/reference/frame-time.mjs [scene-id] [gpu|cpu] [--grand] [--floor-sky=<strength> [--floor-sky-rooms]]
+// node bench/reference/frame-time.mjs [scene-id] [gpu|cpu] [--grand] [--floor-sky=<strength> [--floor-sky-rooms]] [--no-floor-sky]
import { constants, setPriority } from 'node:os';
import { chromium } from 'playwright';
import { createServer } from 'vite';
@@ -20,7 +20,7 @@ const browser = await chromium.launch({ executablePath: CHROME, headless: true,
try {
const page = await browser.newPage({ viewport: { width: 960, height: 540 } });
const floorSkyArgument = process.argv.find(argument => argument.startsWith('--floor-sky='));
- const harnessQuery = [process.argv.includes('--grand') ? 'set=grand' : null, floorSkyArgument ? `floorSky=${floorSkyArgument.split('=')[1]}` : null, process.argv.includes('--floor-sky-rooms') ? 'floorSkyRooms=1' : null].filter(Boolean).join('&');
+ const harnessQuery = [process.argv.includes('--grand') ? 'set=grand' : null, floorSkyArgument ? `floorSky=${floorSkyArgument.split('=')[1]}` : null, process.argv.includes('--floor-sky-rooms') ? 'floorSkyRooms=1' : process.argv.includes('--no-floor-sky') ? 'floorSky=0' : null].filter(Boolean).join('&');
await page.goto(`${serverUrl}/bench/reference/harness.html${harnessQuery ? `?${harnessQuery}` : ''}`, { timeout: PAGE_LOAD_TIMEOUT });
await page.waitForFunction(() => window.measureReferenceFrameTime, null, { timeout: PAGE_LOAD_TIMEOUT });
const results = [];
diff --git a/bench/reference/harness.js b/bench/reference/harness.js
index df4de4de..810e3a5e 100644
--- a/bench/reference/harness.js
+++ b/bench/reference/harness.js
@@ -34,13 +34,19 @@ const REVERSED_DEPTH = new URLSearchParams(location.search).get('reversedDepth')
const WATER_REFLECTION = { off: false, ssr: 'ssr' }[new URLSearchParams(location.search).get('water')] ?? 'planar';
-// ?floorSky=<strength> traces the sky each floor texel sees (src/floor-sky-visibility.js) and scales the world light there by it; the scenes draw without it otherwise.
-const FLOOR_SKY_STRENGTH = Number(new URLSearchParams(location.search).get('floorSky')) || 0;
+// The sky each floor texel sees (src/floor-sky-visibility.js) scales the world light on floors. By default the scenes that are a closed room lit
+// by a sun (the temple halls, the shaft) get it at the addon's room strength; lamp-only rooms and open scenes draw without it, because it made them worse.
+// ?floorSky=0 draws every scene without it, ?floorSky=<strength> sets the strength, ?floorSkyRooms=1 traces every closed room and open scene alike.
+const FLOOR_SKY_PARAMETER = new URLSearchParams(location.search).get('floorSky');
+const FLOOR_SKY_ROOMS_MODE = new URLSearchParams(location.search).get('floorSkyRooms') ?? (FLOOR_SKY_PARAMETER === null ? 'sun' : null);
const floorSkyReports = {};
-function withFloorSky(id, parts) {
- if (!FLOOR_SKY_STRENGTH) return parts;
- const result = applyFloorSkyVisibility(parts, { strength: FLOOR_SKY_STRENGTH, includeClosedRooms: new URLSearchParams(location.search).get('floorSkyRooms') === '1' });
+function withFloorSky(id, parts, scene) {
+ if (FLOOR_SKY_PARAMETER === '0') return parts;
+ const sunlit = (scene?.environment?.keyColor ?? [0, 0, 0]).some(channel => channel > 0);
+ if (FLOOR_SKY_ROOMS_MODE === 'sun' && !sunlit) return parts;
+ const strength = FLOOR_SKY_PARAMETER === null ? undefined : Number(FLOOR_SKY_PARAMETER);
+ const result = applyFloorSkyVisibility(parts, { strength, includeClosedRooms: FLOOR_SKY_ROOMS_MODE === '1', onlyClosedRooms: FLOOR_SKY_ROOMS_MODE === 'sun' });
floorSkyReports[id] = result.report;
return result.parts;
}
@@ -208,7 +214,7 @@ async function renderReferenceScene(id, { describe, ambientOcclusion = 0, ambien
scene.environment = withDerivedGroundBounce(scene, probed ? probed.parts : baked ? baked.parts : scene.parts);
const canvas = document.querySelector('canvas');
// backgroundOnly draws the sky alone, so a score can be limited to the pixels the asset covers.
- const renderer = createSceneRenderer(backgroundOnly ? [] : withFloorSky(id, probed ? probed.parts : baked ? baked.parts : scene.parts), scene, cascades);
+ const renderer = createSceneRenderer(backgroundOnly ? [] : withFloorSky(id, probed ? probed.parts : baked ? baked.parts : scene.parts, scene), scene, cascades);
renderer.resize();
// Blender draws a still scene. The renderer's default wind (0.3) would move the leaf cards by up to four pixels at time 0.
const frame = { ...scene.camera, environment: scene.environment, time: 0, wind: 0, exposure: 1, effects: { ambientOcclusion, ambientOcclusionRadius, ...(bloom ? { bloom } : {}) } };
@@ -235,7 +241,7 @@ async function measureReferenceFrameTime(id, { bake, probes = false, cascades =
const baked = bake ? await bakeScene(scene, {}) : null;
const probed = probes ? await probeScene(scene, id, baked ? baked.parts : scene.parts, probes) : null;
scene.environment = withDerivedGroundBounce(scene, probed ? probed.parts : baked ? baked.parts : scene.parts);
- const renderer = createSceneRenderer(withFloorSky(id, probed ? probed.parts : baked ? baked.parts : scene.parts), scene, cascades, { water });
+ const renderer = createSceneRenderer(withFloorSky(id, probed ? probed.parts : baked ? baked.parts : scene.parts, scene), scene, cascades, { water });
renderer.resize();
const frame = { ...scene.camera, environment: scene.environment, time: 0, exposure: 1, effects: { ambientOcclusion: 0, ambientOcclusionRadius: 0.5 } };
// With orbit the camera moves a little every frame, so cascaded maps have to be redrawn each time, as in a camera move.
diff --git a/bench/reference/images/emissive-sign.jpg b/bench/reference/images/emissive-sign.jpg
new file mode 100644
index 00000000..7c2d6398
Binary files /dev/null and b/bench/reference/images/emissive-sign.jpg differ
diff --git a/bench/reference/run.mjs b/bench/reference/run.mjs
index ebeef357..bfe987dc 100644
--- a/bench/reference/run.mjs
+++ b/bench/reference/run.mjs
@@ -55,6 +55,7 @@ const BACKEND_ARGUMENTS = {
const argumentsGiven = process.argv.slice(2);
// --floor-sky-rooms also traces closed rooms, which are left as they are otherwise.
+// Closed rooms lit by a sun get the floor sky trace by default; --no-floor-sky draws without it, --floor-sky-sun is the same as the default.
// --floor-sky [<strength>] traces the sky each floor texel sees (src/floor-sky-visibility.js) and scales the world light on floors by it (strength 1 when none follows).
const floorSkyFlag = argumentsGiven.indexOf('--floor-sky');
const floorSkyStrength = floorSkyFlag < 0 ? 0 : Number(argumentsGiven[floorSkyFlag + 1]) || 1;
@@ -113,7 +114,7 @@ const sceneIdsGiven = lookIds ?? (sceneFlag >= 0 ? argumentsGiven[sceneFlag + 1]
// The fresh bake.json lands in the work directory and is checked against the committed one (compare-scores.mjs); --update-baseline replaces
// the committed bake.json and images/<id>-baked.jpg with it.
const bakeScoreRun = bakedSceneIds !== null && !sceneSet && !pathTracerFlag;
-const bakeVariantFlags = ['--sky-only', '--bake-preset', '--bake-backend', '--bake-samples', '--bake-density', '--probes', '--ambient', '--ambient-occlusion', '--cascades', '--no-object-probes', '--object-probes', '--no-water', '--ssr-water', '--no-ground-bounce', '--floor-sky', '--floor-sky-rooms'];
+const bakeVariantFlags = ['--sky-only', '--bake-preset', '--bake-backend', '--bake-samples', '--bake-density', '--probes', '--ambient', '--ambient-occlusion', '--cascades', '--no-object-probes', '--object-probes', '--no-water', '--ssr-water', '--no-ground-bounce', '--floor-sky', '--floor-sky-rooms', '--floor-sky-sun', '--no-floor-sky'];
const bakeScoreIsBaseline = bakeScoreRun && argumentsGiven.includes('--update-baseline') && !bakeVariantFlags.some(flag => argumentsGiven.includes(flag));
const onlyScenes = sceneIdsGiven ?? (bakeScoreRun ? bakedSceneIds : null);
const skipCpu = skipCpuFlag || bakeScoreRun || Boolean(viewTransform);
@@ -127,7 +128,7 @@ async function renderBackend(backend, serverUrl, graphics) {
page.on('console', message => message.text().includes('GL_') && console.log('PAGE', message.text().slice(0, 200)));
// Each scene gets a fresh page, so a large scene leaves no GL state or memory behind for the next one.
const openHarness = async () => {
- const harnessQuery = [sceneSet ? `set=${sceneSet}` : null, argumentsGiven.includes('--no-water') ? 'water=off' : argumentsGiven.includes('--ssr-water') ? 'water=ssr' : null, argumentsGiven.includes('--no-ground-bounce') ? 'groundBounce=off' : null, floorSkyStrength ? `floorSky=${floorSkyStrength}` : null, argumentsGiven.includes('--floor-sky-rooms') ? 'floorSkyRooms=1' : null].filter(Boolean).join('&');
+ const harnessQuery = [sceneSet ? `set=${sceneSet}` : null, argumentsGiven.includes('--no-water') ? 'water=off' : argumentsGiven.includes('--ssr-water') ? 'water=ssr' : null, argumentsGiven.includes('--no-ground-bounce') ? 'groundBounce=off' : null, floorSkyStrength ? `floorSky=${floorSkyStrength}` : argumentsGiven.includes('--no-floor-sky') ? 'floorSky=0' : null, argumentsGiven.includes('--floor-sky-rooms') ? 'floorSkyRooms=1' : argumentsGiven.includes('--floor-sky-sun') ? 'floorSkyRooms=sun' : null].filter(Boolean).join('&');
await page.goto(`${serverUrl}/bench/reference/harness.html${harnessQuery ? `?${harnessQuery}` : ''}`, { timeout: PAGE_LOAD_TIMEOUT });
await page.waitForFunction(() => window.renderReferenceScene, null, { timeout: PAGE_LOAD_TIMEOUT });
};
@@ -155,7 +156,7 @@ async function renderBackend(backend, serverUrl, graphics) {
}
const bakeNote = result.bake?.report.refused ? `, bake REFUSED, drawn unbaked: ${result.bake.report.refused}` : result.bake ? `, bake ${result.bake.seconds.toFixed(1)} s, ${result.bake.report.texels} texels${result.bake.report.used ? ` (used ${result.bake.report.used.samples} samples, ${result.bake.report.used.bounces} bounces, ${result.bake.report.used.texelsPerUnit} texels per unit${result.bake.report.reduced ? ', reduced' : ''})` : ''}` : '';
const probeNote = result.probes ? `, probes ${result.probes.report.placed.length} on ${result.probes.report.partsWithProbe} parts` : '';
- const floorSkyNote = result.floorSky ? `, floor sky ${result.floorSky.reason ?? `${result.floorSky.texels} texels, ${result.floorSky.rays} rays, ${result.floorSky.seconds.toFixed(2)} s`}` : '';
+ const floorSkyNote = result.floorSky ? `, floor sky ${result.floorSky.reason ?? `${result.floorSky.texels} texels, mean visibility ${result.floorSky.meanVisibility?.toFixed(3)}, ${result.floorSky.rays} rays, ${result.floorSky.seconds.toFixed(2)} s`}` : '';
console.log(`${id} on ${backend}: ${Math.round(performance.now() - started)} ms${bakeNote}${probeNote}${floorSkyNote}`);
}
if (errors.length) throw new Error(errors.join('\n'));
diff --git a/changes/197-sun-rooms.md b/changes/197-sun-rooms.md
new file mode 100644
index 00000000..9a22943f
--- /dev/null
+++ b/changes/197-sun-rooms.md
@@ -0,0 +1 @@
+- Add `onlyClosedRooms` to `applyFloorSkyVisibility` (issue #197) and `report.meanVisibility`. It traces closed rooms only, at the default strength 0.2 (`FLOOR_SKY_ROOM_STRENGTH`), and leaves open scenes alone, where the trace made streets and cities too dark. The reference harness now applies it by default to closed rooms lit by a sun (`temple-hall`, `dark-shaft` and the three grand temple options; lamp-only rooms and open scenes draw as before), `--no-floor-sky` turns it off. FLIP against Cycles: the four hall scenes improve by 0.0023 to 0.0096, `dark-shaft` moves by +0.0017, nothing else changes. The core entry is unchanged. The README has the numbers.
diff --git a/changes/197-sun-rooms.size.md b/changes/197-sun-rooms.size.md
new file mode 100644
index 00000000..568f4a88
--- /dev/null
+++ b/changes/197-sun-rooms.size.md
@@ -0,0 +1 @@
+- entry:floor-sky-visibility: +93 bytes gzip (15101 to 15194) for the onlyClosedRooms option, the room strength constant and the mean visibility in the report; core entries unchanged
diff --git a/docs/lighting.md b/docs/lighting.md
index 0ad979f4..3179869b 100644
--- a/docs/lighting.md
+++ b/docs/lighting.md
@@ -147,7 +147,7 @@ The other 19 reference scenes drew the same pixels (mean, p20 and FLIP identical
## Sky seen from the floor
-`applyFloorSkyVisibility(parts, { strength, includeClosedRooms })` (`67js/addons/floor-sky-visibility`) is opt-in and returns `{ parts, report }`. It cuts the floor parts into texels, shoots 64 cosine-weighted rays from each against the other opaque parts and stores the share that escapes as the floor's `skyVisibility`, so the world and sky light on a floor under a roof or between walls is scaled down and open ground is not. Pass the returned parts to the renderer. `strength` 1 uses the traced share, 0.5 keeps half of what it hides. A closed room is left alone unless `includeClosedRooms` is `true`, and a scene that is too large (over 200,000 triangles), has no floor or runs past `maxSeconds` (20) comes back unchanged with `report.reason`. It is not on by default: it moves the dark end of halls and studio floors toward Cycles, and makes sunlit streets too dark (`long-street` +0.0135 FLIP at 0.5). The trace takes 0.5 to 1.7 s, and the floor grows to about 66,000 triangles, which adds 0.1 to 0.3 ms per frame in the reference scenes. Numbers: `bench/reference/README.md`, "Sky visibility traced from the floor texels".
+`applyFloorSkyVisibility(parts, { strength, includeClosedRooms, onlyClosedRooms })` (`67js/addons/floor-sky-visibility`) is opt-in and returns `{ parts, report }`. It cuts the floor parts into texels, shoots 64 cosine-weighted rays from each against the other opaque parts and stores the share that escapes as the floor's `skyVisibility`, so the world and sky light on a floor under a roof or between walls is scaled down and open ground is not. Pass the returned parts to the renderer. `strength` 1 uses the traced share, 0.5 keeps half of what it hides. `onlyClosedRooms: true` is the setting that helped: it traces closed rooms only, at strength 0.2 unless you pass one, and leaves open scenes alone. Use it for a room a sun lights through its openings (the reference halls); a room lit by lamps alone and open ground are better without it. A closed room is left alone unless `includeClosedRooms` is `true`, and a scene that is too large (over 200,000 triangles), has no floor or runs past `maxSeconds` (20) comes back unchanged with `report.reason`. It is not on by default: it moves the dark end of halls and studio floors toward Cycles, and makes sunlit streets too dark (`long-street` +0.0135 FLIP at 0.5). The trace takes 0.5 to 1.7 s, and the floor grows to about 66,000 triangles, which adds 0.1 to 0.3 ms per frame in the reference scenes. Numbers: `bench/reference/README.md`, "Sky visibility traced from the floor texels".
## Local shadows
diff --git a/src/floor-sky-visibility.js b/src/floor-sky-visibility.js
index 749a1211..e71a1cca 100644
--- a/src/floor-sky-visibility.js
+++ b/src/floor-sky-visibility.js
@@ -13,6 +13,8 @@ export const FLOOR_SKY_RAYS = 64;
export const FLOOR_SKY_MAXIMUM_TEXELS = 24_000;
export const FLOOR_SKY_MAXIMUM_SECONDS = 20;
export const FLOOR_SKY_STRENGTH = 1;
+// With onlyClosedRooms the default is lower: a hall also gets light that comes back from its walls and sunlit floor, which a sky trace does not hold.
+export const FLOOR_SKY_ROOM_STRENGTH = 0.2;
const FLOOR_THINNESS = 0.1;
const FLOOR_MINIMUM_FOOTPRINT_SHARE = 0.02;
@@ -199,7 +201,8 @@ function fixedSamples(sampleCount) {
* larger than the bake's triangle limit, or the trace passes `maxSeconds`. It reads no clock to decide anything else, and
* the rays are a fixed set, so the same scene gives the same bytes.
*/
-export function applyFloorSkyVisibility(parts, { raysPerTexel = FLOOR_SKY_RAYS, maximumTexels = FLOOR_SKY_MAXIMUM_TEXELS, maxSeconds = FLOOR_SKY_MAXIMUM_SECONDS, strength = FLOOR_SKY_STRENGTH, includeClosedRooms = false } = {}) {
+export function applyFloorSkyVisibility(parts, { raysPerTexel = FLOOR_SKY_RAYS, maximumTexels = FLOOR_SKY_MAXIMUM_TEXELS, maxSeconds = FLOOR_SKY_MAXIMUM_SECONDS, strength: requestedStrength, includeClosedRooms = false, onlyClosedRooms = false } = {}) {
+ const strength = requestedStrength ?? (onlyClosedRooms ? FLOOR_SKY_ROOM_STRENGTH : FLOOR_SKY_STRENGTH);
const started = performance.now();
const unchanged = reason => ({ parts, report: { floors: [], texels: 0, rays: 0, seconds: (performance.now() - started) / 1000, reason } });
const floorIndices = findFloorParts(parts);
@@ -210,7 +213,10 @@ export function applyFloorSkyVisibility(parts, { raysPerTexel = FLOOR_SKY_RAYS,
if (occluders.length < 2) return unchanged('nothing above the floor');
// A closed room has no sky to see: its walls and lamps give the light, and the shader's room term already handles it.
const roomShare = closedRoomShare(parts, new Map(parts.map(part => [part.name, part.matrix])));
- if (!includeClosedRooms && roomShare !== null && roomShare >= CLOSED_ROOM_SHARE) return unchanged('closed room');
+ const closedRoom = roomShare !== null && roomShare >= CLOSED_ROOM_SHARE;
+ if (closedRoom && !includeClosedRooms && !onlyClosedRooms) return unchanged('closed room');
+ // Open ground gets light back from sunlit facades and streets that a sky trace does not hold, so it comes out too dark.
+ if (onlyClosedRooms && !closedRoom) return unchanged('open scene');
let world;
try {
world = buildWorld(occluders);
@@ -265,8 +271,11 @@ export function applyFloorSkyVisibility(parts, { raysPerTexel = FLOOR_SKY_RAYS,
if (builder.hasUvs) cutGeometryResult.uvs = new Float32Array(builder.uvs);
if (builder.hasColors) cutGeometryResult.colors = new Float32Array(builder.colors);
nextParts[index] = Object.freeze({ ...part, geometry: Object.freeze(cutGeometryResult) });
- floors.push({ name: part.name, texels: upwardVertices.size, triangles: indices.length / 3 });
+ let sharedSum = 0;
+ for (const vertex of upwardVertices) sharedSum += skyVisibility[vertex];
+ floors.push({ name: part.name, texels: upwardVertices.size, triangles: indices.length / 3, meanVisibility: upwardVertices.size ? sharedSum / upwardVertices.size : 1 });
}
const texels = floors.reduce((total, floor) => total + floor.texels, 0);
- return { parts: Object.freeze(nextParts), report: { floors, texels, rays: totalRays, seconds: (performance.now() - started) / 1000, reason: null } };
+ const meanVisibility = texels ? floors.reduce((total, floor) => total + floor.meanVisibility * floor.texels, 0) / texels : 1;
+ return { parts: Object.freeze(nextParts), report: { floors, texels, meanVisibility, rays: totalRays, seconds: (performance.now() - started) / 1000, reason: null } };
}
diff --git a/tests/floor-sky-visibility.test.js b/tests/floor-sky-visibility.test.js
index 688c10df..a592b60b 100644
--- a/tests/floor-sky-visibility.test.js
+++ b/tests/floor-sky-visibility.test.js
@@ -92,6 +92,13 @@ test('parts that carry their own light, a cut-out or a tag are not floors', () =
assert.deepEqual(findFloorParts([baked, leaves, water, own, roof]), []);
});
+test('onlyClosedRooms leaves an open scene as it was', () => {
+ const parts = [square('floor', 20, 0), square('roof', 6, 2, { facing: -1 })];
+ const result = applyFloorSkyVisibility(parts, { onlyClosedRooms: true });
+ assert.equal(result.parts, parts);
+ assert.equal(result.report.reason, 'open scene');
+});
+
test('a scene with no floor or nothing above it comes back unchanged', () => {
const lone = [square('floor', 10, 0)];
assert.equal(applyFloorSkyVisibility(lone).parts, lone);