Procedural Terrain Carving Systems: Rivers, Lakes, Hydraulic Erosion, and Local Hydrology Simulation

The Core Concept: Geological Carving

In advanced terrain systems, rivers and lakes are not manually placed objects but dynamically carved formations. This means the terrain itself is modified to simulate water flow rather than simply overlaying a water surface.

A river is constructed as a continuous sequence of modified points in the height buffer. To avoid unnatural segmentation, interpolation methods such as linear interpolation or spline-based smoothing are used between successive brush positions. This ensures that the carved path remains continuous and visually organic rather than appearing as disconnected deformation points.

Unlike rivers, lakes operate as basin systems. Instead of following a directional slope, a lake brush enforces a target elevation within a defined radius. This flattens the terrain inside the affected region while preserving natural transitions at the boundary, effectively creating a concave basin that mimics natural water accumulation.


https://www.udemy.com/course/web-based-3d-terrain-industrial-printing-engine-mastery/


River Pathing and Terrain Interpolation

River systems depend heavily on directional continuity. Each brush stroke represents a point along a flow path, and the system must interpolate between these points to maintain smooth carving behavior.

Without interpolation, river paths would appear as dotted or segmented lines. By applying interpolation techniques, the system ensures that terrain deformation transitions smoothly between input points, producing a continuous channel.

This process effectively converts discrete user input into a continuous geometric modification function applied to the height buffer.


Lake Basin Formation and Flat Region Control

Lake creation operates on a fundamentally different principle than river carving. Instead of directional erosion, the system enforces a uniform target altitude within a circular influence zone.

Vertices within this zone are adjusted toward a single height value, creating a flat water floor. At the same time, boundary vertices are softened to ensure a gradual transition between lake and surrounding terrain.

This produces a physically plausible basin structure that behaves like a natural depression where water would accumulate.


Trainee Assignments: Technical Implementation

Task 1: Smart River Brush System

The existing mode_lower tool must be extended into a dedicated river carving system.

Instead of only lowering vertex heights, the river brush must also apply a secondary smoothing operation along its edges. This combination ensures that the carved channel does not have sharp boundaries and behaves more like natural erosion.

This requires combining two operations:

  • Height depression along the brush center
  • Gradient smoothing along the brush perimeter

The result is a hybrid deformation system that simulates both excavation and natural erosion simultaneously.


Task 2: Global State Stack with Environmental Data

With multiple terrain systems active (rivers, lakes, ocean levels), undo functionality must extend beyond geometry alone.

A HistoryManager class must be implemented to store:

  • Height buffer state
  • Sea level value
  • Topographic scale factor

This ensures that when a user performs an undo operation, the entire simulation environment is restored to a consistent previous state. Without this, visual and physical inconsistencies would occur between terrain and water systems.


Assessment Questions: System Architecture

Question 1: Hydraulic Erosion Logic

To simulate water flow, each vertex must be compared with its surrounding neighbors. The direction of water movement is determined by identifying the steepest downward gradient among adjacent vertices.

By analyzing the difference in height between a vertex and its eight neighbors, the system can determine the direction of flow. Sediment is then transferred from higher elevation points to lower ones, simulating natural erosion processes.

This creates a directional flow model that mimics real hydraulic behavior.


Question 2: GPU vs CPU Bottlenecks

Processing a 1024 × 1024 heightmap involves over one million vertices. Performing this computation on the CPU (JavaScript) introduces significant performance limitations due to:

  • Single-threaded execution
  • Memory bandwidth constraints
  • Inefficient large-array iteration

In contrast, the GPU processes vertex data in parallel using vertex shaders, allowing simultaneous computation across thousands of threads. This makes it vastly more efficient for large-scale terrain transformations.


Question 3: Manifold Constraints in 3D Printing

When exporting terrain as STL, the geometry must remain watertight (manifold). If a river carving operation creates holes that penetrate the base layer, the mesh becomes non-manifold and cannot be correctly processed by slicing software.

To prevent this, the system must enforce a minimum terrain floor level. Any carving operation is clamped so that it cannot go below this base threshold, ensuring structural integrity for 3D printing workflows.


Final Challenge: Local Hydrology Plane System

Concept Overview

The goal is to create a localized water system where lakes are generated dynamically only within carved regions, rather than applying a global ocean plane.

This requires generating a separate mesh that represents water only inside a detected depression area.


Defining Lake Boundaries

To prevent water from leaking into unintended regions, the system must calculate precise boundaries based on terrain morphology.

Instead of fixed geometry, lake bounds should be derived from:

  • Carved depression footprint
  • Contiguous low-elevation regions
  • Gradient threshold detection

This ensures that only fully enclosed or sufficiently depressed areas are filled with water.


Implementation Strategy

A local hydrology plane can be constructed by:

  • Detecting connected low-height regions after carving
  • Generating a secondary mesh that conforms to these boundaries
  • Clamping water surface to the average basin height

This produces isolated water bodies that respond dynamically to terrain changes.


Final Insight

Procedural terrain carving evolves from simple height manipulation into a full geological simulation system when rivers, lakes, and erosion are combined. By integrating interpolation, gradient analysis, and environmental state tracking, the engine becomes capable of simulating coherent hydrological systems where terrain and water continuously reshape each other in real time.