Put THREE.Fog(color, near, far) on scene.fog for a linear blend between object color and fog color from near to far, or THREE.FogExp2(color, density) for an exponential falloff by distance. The math runs inside the built-in material shaders automatically — no extra code needed.
The key is matching the fog color to scene.background (or the renderer’s clear color) exactly. If they differ, you’ll see a visible seam where objects fade out short of the actual background, breaking the illusion.
The demo flies the camera forward through a corridor of same-colored cylindrical pillars. FogExp2 fades distant pillars naturally into the background, and it also conveniently hides the moment the camera snaps back to its starting position.
When to use
Hiding distant geometry pop-in in open or tunnel scenes, or building a sense of distance and mood — mist, haze, deep water.