There are quite a few things I didn’t fully understand here; I’ll need to go over them again later.
The God of the Earth and the God of the Sky
Course positioning: Lecture 6 of GAMES104 Modern Game Engine: From Introduction to Practice, on the rendering of “Mother Nature” — how to express the magnificent natural world with 0s and 1s.
“God of the Earth” and “God of the Sky”: In a game engine team, the engineer responsible for the terrain system is called the “God of the Earth”, and the one responsible for sky, lighting, and clouds is called the “God of the Sky”. These titles arose spontaneously within teams and reflect a love for the technology of rendering nature.
Rendering the beauty of nature: From Spanish cave paintings to Picasso, the human instinct to express nature continues to this day. The mission of game engine developers is to turn mountains, rivers, and skies into virtual worlds with mathematical formulas.
Terrain Rendering Basics
Core Concept: Height Field
Definition: Terrain in a game engine is called Terrain, a word rooted in the Old English meaning “mother of the earth”.
Height Field is the most basic way to represent terrain:
- Use a 2D grayscale image to represent terrain height (similar to a contour map)
- Mathematical essence: $y = f(x,z)$, a single-valued function
- Long before computer games appeared, surveying already used contour lines (Counter) to represent terrain
Geometry generation:
- Generate a uniform grid (e.g., one vertex per meter)
- Displace vertices along the Y axis according to the Height Field
- The early approach is simple, but in an Open World the data volume explodes (1km×1km needs 1 million vertices)
Fractal and the Laws of Nature
Natural terrain (mountain ranges, coastlines, erosion marks) follows the principle of fractals: infinitely self-similar shapes. This mathematical law is the foundation of procedural terrain generation.
Terrain LOD (Level of Detail) Techniques
Core conflict: up close you need detail, far away you need efficiency.
LOD principles:
- Distance-dependent: dense nearby, sparse far away
- FOV (Field of View)-dependent: the narrower the view (e.g., when aiming down sights), the finer the triangles; the wider the view, the sparser they are
- Rationale: at the same screen pixels, the smaller the FOV, the more pixels a single object occupies, so higher geometric precision is required
- Application: 3x and 8x scopes are implemented by shrinking the FOV
Mesh Subdivision Algorithms
Binary Triangle Tree
- Method: always split at the midpoint of the longest side (the hypotenuse) of an isosceles right triangle, producing two new isosceles right triangles
- Structure: a binary tree
- Problem: T Junction (T-shaped junction / crack)
- When adjacent triangles have different subdivision levels, the shared edge ends up with “a vertex on one side and no vertex on the other”
- Result: cracks appear in the terrain (white edges showing the sky background)
- Solution: force-refine the coarser side until it matches its neighbor’s level
Quadtree — the mainstream approach in modern games
- Idea: cut the terrain into “tofu cubes”, which matches human intuition and computer storage conventions (textures and height maps are all block-shaped)
- Hierarchy:
- Block: e.g., a 512m×512m on-disk data block (stores height map, textures, vegetation, and building information)
- Patch: further subdivided into e.g. 64m×64m pieces
- Stop merging once subdivided to the visual limit
T Junction solution: Stitching
- Rather than changing the geometry topology, the extra vertices are “stitched” onto the neighbor’s edge
- This forms degenerate triangles (triangles with zero area)
- Advantage: the mesh structure is unchanged, and the code is simpler than with a Binary Triangle Tree
GPU-Driven Terrain Tessellation
Traditional pipeline (DX11)
- Hull Shader: generates the patches (control points) used for tessellation
- Tessellator: fixed-function hardware unit that subdivides edges a set number of times
- Domain Shader: samples the height map at the tessellated vertices and displaces them
- Geometry Shader: Post Processing; passes vertex data to the next stage
Modern approach: Mesh Shader (DX12+)
- Revolutionary change: Hull, Domain, and Geometry shaders are merged, generating Meshlets (small geometry pieces) in one pass
- Advantages:
- Programmers have full control over the subdivision algorithm
- More flexible geometry generation
- Provides a foundation for Deformable Terrain
Dynamic/Deformable Terrain
Use cases:
- A tractor leaving ruts in a rice field
- The deformable snow in God of War
- Craters left by artillery explosions
Implementation logic:
- Generate geometry in real time with GPU Tessellation
- Maintain a Deformation Texture at runtime
- Add the deformation offset in the Vertex Shader
- Physics synchronization: the Collision Mesh must be updated in sync, otherwise you get the “walking on the void” bug
Complex Terrain Features: Beyond the Height Field
Limitations of the Height Field
- Cannot express vertical Overhangs
- Cannot express Caves or tunnels
Traditional hack solutions
- Hole-punching markers: in the Vertex Shader, output NaN (invalid number) for vertices in the region to be punched out, and the GPU automatically culls the affected triangles
- Placing objects at seams: manually place rock models at cliff edges to hide the seams
Volumetric Terrain + Marching Cubes
Concept: store a density value (Weight) in 3D voxels instead of a single height.
Marching Cubes algorithm:
- Based on the density values at the 8 voxel corners, look up one of 15 (or more) predefined triangulation cases
- Produces a watertight triangle mesh
- Applications: CT scan visualization, digital humans, fluid simulation
Current state and outlook:
- Currently used mainly in voxel games such as Minecraft
- Challenges: LOD transitions, complex data management
- Potential: truly fully dynamic terrain (dig holes or excavate anywhere)
Terrain Material System
Texture Splatting
Basic approach:
- Splat Map: each channel represents the weight of one material
- Material properties: Base Color, Normal, Roughness, Metallic, Height
Height-Based Blending:
- Problem: alpha blending makes sand “float” on the rock surface, which looks unreal
- Solution: compare heights using the Height Map — the higher one is kept, the lower one fades out
- Effect: sand fills the cracks in the rock and grass grows out of them, rather than covering the rock
Reducing jitter:
- Add a Bias (offset, e.g. 0.2) and Smoothstep to avoid sharp boundaries when materials switch and flickering (aliasing) at a distance
Multi-Material Management: Texture Array
- Concept: stack multiple unrelated 2D textures and access them by Index (rather than the trilinear interpolation of a 3D Texture)
- Advantage: supports blending dozens of materials with no interpolation cost between layers
- Data organization: the Splat Map stores both the material Index and the blend weights
Enhancing Surface Detail
- Parallax Mapping:
- Simulates parallax via raymarching
- Produces a three-dimensional bump effect, though the geometric silhouette stays flat
- Displacement Mapping:
- Actually displaces vertices together with Tessellation
- Higher cost, and the trend of the future
Virtual Texture
Core idea: load only the textures in the region visible inside the view frustum, similar to virtual memory management in an operating system.
Workflow:
- Divide the large terrain into multi-level Tiles, forming a mipmap pyramid
- Physics Texture (physical texture / cache): stores only the currently visible Tiles
- Feedback/Indirection: map UVs to positions in the physical texture via a lookup table (Page Table)
- Asynchronous loading: an “apprentice” (thread/IO system) loads Tiles on demand from disk/memory and unloads invisible ones
Advantages:
- Memory: VRAM usage has a theoretical upper bound (a converging geometric series)
- Performance: material blending is precomputed (baked) at load time, so at runtime you sample a single texture directly, greatly reducing overdraw and texture sampling cost
Hardware acceleration:
- DirectStorage: disk → VRAM, transferred while still compressed and decompressed on the GPU
- DMA (Direct Memory Access): a PS5 technology; data goes straight from the SSD to VRAM, bypassing the CPU and memory bus
Floating Point Precision
Problem: when 32-bit floats represent a large-scale world (such as Earth to the Moon, or a large open world), the fractional part lacks precision (precision decreases as the value grows), causing distant objects to jitter.
Symptom: at 2-3 km out, where values reach tens of thousands, the fractional precision may exceed 1 cm, causing decals to z-fight with walls and objects to flicker.
Solution: Camera Relative Rendering
- Set the camera position as the origin (0,0,0)
- Subtract the camera position from all world coordinates to get relative coordinates
- This preserves the high-precision fractional part and eliminates jitter
Other approaches:
- Using Double (64-bit floats): too high a cost in data volume and bandwidth
- Sublevel relative coordinates: used by large engines such as UE5, where the coordinate system is reset for each Level
Environment Element Systems
Foliage Rendering
- SpeedTree: the industry-standard vegetation middleware
- LOD strategy:
- Near: real meshes
- Mid distance: combinations of cards
- Far: billboards
Decorator
- Definition: environment details such as small grass, pebbles, and small shrubs
- Techniques: simple meshes, clustered billboard rendering
Road System
- Spline: artists generate roads by dragging control points
- Erosion (carving): after a road is generated, the Height Field must be carved and flattened so that mountainous terrain is suitable for the road
Decal
- Definition: a detail texture projected onto a surface (e.g., bullet holes, stains, road markings)
- Application: combined with Virtual Texture and baked into the terrain texture
Procedural Generation
Trend: moving from manual editing to rule-based procedural generation.
Capabilities:
- Automatically generate vegetation based on slope, altitude, and material type (broadleaf forest → coniferous forest transition)
- Simulate water erosion to produce ridges and gullies
- Automatically generate road networks
Requirement: engine developers need some naturalist knowledge to understand geological and ecological laws.
Conclusion: The Technical Path to Becoming a “God of the Earth”
- Basics: master the Height Field and LOD principles
- Geometry: implement Quadtree + GPU Tessellation and handle T Junctions
- Materials: Texture Splatting + Virtual Texture
- Dynamics: GPU Driven Deformable Terrain
- Precision: Camera Relative Rendering to solve large-space problems
- Ecosystem: integrate the SpeedTree, Decorator, Road, and Decal systems
- Future: explore Volumetric Terrain and Marching Cubes