Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Terrain Class Reference

Generate a terrain with Perlin noise and erosion. Represent the terrain, regrouping elevation and shadow data and the underlying GPU representation to render it. More...

#include <Terrain.hpp>

Classes

struct  Cell
 
struct  ErosionSettings
 
struct  GenerationSettings
 
struct  MeshSettings
 

Public Member Functions

 Terrain (uint resolution, uint seed)
 
void generateMesh ()
 
void generateMap ()
 
void generateShadowMap (const glm::vec3 &lightDir)
 
bool interface ()
 
 ~Terrain ()
 
float texelSize () const
 
int gridSize () const
 
float meshSize () const
 
const Texturemap () const
 
const TextureshadowMap () const
 
const std::vector< Cell > & cells () const
 

Private Member Functions

void erode (Image &img)
 
void transferAndUpdateMap (Image &heightMap)
 

Private Attributes

PerlinNoise _perlin
 Perlin noise generator.
 
std::vector< Cell_cells
 Grid mesh cells.
 
Texture _map = Texture("Terrain")
 Terrain map, height in R channel, normals in GBA channels.
 
Texture _mapLowRes = Texture("Terrain low-res")
 Low resolution min-height terrain map.
 
Texture _shadowMap
 Shadow map generation texture.
 
GaussianBlur _gaussBlur
 Gaussian blur.
 
GenerationSettings _genOpts
 Terrain generations settings.
 
MeshSettings _mshOpts
 Grid mesh options.
 
ErosionSettings _erOpts
 Erosion options.
 
int _resolution
 Height map resolution.
 
uint _seed
 Current generation seed.
 
float _texelSize = 0.05f
 Size of a map texel in world space.
 
float _meshSize = 0.0f
 Size of the mesh.
 

Detailed Description

Generate a terrain with Perlin noise and erosion. Represent the terrain, regrouping elevation and shadow data and the underlying GPU representation to render it.

Constructor & Destructor Documentation

◆ Terrain()

Terrain::Terrain ( uint  resolution,
uint  seed 
)

Constructor

Parameters
resolutionthe terrain map resolution
seedthe random seed for terrain generation

◆ ~Terrain()

Terrain::~Terrain ( )

Destructor.

Member Function Documentation

◆ cells()

const std::vector< Cell > & Terrain::cells ( ) const
inline
Returns
the grid mesh cells.

◆ erode()

void Terrain::erode ( Image img)
private

Apply erosion on a height map.

Parameters
imgthe map to erode, in place

◆ generateMap()

void Terrain::generateMap ( )

Generate the terrain map for the current seed.

◆ generateMesh()

void Terrain::generateMesh ( )

Generate the grid mesh.

◆ generateShadowMap()

void Terrain::generateShadowMap ( const glm::vec3 &  lightDir)

Generate the shadow map for the current terrain and a sun direction.

Parameters
lightDirthe sun direction

◆ gridSize()

int Terrain::gridSize ( ) const
inline
Returns
the size of the grid.

◆ interface()

bool Terrain::interface ( )

Display terrain options in GUI, in a currently opened window.

Returns
true if any option was modified

◆ map()

const Texture & Terrain::map ( ) const
inline
Returns
the terrain height and normal map.

◆ meshSize()

float Terrain::meshSize ( ) const
inline
Returns
the size of the grid in world space.

◆ shadowMap()

const Texture & Terrain::shadowMap ( ) const
inline
Returns
the terrain shadow map, with self shadowing in the R channel and ocean plane shadowing in the G channel.

◆ texelSize()

float Terrain::texelSize ( ) const
inline
Returns
the size of a terrain map pixel in world space.

◆ transferAndUpdateMap()

void Terrain::transferAndUpdateMap ( Image heightMap)
private

Compute terrain normals from height and uplaod the result to the GPU, with custom mip-map and low-res version.

Parameters
heightMapthe map to update and upload

The documentation for this class was generated from the following files: