Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Compare the sphere light test against the floor patch it averages and record the Classroom gates (#1040)

Nguyen Xuan An10d5d19ff9aa
diff --git a/docs/cycles-parity.md b/docs/cycles-parity.md
index aa671908..89bb4365 100644
--- a/docs/cycles-parity.md
+++ b/docs/cycles-parity.md
@@ -1047,18 +1047,20 @@ Picture (Cook left, Cycles right, 1024 samples, depth of field on, grey diffuse)
| Gate | Result | Pass |
| --- | --- | --- |
-| Mean ratio per channel within 2 % | 1.123 / 1.129 / 1.138 | fail |
-| 8 x 8 tiles within 5 % | 2 of 64 (min 1.003, max 2.914) | fail |
-| FLIP LDR against the seed floor + 0.02 | 0.183 (floor 0.115, ceiling 0.135) | fail |
-| relMSE (reported) | 0.334 against a Cycles seed-to-seed floor of 0.066 | n/a |
+| Mean ratio per channel within 2 % | 0.9995 / 0.9995 / 0.9995 | pass |
+| 8 x 8 tiles within 5 % | 64 of 64 (min 0.990, max 1.010) | pass |
+| FLIP LDR against the seed floor + 0.02 | 0.109 (floor 0.111, ceiling 0.131) | pass |
+| relMSE (reported) | 0.062 against a Cycles seed-to-seed floor of 0.064 | n/a |
| Depth agreement at 1 % on 99.9 % of pixels | 99.939 % (316 of 518,400 pixels disagree) | pass |
| Depth at 0.1 % / 0.5 % | 98.97 % / 99.86 % | reported |
-The pinhole colour comparison gives the same numbers (1.124 / 1.129 / 1.138, 2 of 64 tiles, relMSE 0.336), so depth of field is not what fails the colour gates. The room is dark and noisy (mean radiance 0.17, a small window and a few lamps), so the Cycles noise floor itself is high.
+Every gate passes since the Cycles reference renders a light with a radius as a sphere, as Cook does ([Sphere lights and Soft Falloff](#sphere-lights-and-soft-falloff-1040)). With Blender's default disk light the same run gave 1.123 / 1.129 / 1.138, 2 of 64 tiles (max 2.914), FLIP 0.183 and relMSE 0.334; the section below keeps that diagnosis. The pinhole colour comparison passes with the same margins (0.9997 / 0.9997 / 0.9998, 64 of 64 tiles, relMSE 0.062). The room is dark and noisy (mean radiance 0.17, a small window and a few lamps), so the Cycles noise floor itself is high.
Depth: every one of the 316 disagreeing pixels sits next to a silhouette (none in the interior of a surface; away from silhouettes the agreement is 100 percent and the 99th percentile of the relative error is 0.10 percent). They gather in the right-hand tiles of rows 1 to 4 (107, 119, 45 and 10 pixels in the last column), where the venetian blinds' thin slats are, and a handful are scattered along the floor. 311 are both-hit pixels over 1 percent, 68 over 5 and 17 over 20 percent (a slat edge against what is behind it); 2 are hit only by Cycles and 3 only by Cook. 1,637 pixels are background in both (the window openings), so the miss handling is exercised by a rendered scene for the first time.
-### Why the colour gates fail (measured gap, inferred cause)
+### Why the colour gates failed with Blender's default disk lights (measured gap)
+
+The table is the run with Blender's default disk lights in the Cycles reference. With sphere lights on both sides the seven point lights together read 1.0003 (0.07701 / 0.07699) and one at a time 0.994 to 1.003; the sun and area rows do not change `[measured]`.
Same JSON, one light class at a time (pinhole, 256 spp, mean of the green channel; Cook over Cycles):
@@ -1338,7 +1340,7 @@ Commands: `bash bench/cycles-parity/texture-mips-run-all.sh <dir>` on a machine
## Sphere lights and Soft Falloff (#1040)
-Cook rendered a point light with a radius up to 41 percent brighter than Cycles on the Classroom scene (six lamps of radius 0.18 m inside shades). The cause is in the comparison, not in the kernel `[measured on small scenes, inferred for Classroom]`:
+Cook rendered a point light with a radius up to 41 percent brighter than Cycles on the Classroom scene (six lamps of radius 0.18 m inside shades). The cause is in the comparison, not in the kernel `[measured on small scenes and on Classroom: with the fix its seven lamps read 0.994 to 1.003 one at a time and every Classroom gate passes]`:
- Blender 4 and later give a point or spot light the property `Light.use_soft_falloff`, on by default. With it on, Cycles builds a light with a radius as an oriented disk that faces the shading point (`intern/cycles/blender/light.cpp`: `set_is_sphere(!(mode & LA_USE_SOFT_FALLOFF))`; `kernel/light/point.h`, `point_light_sample`, the `else` branch). With it off, Cycles builds the sphere: it samples the cone of the sphere from outside, the surface from inside, and a path that hits the sphere uses the same pdf.
- Cook implements the sphere (`lgt_sample_point_or_spot_light`, `lgt_sphere_solid_angle_pdf` in `lights.wgsl`), with the radiance `intensity / (pi r^2)` that Cycles uses (`eval_fac` in `PointLight::copy_to_kernel`), so the power does not change with the radius.
diff --git a/tests/cycles-sphere-light-parity.test.js b/tests/cycles-sphere-light-parity.test.js
index 86c62bf0..7b4f3cb5 100644
--- a/tests/cycles-sphere-light-parity.test.js
+++ b/tests/cycles-sphere-light-parity.test.js
@@ -13,7 +13,10 @@ const SIZE = 16;
const FLOOR_ALBEDO = 0.8;
const LAMP_HEIGHT = 2;
const LAMP_INTENSITY = 8;
-const cameraDescription = { eye: [0, 6, 0], target: [0, 0, 0], up: [0, 0, -1], fov: 30 };
+const CAMERA_HEIGHT = 6;
+const CAMERA_FIELD_OF_VIEW_DEGREES = 30;
+const PATCH_SIDE = 4;
+const cameraDescription = { eye: [0, CAMERA_HEIGHT, 0], target: [0, 0, 0], up: [0, 0, -1], fov: CAMERA_FIELD_OF_VIEW_DEGREES };
function floorPart() {
const matrix = new Float32Array([20, 0, 0, 0, 0, 0.1, 0, 0, 0, 0, 20, 0, 0, -0.05, 0, 1]);
@@ -37,13 +40,34 @@ function renderFloorUnderLamp(radius) {
function centreRadiance(rgba) {
let sum = 0;
- const first = SIZE / 2 - 2;
- for (let row = first; row < first + 4; row++) {
- for (let column = first; column < first + 4; column++) {
+ const first = (SIZE - PATCH_SIDE) / 2;
+ for (let row = first; row < first + PATCH_SIDE; row++) {
+ for (let column = first; column < first + PATCH_SIDE; column++) {
sum += rgba[(row * SIZE + column) * 4 + 1];
}
}
- return sum / 16;
+ return sum / (PATCH_SIDE * PATCH_SIDE);
+}
+
+// Where the centre of a pixel column or row lands on the floor, in metres from the point under the lamp.
+function floorOffsetOfPixel(pixelIndex) {
+ const halfExtent = CAMERA_HEIGHT * Math.tan((CAMERA_FIELD_OF_VIEW_DEGREES * Math.PI) / 360);
+ return (((pixelIndex + 0.5) / SIZE) * 2 - 1) * halfExtent;
+}
+
+// A sphere light of intensity I lights a diffuse floor point at a horizontal distance s, with every part of the sphere above
+// the floor, with I * h / (h^2 + s^2)^(3/2), whatever its radius: the power stays fixed as the radius grows. The pixels the
+// test averages reach about 0.5 m from the point under the lamp, where the floor is a few percent darker than at that point.
+function closedFormCentreRadiance() {
+ let sum = 0;
+ const first = (SIZE - PATCH_SIDE) / 2;
+ for (let row = first; row < first + PATCH_SIDE; row++) {
+ for (let column = first; column < first + PATCH_SIDE; column++) {
+ const distanceSquared = LAMP_HEIGHT * LAMP_HEIGHT + floorOffsetOfPixel(row) ** 2 + floorOffsetOfPixel(column) ** 2;
+ sum += ((FLOOR_ALBEDO / Math.PI) * LAMP_INTENSITY * LAMP_HEIGHT) / distanceSquared ** 1.5;
+ }
+ }
+ return sum / (PATCH_SIDE * PATCH_SIDE);
}
test('the Cycles reference script renders point and spot lights as spheres unless asked otherwise', () => {
@@ -54,11 +78,9 @@ test('the Cycles reference script renders point and spot lights as spheres unles
assert.equal(callCount, 3, 'the definition and one call each for point lights and spot lights');
});
-// A sphere light of intensity I seen from a distance d beyond its radius lights a facing diffuse surface with I / d^2, whatever
-// its radius, so the floor under the lamp is albedo / pi * I / d^2 for every radius (power stays fixed as the radius grows).
for (const radius of [0, 0.18, 0.5]) {
test(`the native cycles kernel keeps the power of a point light of radius ${radius} m`, { skip: skipWithoutAddon }, () => {
- const expected = (FLOOR_ALBEDO / Math.PI) * (LAMP_INTENSITY / (LAMP_HEIGHT * LAMP_HEIGHT));
+ const expected = closedFormCentreRadiance();
const measured = centreRadiance(renderFloorUnderLamp(radius));
assert.ok(Math.abs(measured / expected - 1) < 0.03, `floor radiance ${measured} against the closed form ${expected}`);
});