Baltor Get started

Gallery / Godot shaders

Distance and height fog from the depth buffer

In your harnessGodot shaderMIT

Full-screen fog computed from reconstructed world positions: exponential distance fog, exponential height fog that pools low, a near to far colour gradient and a brighter glow toward a sun direction.

Render of Distance and height fog from the depth buffer
The render its check recorded in Godot 4.7.2, 256 by 256 pixels.

What it takes and gives

Shader type
spatial
Render modes
unshaded, cull_disabled, depth_test_disabled, depth_draw_never, skip_vertex_transform, fog_disabled
Parameters
screen_texture (sampler2D), depth_texture (sampler2D), near_color (vec4 = 0.62, 0.68, 0.75, 1), far_color (vec4 = 0.78, 0.82, 0.88, 1), sun_color (vec4 = 1, 0.85, 0.6, 1), distance_density (float = 0.08), height_density (float = 0.6), height_falloff (float = 1.2) and 6 more
Use it on
A MeshInstance3D with a 2 x 2 QuadMesh, material.tres as its material override and a large extra cull margin, as in demo.tscn.
Result
The scene fading into pale blue-grey fog with distance and near the ground, warmer toward the sun.
Renderers
compatibility: compiled and rendered, forward plus: not verified, mobile: not verified
Placement
res://baltor/godot_shaders/post_depth_fog/

Limits. Sky pixels are at the far plane, so they take full fog unless max_opacity is lowered. Fog is computed after lighting, so it does not affect shadows or light scattering. Transparent objects are fogged as their background. The pass reads Godot's screen texture after opaque geometry, so transparent objects drawn after it are not processed and its order among other transparent passes is not controlled.

Details

Kind
Godot shader
Engine
Godot 4.3 or later
Files
11 files, 75.9 KB
Licence
MIT
Declared effects
reads files, runs commands
Checked with
Godot 4.7.2, opengl3 compatibility (Mesa llvmpipe, Xvfb)
Checks
contract static, engine run, engine log clean, shader in scene, capture written, render not uniform, shader changes pixels
Techniques
Exponential distance fog, Analytic integral of exponential height fog along the view ray, World position reconstruction from depth
Tags
godot shader, spatial, post-process, fog, atmosphere, height fog, depth buffer, full-screen
Identity
library.supply.creative_originals.160d69af6c76d8f02270d3c3.12de76b7ca10cdc9
Version
12de76b7ca10cdc9a092bc795cf0e592f8fa576f7bd52007929b7a9dd76bc59f

The version is the SHA-256 of the item your harness downloads; every file in it names its own checksum.

Something wrong with this item, its rights or its safety? Report it on the support page, or from your harness after a download.