Skip to content

3D engine that AI agents drive

Keep the distance haze off a display-referred ramp (#2033)

Nguyen Xuan An8336f37a5cb8
diff --git a/src/shaders.js b/src/shaders.js
index bfabe1fe..a7de9a90 100644
--- a/src/shaders.js
+++ b/src/shaders.js
@@ -924,7 +924,7 @@ ${featureCode("afterEmission")}${featureCode("worldAfterEmission")} if (TAG_FLO
radiance = mix(radiance, vec3(0.018, 0.022, 0.026), fog);
}
${featureCode("worldFinal")} float fog = 1.0 - exp(-length(worldPosition - eye) * fogDensity);
-${featureCode("worldFogScale")} // Additive light fades to black through fog; mixing it toward the fog colour would add a glow of fog.
+ // Additive light fades to black through fog; mixing it toward the fog colour would add a glow of fog.
radiance = alphaMode > 2.5 ? radiance * (1.0 - fog * worldMode) : mix(radiance, fogColor, fog * worldMode);
if (inspection > 0.5) radiance = normal * 0.5 + 0.5;
vec3 displayedColor = displayRadiance(radiance);
diff --git a/src/world-material-shader.js b/src/world-material-shader.js
index 33f7e28e..bd925ca9 100644
--- a/src/world-material-shader.js
+++ b/src/world-material-shader.js
@@ -605,10 +605,9 @@ vec3 waterRampRadianceFor(vec3 asked) {
return guess / max(exposure, 0.0001);
}
`,
- // A ramp stands clear of the distance haze, which would shift the colour it was asked to show.
- worldFogScale: ` if (waterRampOwns > 0.5) fog = 0.0;
-`,
- worldFinal: ` if (waterDepth > 0.0 && waterBody.w > 0.5 && alphaMode < 0.5) alpha = 0.5 + 0.498 * clamp(waterDepth / 8.0, 0.0, 1.0);
+ worldFinal: ` // A ramp stands clear of the distance haze, which would shift the colour it was asked to show: a local density of 0 shadows the uniform.
+ float fogDensity = waterRampOwns > 0.5 ? 0.0 : fogDensity;
+ if (waterDepth > 0.0 && waterBody.w > 0.5 && alphaMode < 0.5) alpha = 0.5 + 0.498 * clamp(waterDepth / 8.0, 0.0, 1.0);
if (TAG_FIRE) {
float turbulence = sin(worldPosition.x * 3.0 + time * 4.0) * sin(worldPosition.y * 4.2 - time * 3.0) * sin(worldPosition.z * 3.7);
float heat = pow(clamp(0.55 + turbulence * 0.5 - explosionProgress * 0.12, 0.0, 1.0), 3.0);
diff --git a/tests/water-ramp.test.js b/tests/water-ramp.test.js
index f8bacb43..81402d01 100644
--- a/tests/water-ramp.test.js
+++ b/tests/water-ramp.test.js
@@ -106,5 +106,5 @@ test('the water shader maps the ramp back through the view transform and keeps t
assert.match(shader, /vec3 waterRampRadianceFor\(vec3 asked\)/);
assert.match(shader, /toneMap\(guess \+ 0\.002\)/);
assert.match(shader, /waterRampRadiance = waterRampRadianceFor\(/);
- assert.match(shader, /if \(waterRampOwns > 0\.5\) fog = 0\.0;/);
+ assert.match(shader, /float fogDensity = waterRampOwns > 0\.5 \? 0\.0 : fogDensity;/);
});