Render Passes
Introduction
The Gorilla3D render pass system provides a flexible multi-pass rendering pipeline for applying advanced visual effects to your 3D scene. Each render pass operates on the scene or on previously rendered textures, producing output that can be chained into subsequent passes.
All render passes inherit from TGorillaRenderPassController, which manages FBO (Frame Buffer Object) allocation, shader compilation, and integration with the viewport's rendering loop. Passes are categorized into two types:
- Pre-passes (
TRenderPassType.Pre) -- Execute before the main scene render. They typically re-render scene objects into an off-screen buffer (e.g., shadow maps, reflections, environment maps, voxelization). - Post-passes (
TRenderPassType.Post) -- Execute after the main scene render. They read the rendered image and apply full-screen effects (e.g., FXAA, bokeh, SSAO compositing, underwater).
Passes use two rendering strategies:
- RenderListToFBO -- Re-renders scene objects into an FBO with a custom shader (used by pre-passes like shadows, reflections, environment).
- RectToFBO -- Renders a full-screen quad with a post-processing shader (used by post-passes like FXAA, bokeh, blur).
Table of Contents
- Anti-Aliasing (FXAA)
- Shadow Mapping
- Screen-Space Ambient Occlusion (SSAO)
- Global Illumination
- Reflections and Refractions
- Depth of Field (Bokeh)
- Blur Passes
- Post-Processing (PostFX)
- Underwater Effect
- Composite Pass
- Deferred Composite
Anti-Aliasing (FXAA)
Unit: Gorilla.Controller.Passes.FXAA
Class: TGorillaRenderPassFXAA
Type: Post-pass, RectToFBO, 1 iteration
FXAA (Fast Approximate Anti-Aliasing) smooths jagged edges in the final rendered image using a luminance-based edge detection algorithm. It operates as an internal render pass and is typically managed by the deferred composite system.
Key Methods
| Method | Description |
|---|---|
SetCompositeInputTexture |
Assigns the input texture from the composite pass |
GetFinalOutputTexture |
Returns the anti-aliased output texture |
Runtime Setup
var
LPass: TGorillaRenderPassFXAA;
begin
LPass := TGorillaRenderPassFXAA.Create(nil);
LPass.Viewport := GorillaViewport1;
LPass.Enabled := True;
end;
Note: FXAA is typically activated automatically when using the deferred rendering pipeline. Manual setup is rarely needed.
Shadow Mapping
Standard Shadow Map (SM)
Unit: Gorilla.Controller.Passes.SMStoreDepth
Class: TGorillaRenderPassSMStoreDepth
Type: Pre-pass, RenderListToFBO
Renders the scene depth from a light's perspective into a shadow map texture. The viewport size defaults to 1024x1024 with OverwriteViewportSize = True.
Published Properties
| Property | Type | Default | Description |
|---|---|---|---|
Light |
TLight |
nil | The light source for shadow projection |
Inherited from TGorillaRenderPassCustomDepth
| Property | Type | Default | Description |
|---|---|---|---|
DepthMethod |
TDepthMethod |
dmDefault |
Depth calculation method: dmDefault, dmMVPPosZ, dmModelViewPosZ |
Public Properties
| Property | Type | Description |
|---|---|---|
MapSize |
Integer |
Shadow map resolution |
BiasMatrix |
TMatrix3D |
Light-space bias matrix for shadow lookup |
DefaultDepth |
Single |
Default depth value for clear |
Variance Shadow Map (VSM)
Unit: Gorilla.Controller.Passes.VSMStoreDepth
Class: TGorillaRenderPassVSMStoreDepth
Type: Pre-pass, RenderListToFBO
Stores both depth and depth-squared (moments) into an RG16F texture, enabling soft shadow edges through variance-based filtering. The shader computes moment1 = depth and moment2 = depth * depth with a partial derivative bias.
Published Properties
| Property | Type | Default | Description |
|---|---|---|---|
Light |
TLight |
nil | The light source for shadow projection |
VSM Blur
Unit: Gorilla.Controller.Passes.VSMBlur
Class: TGorillaRenderPassVSMBlur
Type: Pre-pass, RectToFBO, PingPong mode, 2 iterations
Blurs the variance shadow map to produce soft shadow edges. Uses ping-pong rendering between two FBOs with a default blur amount of 5.
Published Properties
| Property | Type | Description |
|---|---|---|
VSMStoreDepth |
TGorillaRenderPassVSMStoreDepth |
The VSM depth pass to blur (via GetInputPass/SetInputPass) |
Screen-Space Shadows
Unit: Gorilla.Controller.Passes.ScreenSpaceShadows
Class: TGorillaRenderPassScreenSpaceShadows
Type: Post-pass, RectToFBO, internal render pass
Computes shadows in screen space using ray marching from each pixel toward each light source. Supports up to 8 lights via a Uniform Buffer Object (UBO).
Published Properties
| Property | Type | Default | Description |
|---|---|---|---|
Position |
TGorillaRenderPassController |
nil | Position G-buffer input |
Normals |
TGorillaRenderPassController |
nil | Normals G-buffer input |
ShadowStrength |
Single |
4.0 | Shadow intensity multiplier |
NumSamples |
Integer |
32 | Number of ray march samples |
SampleStep |
Single |
0.1 | Step size for ray marching |
Screen-Space Ambient Occlusion (SSAO)
Unit: Gorilla.Controller.Passes.SSAO
Class: TGorillaRenderPassSSAO
Type: Post-pass, RectToFBO, internal render pass
Computes ambient occlusion in screen space using a 128-sample hemisphere kernel and a 4x4 noise texture for randomized sampling. Transfers kernel data efficiently via a UBO (SSAOShaderData).
Published Properties
| Property | Type | Default | Description |
|---|---|---|---|
Position |
TGorillaRenderPassController |
nil | Position G-buffer input |
Normals |
TGorillaRenderPassController |
nil | Normals G-buffer input |
Radius |
Single |
1.0 | Sampling hemisphere radius |
Bias |
Single |
0.5 | Depth comparison bias |
NoiseScale |
TPointF |
(1, 1) | Noise texture tiling scale |
Runtime Setup
var
LPass: TGorillaRenderPassSSAO;
begin
LPass := TGorillaRenderPassSSAO.Create(nil);
LPass.Viewport := GorillaViewport1;
LPass.Position := MyPositionPass;
LPass.Normals := MyNormalsPass;
LPass.Radius := 1.5;
LPass.Bias := 0.25;
LPass.Enabled := True;
end;
Note: The unit also defines
TGorillaRenderPassEmbeddedSSAO, which is the variant used internally by the deferred composite system.
Global Illumination
Voxelization
Unit: Gorilla.Controller.Passes.Voxelize
Class: TGorillaRenderPassVoxelize
Type: Pre-pass, RenderListToFBO
Converts scene geometry into a 3D voxel texture for use in voxel cone tracing. Generates 6 LOD levels and supports up to 8 lights (VOXEL_MAX_LIGHTS = 8).
Published Properties
| Property | Type | Default | Description |
|---|---|---|---|
VoxelSize |
Integer |
-- | Voxel grid resolution (32..512, multiples of 32) |
FocalLength |
Single |
-- | Focal length for voxel projection |
Public Properties
| Property | Type | Description |
|---|---|---|
VoxelCenter |
TPoint3D |
Center of the voxel grid |
BiasMatrix |
TMatrix3D |
Voxel-space transformation matrix |
GetTexture3D |
Function | Returns the 3D voxel texture |
The unit also defines
TGorillaRenderPassEmbeddedVoxelizefor internal use by the deferred pipeline.
Global Illumination Pass
Unit: Gorilla.Controller.Passes.GlobalIllumination
Class: TGorillaRenderPassGlobalIllum
Type: Post-pass, RectToFBO, internal render pass
Computes indirect lighting using voxel cone tracing. Traces shadow cones, reflection cones, and light scattering cones through the voxelized scene. Supports up to 8 lights via UBO.
Published Properties
| Property | Type | Default | Description |
|---|---|---|---|
Position |
TGorillaRenderPassController |
nil | Position G-buffer input |
Normals |
TGorillaRenderPassController |
nil | Normals G-buffer input |
VoxelGeometry |
TGorillaRenderPassController |
nil | Voxelization pass providing 3D texture |
ShadowStrength |
Single |
0.4 | Indirect shadow intensity |
ReflectionStrength |
Single |
0.0 | Indirect reflection intensity |
The unit also defines
TGorillaRenderPassEmbeddedGlobalIllumfor internal deferred pipeline use.
Global Illumination Blur
Unit: Gorilla.Controller.Passes.GlobalIllumBlur
Class: TGorillaRenderPassGlobalIllumBlur
Type: Post-pass, extends TGorillaRenderPassBlur, internal render pass
Blurs the global illumination output to reduce noise. Default blur amount is 1.
Public Properties
| Property | Type | Description |
|---|---|---|
GlobalIllumPass |
TGorillaRenderPassGlobalIllum |
The GI pass to blur |
UpdateTexture |
Method | Updates the input texture reference |
Reflections and Refractions
Planar Reflection
Unit: Gorilla.Controller.Passes.Reflection
Class: TGorillaRenderPassReflection
Type: Pre-pass, RenderListToFBO
Renders a mirrored view of the scene for planar reflective surfaces. Uses a mirror matrix computed via ray-plane intersection, with clip planes to prevent rendering below the mirror surface.
Published Properties
| Property | Type | Default | Description |
|---|---|---|---|
Camera |
TCamera |
nil | Scene camera |
Target |
TControl3D |
nil | Object to exclude from reflection (the mirror itself) |
MirrorPosition |
TPoint3D |
(0,0,0) | Position of the mirror plane |
MirrorNormal |
TPoint3D |
(0,-1,0) | Normal vector of the mirror plane |
MirrorSize |
Single |
10 | Size of the mirror surface |
Runtime Setup
var
LReflection: TGorillaRenderPassReflection;
begin
LReflection := TGorillaRenderPassReflection.Create(nil);
LReflection.Viewport := GorillaViewport1;
LReflection.Camera := Camera1;
LReflection.Target := MirrorPlane1;
LReflection.MirrorPosition := Point3D(0, 0, 0);
LReflection.MirrorNormal := Point3D(0, -1, 0);
LReflection.MirrorSize := 15;
LReflection.Enabled := True;
end;
Refraction
Unit: Gorilla.Controller.Passes.Refraction
Class: TGorillaRenderPassRefraction
Type: Pre-pass, RenderListToFBO
Renders the scene as seen through a refractive surface, using clip planes to render only geometry on one side of the surface.
Published Properties
| Property | Type | Default | Description |
|---|---|---|---|
SurfacePosition |
TPoint3D |
(0,0,0) | Position of the refractive surface |
SurfaceNormal |
TPoint3D |
(0,1,0) | Normal of the refractive surface |
SurfaceCutOff |
Single |
0 | Cut-off distance for clipping |
ClippingEnabled |
Boolean |
True | Enable/disable clip plane |
Public Properties
| Property | Type | Description |
|---|---|---|
OutputDepthTexture |
Texture | Depth texture output for refraction calculations |
Environment Mapping
Unit: Gorilla.Controller.Passes.Environment
Class: TGorillaRenderPassEnvironment
Type: Pre-pass, RenderListToFBO, 6 iterations (one per cube face)
Renders the scene into a 6-face cubemap texture for environment reflections. Each face is rendered from the environment position looking in the corresponding axis direction.
Published Properties
| Property | Type | Default | Description |
|---|---|---|---|
Position |
TPoint3D |
-- | Center position for environment capture |
IsDynamic |
Boolean |
False | Re-render every frame if True |
Target |
TControl3D |
nil | Object to exclude from environment |
UseEmbeddedLight |
Boolean |
True | Use built-in light for environment rendering |
CenterOffsetFront |
Single |
-- | Per-face offset for front |
CenterOffsetBack |
Single |
-- | Per-face offset for back |
CenterOffsetLeft |
Single |
-- | Per-face offset for left |
CenterOffsetRight |
Single |
-- | Per-face offset for right |
CenterOffsetTop |
Single |
-- | Per-face offset for top |
CenterOffsetBottom |
Single |
-- | Per-face offset for bottom |
Public Properties
| Property | Type | Description |
|---|---|---|
Camera |
TCamera |
Internal camera used for rendering |
EmbeddedLight |
TLight |
Built-in light for environment |
MapSize |
Integer |
Cubemap face resolution (default 128) |
CubeMap |
Texture | The generated cubemap texture |
Public Methods
| Method | Description |
|---|---|
InvalidateEnvironment |
Forces re-rendering of the cubemap |
SetCenterOffsets(AValue) |
Sets all 6 face offsets to the same value |
SetCenterOffsets(F,B,L,R,T,Bo) |
Sets each face offset individually |
Runtime Setup
var
LEnvMap: TGorillaRenderPassEnvironment;
begin
LEnvMap := TGorillaRenderPassEnvironment.Create(nil);
LEnvMap.Viewport := GorillaViewport1;
LEnvMap.Position := Point3D(0, 2, 0);
LEnvMap.IsDynamic := False;
LEnvMap.Target := ReflectiveSphere1;
LEnvMap.Enabled := True;
end;
Depth of Field (Bokeh)
Unit: Gorilla.Controller.Passes.Bokeh
Class: TGorillaRenderPassBokeh
Type: Post-pass, RectToFBO
Simulates camera depth of field with bokeh blur shapes. Supports pentagon-shaped bokeh, chromatic aberration, vignetting, and auto-focus. Requires a depth pass as input.
Published Properties
| Property | Type | Default | Description |
|---|---|---|---|
FocalDepth |
Single |
10 | Distance to the focal plane |
FocalLength |
Single |
75 | Lens focal length |
Vignette |
Single |
16 | Vignette intensity |
VignetteFade |
Single |
24 | Vignette fade distance |
FrustumNearFar |
TPointF |
(1, 100) | Camera frustum near/far planes |
BlurSamples |
Integer |
4 | Blur sample count (clamped 1..16) |
BlurRings |
Integer |
4 | Blur ring count (clamped 1..16) |
ShowFocus |
Boolean |
False | Visualize the focus plane |
AutoFocus |
Boolean |
True | Auto-focus on center of screen |
BokehType |
TGorillaBokehType |
btDefault |
Bokeh style: btDefault, btGlow |
Convenience Component: TGorillaBokeh
Unit: Gorilla.Bokeh
A design-time convenience component that wraps TGorillaRenderPassCustomDepth and TGorillaRenderPassBokeh together. Drop it onto a viewport to enable depth of field.
Runtime Setup
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;
Blur Passes
Custom Blur
Unit: Gorilla.Controller.Passes.CustomBlur
Class: TGorillaRenderPassBlur
Type: Post-pass, RectToFBO
Base class for all blur render passes. Supports multiple blur algorithms and ping-pong rendering for iterative blurring.
Published Properties
| Property | Type | Default | Description |
|---|---|---|---|
BlurType |
TPassBlurType |
-- | Blur algorithm: RadialBlur, FastBlur, GaussianBlur |
BlurMode |
TPassBlurMode |
-- | Direction: Horizontal, Vertical |
BlurAmount |
Single |
-- | Blur strength |
Exposure |
Single |
-- | Exposure adjustment |
Note:
FastBlurmay produce unexpected artefacts on some NVIDIA GPUs.
Emissive Blur
Unit: Gorilla.Controller.Passes.EmissiveBlur
Class: TGorillaRenderPassEmissiveBlur
Type: Extends TGorillaRenderPassBlur, internal render pass
Blurs the emissive channel from the deferred rendering G-buffer to produce bloom/glow effects.
Public Properties
| Property | Type | Description |
|---|---|---|
EmissiveTexture |
Texture | The emissive G-buffer texture to blur |
Post-Processing (PostFX)
Unit: Gorilla.Controller.Passes.PostFX
Class: TGorillaRenderPassPostFX
Type: Post-pass, RectToFBO
Allows custom GLSL post-processing shaders. You provide a surface shader function that processes each fragment. The pass provides access to G-buffer textures and time information via a UBO.
Published Properties
| Property | Type | Default | Description |
|---|---|---|---|
SurfaceShader |
TStrings |
nil | Custom GLSL shader code |
MaskTexture |
TBitmap |
nil | Optional mask texture |
Available Shader Uniforms
| Uniform | Description |
|---|---|
_RenderedTexture |
The main rendered scene texture |
_MaskTexture |
User-supplied mask texture |
_AlphaTexture |
Alpha G-buffer channel |
_PositionTexture |
Position G-buffer channel |
_NormalsTexture |
Normals G-buffer channel |
_EmissiveTexture |
Emissive G-buffer channel |
UBO Time Data
The _TimeInfo vec4 uniform provides:
X= start timeY= current timeZ= previous frame timeW= delta time
Surface Shader Signature
Your custom shader must implement:
vec3 SurfaceShader(inout TLocals DATA)
Public Methods
| Method | Description |
|---|---|
ResetTime |
Resets the internal time counter |
UpdateShader |
Recompiles the shader after changing SurfaceShader |
Runtime Setup
var
LPostFX: TGorillaRenderPassPostFX;
begin
LPostFX := TGorillaRenderPassPostFX.Create(nil);
LPostFX.Viewport := GorillaViewport1;
LPostFX.SurfaceShader.Text :=
'vec3 SurfaceShader(inout TLocals DATA) {' + sLineBreak +
' vec3 col = DATA.Color.rgb;' + sLineBreak +
' float gray = dot(col, vec3(0.299, 0.587, 0.114));' + sLineBreak +
' return vec3(gray);' + sLineBreak +
'}';
LPostFX.UpdateShader;
LPostFX.Enabled := True;
end;
Underwater Effect
Unit: Gorilla.Controller.Passes.Underwater
Class: TGorillaRenderPassUnderwater
Type: Post-pass, RectToFBO
A procedural underwater visual effect using ray marching and caustics simulation with time-based animation. Reads the position G-buffer from the deferred composite to determine which fragments are below the water surface (Y < 0).
Composite Pass
Unit: Gorilla.Controller.Passes.Composite
Class: TGorillaRenderPassComposite
Type: Post-pass, RectToFBO
Combines two render pass outputs using a configurable blending method.
Published Properties
| Property | Type | Default | Description |
|---|---|---|---|
Method |
TCompositeMethod |
-- | Blend operation: Add, Subtract, Multiply, Divide, Mix, Input1, Input2 |
BlendFactor |
Single |
-- | Blending factor for Mix method |
Public Methods
| Method | Description |
|---|---|
SetInput2Pass |
Assigns the second input render pass |
Deferred Composite
Unit: Gorilla.Controller.Passes.Deferred.Composite
Class: TGorillaRenderPassDeferredComposite
Type: Post-pass
The central compositing pass for the deferred rendering pipeline. Combines all G-buffer channels (albedo, position, normals, emissive, etc.) with lighting, shadows, SSAO, global illumination, and other effects into the final image.
Output Layer Flags
| Constant | Value | Description |
|---|---|---|
ALL |
$00 | All layers |
ALBEDO |
$01 | Opaque albedo |
TRANSLUCENT_ALBEDO |
$02 | Translucent albedo |
ALPHA |
$04 | Alpha channel |
DEPTH |
$08 | Depth buffer |
POSITION |
$10 | World-space position |
NORMAL |
$20 | World-space normals |
EMISSIVE |
$40 | Emissive channel |
COMPS |
$80 | Components channel |
AMBIENT |
$100 | Ambient channel |
SPECULAR |
$200 | Specular channel |
SSS |
$1000 | Subsurface scattering |
SSAO |
$2000 | SSAO |
Key Material Textures
| Property | Description |
|---|---|
AlbedoTexture |
Opaque albedo G-buffer |
TranslucentAlbedoTexture |
Translucent albedo G-buffer |
AlphaTexture |
Alpha G-buffer |
PositionTexture |
Position G-buffer |
NormalsTexture |
Normals G-buffer |
EmissiveTexture |
Emissive G-buffer |
SSSTexture |
Subsurface scattering G-buffer |
SSAOTexture |
SSAO G-buffer |
ComponentsTexture |
Material components G-buffer |
AmbientTexture |
Ambient lighting G-buffer |
SpecularTexture |
Specular lighting G-buffer |
Key Properties
| Property | Type | Description |
|---|---|---|
Saturation |
TPoint3D |
Saturation: X=opaque, Y=translucent, Z=composite |
EmissiveBlur |
-- | Emissive bloom blur control |
GlobalFlags |
-- | Global rendering flags |
SSSFlags |
-- | Subsurface scattering flags |
SSAOFlags |
-- | SSAO flags |
SSRFlags |
-- | Screen-space reflection flags |