โ† All examples

godot shaders

Screen-space ambient occlusion from depth only

Darken creases and contacts with ambient occlusion estimated in one pass from the depth buffer: normals from position derivatives, a disc of samples scaled by distance, and a range check against far geometry.

Recorded render of Screen-space ambient occlusion from depth only

What this component contains

  • ATTRIBUTION.md
  • LICENSE
  • README.md
  • component.json
  • demo.tscn
  • inspect_shader.py
  • material.tres
  • post_depth_ao_approx.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), radius (float = 0.45), intensity (float = 1.4), samples (int = 16), bias (float = 0.03), max_pixels (float = 48), shadow_tint (vec4 = 0, 0, 0.05, 1) and 1 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 with soft darkening where objects meet the floor and in corners.
Renderers
compatibility: compiled and rendered, forward plus: not verified, mobile: not verified
Placement
res://baltor/godot_shaders/post_depth_ao_approx/

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

Applied after lighting, so it also darkens directly lit areas. Noisy without a blur pass (the per-pixel rotation trades banding for grain). Derivative normals break at object edges and give thin halos there. 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.