Capítulo 815 de 859
How to fade a scene to a color with distance using Fog (linear near/far fade) or FogExp2 (exponential falloff), why the fog color must match the scene background color, and how to disable fog per-material for interiors.
Fog(color, near, far): linear fade — unaffected before near, fully fog-colored past far, blended in between.FogExp2(color, density): exponential falloff with distance; more physically realistic but harder to art-direct precisely than Fog.scene.fog: where a fog instance is assigned to take effect.scene.background should be set to the same color as the fog or the horizon won't blend seamlessly.material.fog (boolean): defaults to true; turning it off per-material excludes that surface from fog, useful for interiors (e.g. inside a vehicle cockpit or a house) that shouldn't be washed out by short-range exterior fog.class FogGUIHelper {
constructor(fog, backgroundColor) {
this.fog = fog;
this.backgroundColor = backgroundColor;
}
get near() { return this.fog.near; }
set near(v) { this.fog.near = v; this.fog.far = Math.max(this.fog.far, v); }
get far() { return this.fog.far; }
set far(v) { this.fog.far = v; this.fog.near = Math.min(this.fog.near, v); }
get color() { return `#${this.fog.color.getHexString()}`; }
set color(hexString) {
this.fog.color.set(hexString);
this.backgroundColor.set(hexString);
}
}
near <= far and syncs the fog color with the scene background color.Fog fades linearly between a near and far distance; FogExp2 grows exponentially and is more realistic but less controllable.scene.background to the same color as the fog color or the fade will look wrong at the horizon.near <= far when driving fog settings from a UI; a small wrapper class can enforce that automatically.material.fog = false off for surfaces that shouldn't be affected, such as interior walls under a short-range exterior fog setting.