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
Human-readable name for identification
Fallback tint applied when no texture is used
Texture applied when useTexture is enabled
Minimum height threshold for biome appearance
Maximum height threshold for biome appearance
Minimum moisture value required
Maximum moisture value allowed
Minimum temperature threshold
Maximum temperature threshold
Terrain Properties
Number of vertices along the X axis
Number of vertices along the Z axis
LOD resolution multiplier controlling tessellation density
Maximum elevation (in world units) used when normalizing heights
Elevation at which water begins to cover the terrain
Terrain origin relative to world space
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);
// 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);
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