โ† All examples

godot shaders

Distance and height fog from the depth buffer

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.

Recorded render of Distance and height fog from the depth buffer

What this component contains

  • ATTRIBUTION.md
  • LICENSE
  • README.md
  • component.json
  • demo.tscn
  • inspect_shader.py
  • material.tres
  • post_depth_fog.gdshader
  • preview.png
  • test_package.py
  • verification/native.json

How it works

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/

Recorded checks

godot 4.7.2.stable.official.ed1daf0bf

  • contract_static
  • engine_run
  • engine_log_clean
  • shader_in_scene
  • capture_written
  • render_not_uniform
  • shader_changes_pixels

Limits to consider

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.