/MiniBokeh

Lightweight DoF effect for Unity URP

Primary LanguageC#OtherNOASSERTION

MiniBokeh

gif

MiniBokeh is a lightweight depth-of-field effect for Unity's Universal Render Pipeline (URP).

Instead of sampling a camera depth texture, MiniBokeh models scene depth with a single reference plane. It assumes content lies on or near that plane, which makes it a good fit for planar scenes such as tabletop games, card games, or top-down strategy titles, and less suitable for general 3D scenes.

MiniBokeh uses a user-defined reference plane to compute depth. Place content near that plane for best results.

Reference Plane

MiniBokeh works well for top-down strategy scenes, especially when aiming for a miniature look (tilt-shift effect).

Fantasy Kingdom

It uses efficient separable blurs and provides two variants:

  • Hexagonal Separable Filter (L. McIntosh et al.) 1
  • Circular Separable Convolution Depth of Field (K. Garcia) 2

By using separable filters, MiniBokeh reduces GPU load compared to typical depth-of-field implementations, making it well-suited for mobile use.

System Requirements

  • Unity 6
  • Universal Render Pipeline (URP)
  • Render Graph enabled: MiniBokeh requires the URP Render Graph backend and is not compatible with "Compatibility Mode (Render Graph Disabled)" in the URP Global Settings.

Installation

The MiniBokeh package (jp.keijiro.minibokeh) can be installed via the "Keijiro" scoped registry using Package Manager. To add the registry to your project, please follow these instructions.

Setup

  • Add MiniBokehFeature to the Renderer Features list in your URP Renderer asset. See the Unity documentation for step-by-step instructions.
  • Attach the MiniBokehController component to each camera that should use the effect. The effect runs only on cameras with this component.

Controller Component

Inspector

Reference Plane

Transform that defines the reference plane used to compute depth.

Auto Focus

When enabled, focus distance is computed by intersecting the camera's forward ray with the reference plane. Disable to set it manually.

Focus Distance

Manual focus distance, used when Auto Focus is off.

Bokeh Strength

Controls bokeh sensitivity. Higher values create stronger blur with smaller depth differences. Value represents blur radius (% of screen height) when object distance equals focus distance.

Max Blur Radius

Maximum blur radius limit, specified as a percentage of screen height.

Boundary Fade

Controls edge darkening for out-of-bounds samples. See Limitations: Edge Sample Artifacts for details.

Bokeh Mode

Aperture shape. Hexagonal is faster but may show artifacts; Circular is smoother but uses more bandwidth.

Downsample Mode

Processing resolution. Half is faster with a slightly softer result; Full preserves more detail at higher cost.

Limitations

Artifacts with Hexagonal Bokeh

Hexagonal mode can produce artifacts near bright highlights.

Hex Artifacts

These artifacts are most visible in high-contrast scenes, for example with bright floating particles on a dark background.

Bokeh Shape Distortion

Bokeh shapes can appear distorted (teardrop-like) when the camera views the reference plane at a shallow angle.

Distorted Bokeh

A correct DoF scatters using the source pixel’s CoC; MiniBokeh gathers and uses the receiver’s CoC, which leads to distortion.

Edge Sample Artifacts

MiniBokeh uses clamp texture sampling for out-of-bounds samples. This can cause noticeable temporal artifacts at boundaries, especially with high-frequency elements (e.g., small dots, thin lines).

Edge artifacts example

You can reduce these by darkening out-of-bounds samples using the Boundary Fade property.

Boundary Fade applied

However, this also darkens screen edges, so balance it to suit the scene's tone.

Gallery

Screenshot 1 Screenshot 2 Screenshot 3 Screenshot 4