Gorilla.Controller.Passes.Refraction
Overview
This unit implements planar refraction for the Gorilla3D rendering pipeline. It re-renders the scene from the normal camera view into an off-screen FBO while clipping geometry against a refraction surface plane, producing a refraction texture that can be applied to transparent surfaces such as water or glass.
Architecture
The refraction pass is a pre-pass using RenderListToFBO — it renders the scene from the regular camera, but a clip plane (defined by SurfacePosition / SurfaceNormal) removes geometry on the wrong side of the refractive surface. In addition to the color output the pass exposes a position/depth texture (OutputDepthTexture), which materials like TGorillaWaterMaterialSource use for depth-based edge blending.
Core Classes
TGorillaRenderPassRefraction
Inherits from: TGorillaRenderPassController
Default pass id: 'Refraction'
Published Properties
| Property | Type | Default | Description |
|---|---|---|---|
SurfacePosition |
TPosition3D |
(0, 0, 0) | World-space position of the refraction clipping surface plane. |
SurfaceNormal |
TPosition3D |
(0, 1, 0) | Normal vector of the clipping surface, pointing to the side that is kept. |
SurfaceCutOff |
Single |
0 | Additional offset that shifts the clipping plane along its normal. |
ClippingEnabled |
Boolean |
True | Enables/disables the refraction clipping surface. |
Public Properties
| Property | Type | Description |
|---|---|---|
OutputDepthTexture |
TTexture |
Read-only. The position/depth texture produced by the refraction renderer. |
Key Public Methods
function GetOutputTexture() : TTexture; override;
function GetTextureMatrix(AContext : TContext3D;
const AUseBias : Boolean = false) : TMatrix3D; override;
procedure SetupMatrices(const AContext : TContext3D);
CreateMaterialSource() returns nil — the refraction pass renders objects with their original materials.
Runtime Setup
uses
Gorilla.Controller.Passes.Refraction;
var
LRefraction: TGorillaRenderPassRefraction;
begin
LRefraction := TGorillaRenderPassRefraction.Create(nil);
LRefraction.Viewport := GorillaViewport1;
// Configure the water surface (Y = 0 plane, normal pointing up)
LRefraction.SurfacePosition := Point3D(0, 0, 0);
LRefraction.SurfaceNormal := Point3D(0, 1, 0);
LRefraction.ClippingEnabled := True;
// Exclude the water plane itself from the refraction render
LRefraction.IgnoreControl(WaterPlane);
LRefraction.Enabled := True;
end;
Assign the pass via the material's RefractionPass property (see Materials → Reflections and Refractions).
Technical Details
- Pass type: Pre-pass (
TRenderPassType.Pre) - Render method:
RenderListToFBO(re-renders scene objects) - The clip plane is derived from
SurfacePosition,SurfaceNormalandSurfaceCutOff. SetClippingEnabled := Falseto capture the full scene without clipping. OutputDepthTextureexposes the position buffer so refractive materials can blend by water depth and soften surface edges.