Skip to content

Rendering

S.U.P.E edited this page Nov 6, 2026 · 1 revision

Rendering

Heaven3D's renderer is written directly against the OpenGL 3.3 Core profile through ModernGL (on macOS it runs on Apple's OpenGL 4.1 core profile). It is a deferred renderer with an HDR pipeline and a forward pass for transparency.

Frame overview

The main stages of a frame, roughly in order:

  1. Shadow pass — the sun renders a shadow map (default 2048²). Objects outside the sun's shadow view are skipped.
  2. Geometry pass (G-buffer) — opaque meshes write world positions (full 32-bit precision), normals, albedo, material (metal / rough / AO) and full-colour emissive.
  3. SSAO — screen-space ambient occlusion from the G-buffer.
  4. Lighting pass — Cook-Torrance GGX PBR for the sun, point, spot and ambient lights, with PCF soft shadows, into an HDR float buffer.
  5. Sky, clouds and ocean — the procedural sky and cloud layer, and the analytic Gerstner ocean.
  6. Forward transparency — alpha-blended materials, drawn after the opaque scene.
  7. Screen-space reflections and bloom.
  8. Tone mapping — ACES filmic.
  9. FXAA 3.11 (full Quality path), stacked on top of 4× hardware MSAA.

Materials (PBR)

Metallic-roughness workflow, matching glTF 2.0:

Property Default Notes
base_color (1, 1, 1, 1) RGBA; alpha used by MASK / BLEND
metallic 0.0
roughness 0.5
emissive, emissive_intensity (0,0,0), 1.0 glow, feeds bloom
base_color_tex, metallic_roughness_tex, normal_tex, emissive_tex, occlusion_tex none texture paths (or embedded GLB images)
alpha_mode "OPAQUE" OPAQUE, MASK (cut-out) or BLEND (forward pass)
alpha_cutoff 0.5 for MASK
double_sided false

Baked ambient occlusion (occlusion_tex) multiplies the image-based ambient and specular light.

Lights

Light Fields (defaults)
Sun (SunLight) direction, colour (1, 0.96, 0.90), intensity 3.0, shadow map 2048, shadow bias. The Sun is a scene node: rotating it changes the light, shadows and sky.
Point Light colour (1, 0.92, 0.78), intensity 8, range 12 m
Spot Light colour (1, 0.96, 0.88), intensity 14, range 18 m, inner angle 25°, outer angle 35°
Ambient colour (0.25, 0.27, 0.32), intensity 0.6

engine.spawn_flash(position, color) creates a short-lived point light for muzzle flashes and explosions.

Shadows

  • The shadow bias is measured in world units from the real shadow-texel size, so shadows stay attached to their objects.
  • Shadows fade out softly at the edge of the shadow area.
  • The shadow window snaps to whole texels, so edges don't crawl or shimmer when the camera moves.

Sky and clouds

Every scene gets a procedural day/night sky driven by the Sun's direction, plus a Clouds node:

CloudSettings Default
enabled true
coverage 0.45 fraction of the sky filled (0–1)
density 0.85 opacity and belly darkening
scale 1.0 larger = bigger cloud masses
altitude 800 height of the cloud plane (m)
speed 0.012 drift speed
tint (1, 1, 1) colour multiplier
wind_dir (0.8, 0.6) drift direction on XZ

Ocean

The Ocean node is an analytic Gerstner-wave sea with Beer-Lambert absorption, fresnel sky reflection, sun glint and foam. Wave heights are mirrored on the CPU, so floating objects get buoyancy.

OceanSettings Default
enabled true switch off for indoor or land-only levels
sea_level 0.0 world height of the mean surface
water_shallow / water_deep teal / deep blue absorption colours
wave_height 0.45 peak amplitude (m)
wave_speed 1.0 phase-speed multiplier
wind_dir, wind_strength (1, 0.35), 1.0 0 strength = glassy water
choppiness 0.7 crest sharpening
foam_amount 1.0 shoreline, crest and ripple foam
buoyancy_enabled, buoyancy_strength true, 1.0

Quality settings

Each project stores its post-processing switches in main.heaven3d:

"settings": {"shadows": true, "ssao": true, "bloom": true, "fxaa": true, "msaa": true, "msaa_samples": 4}

Performance features

  • Instancing for nodes that share a mesh and material.
  • The scene graph is walked once per frame (not once per pass), world matrices are computed without recursion, and node transforms are memoised.
  • Repeated material binds are skipped.
  • Shadow casters outside the sun's view are culled.

These optimisations are pixel-for-pixel identical to the unoptimised path. Set HEAVEN3D_NO_PERF=1 to switch them off for comparison.

On drivers that can't render 32-bit float positions, the G-buffer falls back to the older half-float format automatically.

Clone this wiki locally