Renderer
Renderers in Gorilla3D manage the rendering pipeline, controlling how 3D scenes are drawn to the screen. The framework provides different renderer types optimized for various use cases, with the Forward Renderer being the recommended default.
Renderer Types
Forward Renderer (Recommended)
The default renderer using Weighted Blended Order Independent Transparency (WBOIT) for correct translucent object rendering regardless of draw order.
Features:
- Order-independent transparency
- Multiple render targets (albedo, normals, positions, emissive)
- Full support for Gorilla3D default materials
- Advanced effects (emissive blur, global illumination, FXAA)
- G-buffer access for custom effects
Use When:
- Building standard 3D applications
- Need correct transparency rendering
- Want access to advanced rendering features
- Using Gorilla3D materials
Legacy Renderer
Simple single-framebuffer renderer for maximum compatibility.
Features:
- Single render pass
- Single framebuffer
- Opaque-then-translucent rendering order
- Compatible with FMX materials
- Lower resource usage
Use When:
- Need maximum FMX material compatibility
- Doing extensive native OpenGL rendering
- Working on very limited hardware
- Don't need advanced transparency or effects
Accessing the Renderer
The renderer is managed internally by the viewport:
// Get the main pass renderer
var Renderer := Viewport.MainPassRenderer;
// Get current active renderer (may differ during render passes)
var CurrentRenderer := Viewport.CurrentRenderer;
// Change renderer type
Viewport.RendererType := TRendererType.ForwardRenderer;
// or
Viewport.RendererType := TRendererType.LegacyRenderer;
Rendering Pipeline
Forward Renderer Pipeline
-
Fragment Depth Pre-Pass (optional)
- Renders front-facing fragment depths
- Improves translucent blending
- Enable via
Viewport.FragmentDepthRendering
-
Opaque Rendering
- Render all opaque objects
- Writes to multiple render targets:
- Albedo (color)
- Normals
- Positions
- Emissive
-
Translucent Rendering
- Render translucent objects with WBOIT
- Writes to separate translucent albedo buffer
- Order-independent accumulation
-
Post-Processing Passes
- Voxelization (for GI)
- Global Illumination
- Emissive Blur
- Screen Space Effects (SSS, SSAO)
- FXAA
-
Compositing
- Combines all render targets
- Applies saturation
- Produces final image
Legacy Renderer Pipeline
-
Opaque Rendering
- Render all opaque objects to single buffer
-
Translucent Rendering
- Render translucent objects in order
- Standard alpha blending
-
Output
- Direct framebuffer output
Render Target Access
The Forward Renderer exposes various render targets for custom effects:
var
Renderer: TCompositeRenderer;
begin
if Viewport.MainPassRenderer is TCompositeRenderer then
begin
Renderer := Viewport.MainPassRenderer as TCompositeRenderer;
// Access render targets
var AlbedoTex := Renderer.AlbedoTexture; // Color
var NormalsTex := Renderer.NormalsTexture; // Normals
var PositionTex := Renderer.PositionTexture; // Positions
var EmissiveTex := Renderer.EmissiveTexture; // Emissive
var AlphaTex := Renderer.AlphaTexture; // Alpha
// Use in custom shaders or post-processing
end;
end;
Advanced Rendering Features
Emissive Blur
Create glowing effects for emissive materials:
// Enable emissive blur (via viewport)
Viewport.EmissiveBlur := 3; // 0-10, higher = stronger glow
// Or via renderer
if Viewport.MainPassRenderer is TCompositeRenderer then
(Viewport.MainPassRenderer as TCompositeRenderer).EmissiveBlur := 3;
Performance Impact: Each increment adds blur iterations. Start low (2-3) and increase carefully.
Global Illumination
Real-time voxel-based global illumination with shadows and reflections.
Availability: GAME_PACKAGE only
// Set quality level (0-7)
Viewport.GlobalIllumDetail := 3; // Good balance for normal GPUs
// Adjust appearance
Viewport.GlobalIllumSoftness := 1.0; // Shadow/reflection softness
Viewport.ShadowStrength := 0.4; // Shadow darkness
Viewport.ReflectionStrength := 0.5; // Reflection intensity
Quality Levels:
- Level 0: Off
- Level 1-2: Elder GPUs (32-64 voxels)
- Level 3-4: Normal GPUs (128-192 voxels)
- Level 5-7: High-end GPUs (256-512 voxels)
Fast Approximate Anti-Aliasing (FXAA)
Post-process anti-aliasing alternative to MSAA:
// Enable FXAA
Viewport.FXAA := 4; // 0-8, higher = smoother but slower
Comparison:
- MSAA: Hardware-based, samples during rasterization, higher quality, more memory
- FXAA: Post-process, edge detection, faster, less memory, slight blur
You can use both together for best results on capable hardware.
Screen Space Shadows
Soft shadows computed in screen space.
Availability: If enabled in build
Viewport.SSS_Enabled := True;
Viewport.SSS_NumSamples := 128; // Lower for better performance
Viewport.SSS_SampleStep := 0.05; // Larger = wider shadow area
Viewport.SSS_ShadowStrength := 2.0; // Darkness
Warning: Very performance-intensive. Each light iterates all samples.
Screen Space Ambient Occlusion (SSAO)
Adds realistic ambient shadows in crevices and corners.
Availability: If enabled in build
Viewport.SSAO_Enabled := True;
Viewport.SSAO_Radius := 1.0; // Sampling radius
Viewport.SSAO_Bias := 0.5; // Prevents self-shadowing
Viewport.SSAO_NoiseScale := PointF(1, 1);
Saturation Control
Control color saturation at different rendering stages:
// Opaque objects - usually no adjustment needed
Viewport.OpaqueSaturation := 0.0; // 0 = no saturation effect
// Translucent objects - often benefits from extra saturation
Viewport.TranslucentSaturation := 1.5;
// Final composite - post-process saturation
Viewport.CompositeSaturation := 0.0;
Or via renderer:
if Viewport.MainPassRenderer is TCompositeRenderer then
with (Viewport.MainPassRenderer as TCompositeRenderer) do
begin
Saturation := Point3D(0, 1.5, 0); // X=Opaque, Y=Translucent, Z=Composite
end;
Debugging Render Targets
Visualize individual render passes for debugging:
// Show only normals
Viewport.RendererOutputLayer := TRendererOutputLayer.OutputNormal;
// Show only albedo
Viewport.RendererOutputLayer := TRendererOutputLayer.OutputAlbedo;
// Show positions
Viewport.RendererOutputLayer := TRendererOutputLayer.OutputPosition;
// Show emissive only
Viewport.RendererOutputLayer := TRendererOutputLayer.OutputEmissive;
// Show depth
Viewport.RendererOutputLayer := TRendererOutputLayer.OutputDepth;
// Back to normal (all layers)
Viewport.RendererOutputLayer := TRendererOutputLayer.OutputAll;
Available Layers:
OutputAll- Normal renderingOutputAlbedo- Color/albedo onlyOutputTranslucentAlbedo- Translucent colorsOutputAlpha- Alpha channelOutputDepth- Depth bufferOutputPosition- World positionsOutputNormal- Surface normalsOutputEmissive- Emissive channelOutputComps- Material components (deferred)OutputAmbient- Ambient light (deferred)OutputSpecular- Specular light (deferred)OutputSSS- Screen space shadowsOutputSSAO- Ambient occlusion
Performance Optimization
Rendering Pipeline Optimization
// Disable unused features
Viewport.FragmentDepthRendering := False; // If no transparency
Viewport.EmissiveBlur := 0; // If no glowing materials
Viewport.FXAA := 0; // If using MSAA or performance critical
// Reduce global illumination quality
Viewport.GlobalIllumDetail := 2; // Lower on older GPUs
// Disable expensive screen space effects
Viewport.SSS_Enabled := False;
Viewport.SSAO_Enabled := False;
Resolution Scaling
// Render at lower resolution for performance
procedure SetRenderScale(AViewport: TGorillaViewport; AScale: Single);
begin
if Assigned(AViewport.MainPassRenderer) then
begin
AViewport.MainPassRenderer.Scale := AScale; // 0.5 = half resolution
end;
end;
MSAA vs FXAA Trade-offs
// High-end: Use both
Viewport.MSAA := TMSAASamples.Samples4X;
Viewport.FXAA := 2;
// Mid-range: MSAA only
Viewport.MSAA := TMSAASamples.Samples2X;
Viewport.FXAA := 0;
// Low-end: FXAA only
Viewport.MSAA := TMSAASamples.None;
Viewport.FXAA := 4;
// Minimum: Neither
Viewport.MSAA := TMSAASamples.None;
Viewport.FXAA := 0;
Common Patterns
Quality Settings Presets
procedure ApplyLowQuality(AViewport: TGorillaViewport);
begin
AViewport.MSAA := TMSAASamples.None;
AViewport.FXAA := 2;
AViewport.EmissiveBlur := 0;
AViewport.GlobalIllumDetail := 0;
AViewport.FragmentDepthRendering := False;
end;
procedure ApplyMediumQuality(AViewport: TGorillaViewport);
begin
AViewport.MSAA := TMSAASamples.Samples2X;
AViewport.FXAA := 2;
AViewport.EmissiveBlur := 2;
AViewport.GlobalIllumDetail := 2;
AViewport.FragmentDepthRendering := True;
end;
procedure ApplyHighQuality(AViewport: TGorillaViewport);
begin
AViewport.MSAA := TMSAASamples.Samples4X;
AViewport.FXAA := 4;
AViewport.EmissiveBlur := 4;
AViewport.GlobalIllumDetail := 5;
AViewport.FragmentDepthRendering := True;
end;
Screenshot/Video Recording Setup
procedure SetupForRecording(AViewport: TGorillaViewport);
begin
// Maximum quality
AViewport.MSAA := TMSAASamples.Samples8X;
AViewport.FXAA := 6;
AViewport.EmissiveBlur := 5;
// Disable manual rendering for consistent frame output
AViewport.ManualRendering := False;
AViewport.UseFixedFrameRate := True;
AViewport.FixedFrameRate := 30; // Match video framerate
end;
Best Practices
-
Start with Forward Renderer: Use
TRendererType.ForwardRendererunless you have specific reasons for Legacy. -
Enable Fragment Depth: Keep
FragmentDepthRendering := Trueif you have any close up transparent objects. -
Profile Before Optimizing: Use diagnostics to identify actual bottlenecks:
Viewport.DiagnosticsActive := True; ShowMessage(Format('Draw Calls: %d, FPS: %.1f', [Viewport.Diagnostics.DrawCalls, Viewport.Diagnostics.AverageFramesPerSecond])); -
Scale Effects to Hardware: Test on minimum spec hardware and provide quality settings.
-
Debug with Output Layers: Use render target visualization during development to understand what's being rendered.
-
Global Illumination Requires Tuning: GI settings are scene-dependent. Experiment with softness and strength values.
-
Batch Rendering Changes: Use
BeginUpdate/EndUpdatewhen changing multiple renderer settings.