Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Escape the dot in the local volumes test regex and soften the GPU rounding claim to what was measured (#808)

Nguyen Xuan Anfc7b858e5c99
diff --git a/docs/volumetric.md b/docs/volumetric.md
index 5df9bba1..97641a72 100644
--- a/docs/volumetric.md
+++ b/docs/volumetric.md
@@ -152,4 +152,4 @@ Each volume is marched on its own between its entry and its exit, cut at the fir
### Not covered yet
-The noise is `localVolumeNoise` in `src/fog-shader.js` and `src/local-volume-noise.js`: trilinear value noise on a hash made of multiplies, adds and `fract` only, which every GPU rounds the same way. The fog's `cloudNoise` hashes with `sin`, whose error grows with its argument: on SwiftShader its lattice values differed from a 32-bit JavaScript port by up to 0.3, so the two renderers drew different clouds. The JavaScript port rounds every step to 32 bits. `tests/local-volume-noise.test.js` draws a noisy box (`density` 1.2, `falloff` 0.3, `noiseAmount` 0.9, `noiseScale` 3) in both renderers and compares the light let through in 8 by 8 regions: on SwiftShader the worst region differed by 0.003 and the mean of the whole frame by 0.0008, and the test allows 0.01 and 0.005. The rasterizer jitters each pixel's steps with a hash and the tracer with its sampler, so single pixels differ by a few percent. Volumes with `noiseAmount` drew with the fog's sine noise before this change, so their pattern moved; the mean density is unchanged. Lighting baked surfaces from a volume's emission is not planned (#809): the bake reports the limit instead.
+The noise is `localVolumeNoise` in `src/fog-shader.js` and `src/local-volume-noise.js`: trilinear value noise on a hash made of multiplies, adds and `fract` only, which rounded the same way on SwiftShader, where it was measured; it is unchecked on hardware GPUs. The fog's `cloudNoise` hashes with `sin`, whose error grows with its argument: on SwiftShader its lattice values differed from a 32-bit JavaScript port by up to 0.3, so the two renderers drew different clouds. The JavaScript port rounds every step to 32 bits. `tests/local-volume-noise.test.js` draws a noisy box (`density` 1.2, `falloff` 0.3, `noiseAmount` 0.9, `noiseScale` 3) in both renderers and compares the light let through in 8 by 8 regions: on SwiftShader the worst region differed by 0.003 and the mean of the whole frame by 0.0008, and the test allows 0.01 and 0.005. The rasterizer jitters each pixel's steps with a hash and the tracer with its sampler, so single pixels differ by a few percent. Volumes with `noiseAmount` drew with the fog's sine noise before this change, so their pattern moved; the mean density is unchanged. Lighting baked surfaces from a volume's emission is not planned (#809): the bake reports the limit instead.
diff --git a/src/fog-shader.js b/src/fog-shader.js
index e39d5b67..46f726da 100644
--- a/src/fog-shader.js
+++ b/src/fog-shader.js
@@ -122,7 +122,7 @@ uniform highp sampler2D localMeshVolumes;
// Each volume is marched on its own between its entry and exit (cut at the first surface) and composited nearest first: the colour
// behind it is dimmed by exp(-absorption * profile * step) and its emission is added, both per colour channel.
const LOCAL_VOLUME_FUNCTIONS = `
-// Value noise on a hash of plain multiplies, adds and fract, which every GPU rounds the same way (a sine hash does not: its error
+// Value noise on a hash of plain multiplies, adds and fract, which rounds the same way on SwiftShader, where it was measured, and is unchecked on hardware GPUs (a sine hash does not: its error
// grows with the argument). local-volume-noise.js repeats it for the CPU path tracer, so keep the two in step.
float localVolumeCellHash(vec3 cell) {
vec3 scrambled = fract(cell * 0.1031);
diff --git a/tests/local-volumes.test.js b/tests/local-volumes.test.js
index 5263a245..d1c4aaf4 100644
--- a/tests/local-volumes.test.js
+++ b/tests/local-volumes.test.js
@@ -191,7 +191,7 @@ test('the path tracer refuses local volumes on every non-CPU backend instead of
for (const backend of ['gpu', 'webgpu']) {
await assert.rejects(
renderPathTracedImage({ parts: ground(1), environment: { localVolumes: [{ shape: 'sphere', center: [0, 1, 0], radius: 1 }] }, camera: LOOKING_DOWN }, { ...IMAGE, backend }),
- new RegExp(`environment\.localVolumes is traced by the CPU path tracer only; backend "${backend}" cannot draw them`),
+ new RegExp(`environment\\.localVolumes is traced by the CPU path tracer only; backend "${backend}" cannot draw them`),
);
}
});