Gorilla.Controller.Passes.GlobalIllumination
Overview
This unit implements global illumination (GI) using voxel cone tracing for the Gorilla3D deferred rendering pipeline. It computes indirect lighting, soft shadows, and reflections by tracing cones through a voxelized representation of the scene.
The unit defines two classes:
TGorillaRenderPassGlobalIllum-- The standalone global illumination pass.TGorillaRenderPassEmbeddedGlobalIllum-- A variant used internally by the deferred composite system.
Architecture
The GI pass is a post-pass using RectToFBO rendering. It is marked as an internal render pass (IsInternalRenderPass = True). It reads position and normal G-buffers and samples a 3D voxel texture (produced by TGorillaRenderPassVoxelize) to compute:
- Shadow cone tracing -- Traces cones toward light sources through the voxel grid to compute soft indirect shadows.
- Reflection cone tracing -- Traces cones along reflection vectors for indirect specular reflections.
- Light scattering -- Simulates light diffusion through the voxelized scene.
Light data (up to 8 lights) is transferred to the GPU via a Uniform Buffer Object (UBO).
Core Classes
TGorillaRenderPassGlobalIllum
Inherits from: TGorillaRenderPassController
Published Properties
| Property | Type | Default | Description |
|---|---|---|---|
Position |
TGorillaRenderPassController |
nil | Input render pass providing the position G-buffer texture. |
Normals |
TGorillaRenderPassController |
nil | Input render pass providing the normals G-buffer texture. |
VoxelGeometry |
TGorillaRenderPassController |
nil | The voxelization pass (TGorillaRenderPassVoxelize) providing the 3D voxel texture. |
ShadowStrength |
Single |
0.4 | Strength of indirect shadows. Higher values produce darker indirect shadows. |
ReflectionStrength |
Single |
0.0 | Strength of indirect reflections. Set to 0 by default (reflections disabled). Increase to add voxel-based reflections. |
Public Methods
constructor Create(AOwner: TComponent); override;
destructor Destroy(); override;
TGorillaRenderPassEmbeddedGlobalIllum
Inherits from: TGorillaRenderPassGlobalIllum
An embedded variant designed for use within the deferred composite pipeline. Functionally identical to TGorillaRenderPassGlobalIllum but integrated into the deferred rendering workflow.
Related Units
Gorilla.Controller.Passes.Voxelize
The voxelization pass (TGorillaRenderPassVoxelize) must be set up first to provide the 3D voxel texture:
| Property | Type | Default | Description |
|---|---|---|---|
VoxelSize |
Integer |
-- | Voxel grid resolution (32..512, multiples of 32) |
FocalLength |
Single |
-- | Focal length for voxel projection |
Public properties include VoxelCenter (TPoint3D), BiasMatrix (TMatrix3D), and GetTexture3D (returns the 3D texture).
Constants: VOXEL_LOD = 8 (LOD levels used internally), VOXEL_MAX_LIGHTS = 8.
Gorilla.Controller.Passes.GlobalIllumBlur
TGorillaRenderPassGlobalIllumBlur extends TGorillaRenderPassBlur to smooth the GI output:
| Property | Type | Description |
|---|---|---|
GlobalIllumPass |
TGorillaRenderPassGlobalIllum |
The GI pass whose output to blur |
UpdateTexture |
Method | Updates the input texture reference |
Default blur amount is 1. Marked as internal render pass.
Runtime Setup
uses
Gorilla.Controller.Passes.Voxelize,
Gorilla.Controller.Passes.GlobalIllumination;
var
LVoxel: TGorillaRenderPassVoxelize;
LGI: TGorillaRenderPassGlobalIllum;
begin
// 1) Create voxelization pass
LVoxel := TGorillaRenderPassVoxelize.Create(nil);
LVoxel.Viewport := GorillaViewport1;
LVoxel.Enabled := True;
// 2) Create global illumination pass
LGI := TGorillaRenderPassGlobalIllum.Create(nil);
LGI.Viewport := GorillaViewport1;
LGI.Position := MyPositionPass;
LGI.Normals := MyNormalsPass;
LGI.VoxelGeometry := LVoxel;
LGI.ShadowStrength := 0.5;
LGI.ReflectionStrength := 0.2;
LGI.Enabled := True;
end;
Technical Details
- Pass type: Post-pass (
TRenderPassType.Post) - Render method: RectToFBO (full-screen quad)
- Maximum lights: 8 (transferred via UBO)
- Voxel cone tracing works by marching through the 3D voxel texture along cone directions, sampling at increasing LOD levels as the cone widens. This approximates the integral of incoming light along each cone.
- Shadow cones are traced toward each light source; occlusion in the voxel grid attenuates the light contribution.
- Reflection cones are traced along the surface reflection vector, gathering indirect specular information from the voxelized scene.
- The
ShadowStrengthandReflectionStrengthproperties control the intensity of these contributions in the final composite.