Baltor Get started

Gallery / Godot shaders

Depth of field with a golden-angle bokeh gather

In your harnessGodot shaderMIT

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.

Render of Depth of field with a golden-angle bokeh gather
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), 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/

Limits. 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.

Details

Kind
Godot shader
Engine
Godot 4.3 or later
Files
11 files, 67.2 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
Circle of confusion from linear depth, Golden-angle (Vogel) disc sampling, Mutual radius weighting to limit bleeding
Tags
godot shader, spatial, post-process, depth of field, bokeh, blur, camera, full-screen
Identity
library.supply.creative_originals.1d9926dccd4647888fb02b96.ed6c440395ffe804
Version
ed6c440395ffe804b3b02e413dcddb21bf78efc0a708ff3e834720ad5f95835d

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.