Gorilla.Controller.Passes.Underwater

Overview

This unit implements a full-screen underwater post-processing effect. When the camera dips below a defined water surface, it applies animated refraction distortion, depth-based color absorption (fog), caustics shimmer, a fisheye/barrel warp and a diving-mask vignette — fading smoothly in and out around the surface.

Architecture

The underwater pass is a post-pass using RectToFBO. It draws a fullscreen quad with a screen-space shader that reads the rendered scene color (Color_0) and the transformed-position buffer (Color_2) from the main renderer. All effect parameters are packed into a TUnderwaterShaderData UBO and updated per frame. The effect strength is driven by the camera position relative to SurfaceHeight, smoothed over TransitionBand.

Core Classes

TGorillaRenderPassUnderwater

Inherits from: TGorillaRenderPassController

Default pass id: 'Underwater'

Published Properties

Property Type Default Description
SurfaceHeight Single 0 World-space Y of the water surface; the effect activates below it.
TransitionBand Single 0.35 Fade width (world units) around the surface for a smooth in/out blend.
Intensity Single 1.0 Master effect strength (0..1).
TintColor TAlphaColor $FF14506E Underwater tint / fog color (deep teal-blue).
Distortion Single 1.0 Amount of animated wavy refraction.
Fisheye Single 0.15 Radial barrel-distortion amount.
Density Single 0.06 Depth-fog density.
Caustics Single 0.15 Animated caustics shimmer amount.
Vignette Single 0.6 Edge darkening (diving-mask) amount.
WaveScale Single 12.0 Spatial frequency of the wavy distortion.
WaveSpeed Single 1.2 Animation speed of distortion and caustics.

Key Public Methods

procedure Loaded(); override;
procedure UpdateShader();
function ComputeUnderwaterAmount() : Single;
procedure ApplyEffectParams();

ComputeUnderwaterAmount() returns the current fade factor (0..1) from the camera position versus SurfaceHeight, smoothstepped across TransitionBand. ApplyEffectParams() pushes the parameters into the shader each frame.

TUnderwaterMaterial / TUnderwaterMaterialSource

Internal material classes holding the post-process shader and the TUnderwaterShaderData record. TUnderwaterMaterialSource exposes a TransfPosition texture input.

TUnderwaterShaderData (packed record)

Field Type Contents
TimeInfo TVector3D start / current / previous / delta time
Params TVector3D underwater amount × intensity, distortion, fisheye, density
Tint TVector3D tint color RGB + caustics shimmer
Extra TVector3D vignette, wave scale, wave speed
CameraPos TVector3D camera world position (for depth fog)

Runtime Setup

uses
  Gorilla.Controller.Passes.Underwater;

var
  LUnderwater: TGorillaRenderPassUnderwater;
begin
  LUnderwater := TGorillaRenderPassUnderwater.Create(nil);
  LUnderwater.Viewport      := GorillaViewport1;
  LUnderwater.SurfaceHeight := 0.0;     // water plane at Y = 0
  LUnderwater.TransitionBand := 0.5;
  LUnderwater.TintColor     := $FF14506E;
  LUnderwater.Density       := 0.08;
  LUnderwater.Caustics      := 0.2;
  LUnderwater.Enabled       := True;
end;

Technical Details

  • Pass type: Post-pass (TRenderPassType.Post)
  • Render method: RectToFBO (fullscreen quad)
  • Inputs: scene color (Color_0) and transformed position (Color_2) MRT outputs from the main renderer.
  • The effect automatically fades to nothing above SurfaceHeight, so the pass can stay enabled permanently.
  • Shader support: GLSL (OpenGL ES 3.1+ / OpenGL 4.3+) and Metal (macOS/iOS, experimental).

See Also