Skip to main content

Overview

The Aurora terrain system provides tessellated terrain surfaces that can be generated procedurally using noise algorithms or loaded from heightmap images. Terrains support multiple biomes with custom textures, colors, and environmental parameters.

Creating a Terrain

Procedural Generation

Create terrain using built-in generators:
#include "aurora/terrain.h"
#include "aurora/procedural.h"

// Create terrain with a hill generator
Terrain terrain(HillGenerator());
terrain.width = 512;
terrain.height = 512;
terrain.initialize();
terrain.addBiome(Biome("Snow", Color::white()));
window.addObject(&terrain);

From Heightmap

Load terrain from an image file:
Resource heightmapResource = Workspace::get().createResource(
    "terrain_height.png", "TerrainHeight", ResourceType::Image);

Terrain terrain(heightmapResource);
terrain.initialize();
window.addObject(&terrain);

Biome System

Biomes define visual and environmental parameters for terrain regions based on height, moisture, and temperature thresholds.

Basic Biome

Biome grassland("Grassland", Color(0.3, 0.6, 0.2, 1.0));
grassland.minHeight = 0.0f;
grassland.maxHeight = 20.0f;
terrain.addBiome(grassland);

Textured Biome

Biome desert("Desert");
desert.minHeight = 0.0f;
desert.maxHeight = 15.0f;
desert.minMoisture = 0.0f;
desert.maxMoisture = 0.3f;
desert.condition = [](Biome &b) {
    b.attachTexture(Texture::fromResourceName("Sand"));
};
terrain.addBiome(desert);

Biome Parameters

name
std::string
Human-readable name for identification
color
Color
Fallback tint applied when no texture is used
texture
Texture
Texture applied when useTexture is enabled
minHeight
float
default:"-1.0f"
Minimum height threshold for biome appearance
maxHeight
float
default:"-1.0f"
Maximum height threshold for biome appearance
minMoisture
float
default:"-1.0f"
Minimum moisture value required
maxMoisture
float
default:"-1.0f"
Maximum moisture value allowed
minTemperature
float
default:"-1.0f"
Minimum temperature threshold
maxTemperature
float
default:"-1.0f"
Maximum temperature threshold

Terrain Properties

width
int
Number of vertices along the X axis
height
int
Number of vertices along the Z axis
resolution
unsigned int
default:"20"
LOD resolution multiplier controlling tessellation density
maxPeak
float
default:"48.0f"
Maximum elevation (in world units) used when normalizing heights
seaLevel
float
default:"16.0f"
Elevation at which water begins to cover the terrain
position
Position3d
Terrain origin relative to world space
rotation
Rotation3d
Euler rotation applied to the terrain
scale
Scale3d
default:"{1.0, 1.0, 1.0}"
Scale applied across each axis

Methods

initialize()

Builds buffers, materials, and generator data:
void initialize() override;

addBiome()

Registers a biome definition for map generation:
void addBiome(const Biome &biome);

Transform Methods

// Set absolute position
void setPosition(const Position3d &newPosition);

// Translate by delta
void move(const Position3d &deltaPosition);

// Set rotation
void setRotation(const Rotation3d &newRotation);

// Rotate incrementally
void rotate(const Rotation3d &deltaRotation);

// Set scale
void setScale(const Scale3d &newScale);

// Scale relative to current size
void scaleBy(const Scale3d &deltaScale);

Slope Calculation

Compute slope factors for heightmap analysis:
float slope = aurora::computeSlope(heightMap, width, height, x, y);
heightMap
const uint8_t*
Pointer to height data
width
int
Width of the heightmap
height
int
Height of the heightmap
x
int
Sample X coordinate
y
int
Sample Y coordinate
return
float
Gradient magnitude representing slope steepness

Advanced Textures

// Procedurally generated moisture and temperature data
terrain.moistureTexture = /* custom texture */;
terrain.temperatureTexture = /* custom texture */;

Example: Multi-Biome Terrain

// Create terrain with mountain generator
MountainGenerator mountains(10.0f, 100.0f, 6, 0.5f);
Terrain terrain(mountains, 1024, 1024);

// Snow peaks
Biome snow("Snow", Color::white());
snow.minHeight = 80.0f;
terrain.addBiome(snow);

// Mountain rock
Biome rock("Rock", Color(0.5, 0.5, 0.5));
rock.minHeight = 40.0f;
rock.maxHeight = 80.0f;
terrain.addBiome(rock);

// Grassland
Biome grass("Grass", Color(0.3, 0.7, 0.2));
grass.minHeight = 10.0f;
grass.maxHeight = 40.0f;
terrain.addBiome(grass);

// Beach
Biome sand("Sand", Color(0.9, 0.8, 0.6));
sand.minHeight = 0.0f;
sand.maxHeight = 10.0f;
terrain.addBiome(sand);

terrain.maxPeak = 120.0f;
terrain.seaLevel = 5.0f;
terrain.initialize();
window.addObject(&terrain);
Terrains are rendered using forward rendering regardless of the window’s deferred rendering setting.

See Also

Build docs developers (and LLMs) love