โ† All examples

godot shaders

Depth of field with a golden-angle bokeh gather

Blur the scene by distance from a focus plane: a circle of confusion per pixel from the depth buffer and a gather of samples on a golden-angle spiral, weighted so sharp foreground edges do not smear.

Recorded render of Depth of field with a golden-angle bokeh gather

What this component contains

  • ATTRIBUTION.md
  • LICENSE
  • README.md
  • component.json
  • demo.tscn
  • inspect_shader.py
  • material.tres
  • post_depth_of_field.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), focus_distance (float = 2.4), focus_range (float = 0.4), blur_falloff (float = 2.5), max_blur_pixels (float = 9), samples (int = 32), show_focus (bool = no)
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 the red sphere sharp and the far pillars and floor softly blurred.
Renderers
compatibility: compiled and rendered, forward plus: not verified, mobile: not verified
Placement
res://baltor/godot_shaders/post_depth_of_field/

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

A gather approximation: out-of-focus foreground cannot spread over in-focus objects behind it (no scatter). Each sample reads depth again, so the cost is twice the sample count in texture reads. 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.