Authors: David Sommerfield and Nicholas Moen
This repository contains code and a paper detailing a method for simulating hydraulic erosion on heightmaps. It utilizes a GAN framework for training, while the core architecture is a high-performance CNN designed for realistic and efficient terrain generation. This approach is enables high speed terrain procedural terrain generation and real-time terrain authoring in artistic applications.
Note: the paper was just made for a university course, so it's less polished than a typical academic publication. See our presentation here: Google Slides Link.
- Architecture: Based on a modified pix2pix model, the framework incorporates encoder-decoder structures and a patch-based discriminator. The generator utilizes dilated convolution layers to capture long-range spatial patterns like sediment carry.
- Performance: This model performs signifigantly faster than traditional simulation (~192x faster than the simulation we used to generate the training data). On three Quadro RTX 6000/8000 GPUs, the model generates 32 terrain images in 0.1 seconds. Even a single GTX 1060 achieves this in 0.3 seconds, making it suitable for real-time applications.
- Data Generalization: Trained on a diverse set of procedurally generated heightmaps (e.g., Perlin noise), the model demonstrates adaptability by effectively simulating erosion on unseen data.
- Limitations: The model exhibits minor grid artifacts in the output terrain and can benefit from further refinements in detail generation.
The training data was created using a custom data acquisition pipeline, described in detail in the "Datasets" section of the final project report.
- Input Images: Generated using Perlin noise maps with adjustable parameters such as scale, noise level, amplitudes, and variances all distrubted according to a normal distribution. These parameters enabled the creation of diverse terrain characteristics and helped avoid artifacts resulting from sparse input.
- Output Images: Created by running the input DEMs through a hydraulic erosion algorithm.
To optimize the data for GAN-based architectures, images were encoded as 16-bit .tiff files, allowing parameter values to range from 0–65535 instead of the typical 0-255 (important for smooth height representation).
Encoding details:
- Red Channel: Height (the only value that differs between input and output).
- Green Channel: Rock hardness.
- Blue Channel: Erosion amount in simulation (constant per image).
- Encoder: Downsampling with dilated convolutions to capture both local and long-distance features.
- Decoder: Transposed convolutions and dilated layers to upsample and refine the output.
- Patch-based evaluation (patch size: 70×70) focuses on localized details for realistic texture reproduction.
- Loss Function: Mean Absolute Error (MAE) and LPIPS for realism and perceptual similarity.
- Augmentation: Random rotations to improve robustness across terrain orientations (not strictly necessary).
- Hardware: Trained on three Quadro RTX (6000/8000) GPUs over 200 epochs (21 hours).
- Create Conda Environment:
conda env create -f agbaes_env.yaml- Or if you want just make sure your dependencies match.
- Activate Environment:
conda activate agbaes_env- Configure Dataset Path:
- Change the
dataPathvariable intest/test_generator.py(line 83) andmodels/train.py(line 92).
To start training:
- Navigate to
modelsdirectory:
cd models- Run the training Script
python3 train.pyAfter training, run the testing script:
- Navigate to
testdirectory:
cd test- Run the test script:
python3 test_generator.pyThis will generate output images for evaluation.
You can modify the ErosionOnFileWith8_BitImages() function in test_generator.py to use your own images.
For further details, consult the provided paper or feel free to contact us.