Gorilla.Controller.Passes.Reflection

Overview

This unit implements planar reflections for the Gorilla3D rendering pipeline. It renders a mirrored view of the scene from a virtual camera positioned on the opposite side of a reflective plane, producing a reflection texture that can be applied to flat reflective surfaces such as floors, water, or mirrors.

Architecture

The reflection pass is a pre-pass using RenderListToFBO -- it re-renders scene objects into an off-screen FBO using a mirrored camera. The mirror matrix is computed internally using ray-plane intersection, and a clip plane prevents rendering of geometry behind the mirror surface.

Core Classes

TGorillaRenderPassReflection

Inherits from: TGorillaRenderPassController

Published Properties

Property Type Default Description
Camera TCamera nil The scene camera. The reflection pass creates a mirrored version of this camera for rendering.
Target TControl3D nil The reflective surface object. This object is excluded from the reflection render to prevent self-reflection artifacts.
MirrorPosition TPoint3D (0, 0, 0) World-space position of the mirror plane.
MirrorNormal TPoint3D (0, -1, 0) Normal vector of the mirror plane, pointing away from the reflective side.
MirrorSize Single 10 Size of the mirror surface, used for clipping calculations.

Key Internal Methods

Method Description
CalcMirrorMatrix Computes the mirror transformation matrix using ray-plane intersection. Called internally before each render.

Runtime Setup

uses
  Gorilla.Controller.Passes.Reflection;

var
  LReflection: TGorillaRenderPassReflection;
begin
  LReflection := TGorillaRenderPassReflection.Create(nil);
  LReflection.Viewport := GorillaViewport1;
  LReflection.Camera := Camera1;
  LReflection.Target := FloorPlane;
  LReflection.MirrorPosition := Point3D(0, 0, 0);
  LReflection.MirrorNormal := Point3D(0, -1, 0);
  LReflection.MirrorSize := 20;
  LReflection.Enabled := True;
end;

After enabling the reflection pass, assign its output texture to the reflective material's reflection texture slot to display the reflection on the surface.

Technical Details

  • Pass type: Pre-pass (TRenderPassType.Pre)
  • Render method: RenderListToFBO (re-renders scene objects)
  • The mirror matrix flips the camera across the defined plane. The clip plane ensures only geometry above the mirror surface is rendered into the reflection.
  • The MirrorNormal default of (0, -1, 0) is oriented for a horizontal floor reflection. For vertical mirrors, adjust the normal accordingly (e.g., (0, 0, 1) for a wall mirror facing the Z direction).
  • The Target property is important for preventing the mirror surface itself from appearing in the reflection, which would cause visual artifacts.