Gorilla.Controller.Passes.Bokeh

Overview

This unit implements a depth-of-field (DoF) post-processing effect with bokeh simulation for the Gorilla3D rendering pipeline. It produces realistic camera focus blur with configurable focal parameters, pentagon-shaped bokeh, chromatic aberration, and vignetting.

Architecture

The bokeh pass is a post-pass using RectToFBO rendering. It requires a depth pass as input (set via SetInputPass) to read per-pixel depth values. The shader samples surrounding pixels in concentric rings to simulate the blur circle of confusion, with the blur intensity determined by the distance from the focal plane.

Types

TGorillaBokehType

TGorillaBokehType = (btDefault, btGlow);
Value Description
btDefault Standard depth-of-field blur
btGlow Bokeh with enhanced glow effect

Core Classes

TGorillaRenderPassBokeh

Inherits from: TGorillaRenderPassController

Published Properties

Property Type Default Description
FocalDepth Single 10 Distance from the camera to the focal plane (in-focus region).
FocalLength Single 75 Simulated lens focal length in mm. Affects the size of the blur circle.
Vignette Single 16 Vignette darkening intensity at screen edges.
VignetteFade Single 24 Distance over which the vignette fades from edge to center.
FrustumNearFar TPointF (1, 100) Camera frustum near (X) and far (Y) plane distances. Must match the camera settings.
BlurSamples Integer 4 Number of blur samples per ring. Clamped to range 1..16. Higher values produce smoother blur at higher cost.
BlurRings Integer 4 Number of concentric blur rings. Clamped to range 1..16. More rings increase the maximum blur radius.
ShowFocus Boolean False When True, renders a visual indicator of the focus plane for debugging.
AutoFocus Boolean True When True, automatically focuses on the object at screen center using the depth buffer.
BokehType TGorillaBokehType btDefault Bokeh rendering style.

Key Methods

constructor Create(AOwner: TComponent); override;
destructor Destroy(); override;
procedure SetInputPass(AValue: TGorillaRenderPassController);

Convenience Component: TGorillaBokeh

Unit: Gorilla.Bokeh

TGorillaBokeh is a design-time convenience component that wraps a TGorillaRenderPassCustomDepth and a TGorillaRenderPassBokeh into a single droppable component. It exposes the same published properties as the bokeh pass.

Published Properties

Property Type Description
Viewport TGorillaViewport Target viewport
Enabled Boolean Enable/disable the effect
FocalDepth Single Focal plane distance
FocalLength Single Lens focal length
Vignette Single Vignette intensity
VignetteFade Single Vignette fade
FrustumNearFar TPointF Near/far planes
BlurSamples Integer Samples per ring
BlurRings Integer Concentric rings
ShowFocus Boolean Focus plane debug view
AutoFocus Boolean Auto-focus on center

Public Properties

Property Type Description
DepthPass TGorillaRenderPassCustomDepth The internal depth pass
MainPass TGorillaRenderPassBokeh The internal bokeh pass

Runtime Setup

Using TGorillaBokeh (Recommended)

uses
  Gorilla.Bokeh;

var
  LBokeh: TGorillaBokeh;
begin
  LBokeh := TGorillaBokeh.Create(GorillaViewport1);
  LBokeh.Viewport := GorillaViewport1;
  LBokeh.FocalDepth := 15;
  LBokeh.FocalLength := 50;
  LBokeh.BlurSamples := 6;
  LBokeh.BlurRings := 6;
  LBokeh.AutoFocus := True;
  LBokeh.Enabled := True;
end;

Using TGorillaRenderPassBokeh Directly

uses
  Gorilla.Controller.Passes.CustomDepth,
  Gorilla.Controller.Passes.Bokeh;

var
  LDepth: TGorillaRenderPassCustomDepth;
  LBokeh: TGorillaRenderPassBokeh;
begin
  LDepth := TGorillaRenderPassCustomDepth.Create(nil);
  LDepth.Viewport := GorillaViewport1;
  LDepth.Enabled := True;

  LBokeh := TGorillaRenderPassBokeh.Create(nil);
  LBokeh.Viewport := GorillaViewport1;
  LBokeh.SetInputPass(LDepth);
  LBokeh.FocalDepth := 15;
  LBokeh.FocalLength := 50;
  LBokeh.Enabled := True;
end;

Technical Details

  • Pass type: Post-pass (TRenderPassType.Post)
  • Render method: RectToFBO (full-screen quad)
  • The shader produces pentagon-shaped bokeh highlights using geometric masking.
  • Chromatic aberration is applied to out-of-focus regions, splitting color channels slightly for realism.
  • The circle of confusion is computed from the depth difference between each pixel and the focal plane, scaled by FocalLength.
  • BlurSamples * BlurRings determines the total number of texture lookups per pixel. Values of 4x4 (16 total samples) provide a good quality/performance balance.