Heightfield 1.0
GPUStreamPowerOptimized Class Reference

Stream power erosion simulation on the GPU. More...

#include <gputerrainsimu.h>

Public Member Functions

 GPUStreamPowerOptimized ()
 Default constructor.
 ~GPUStreamPowerOptimized ()
 Destructor. Destroys the OpenGl buffers and shader program.
void Init (const HeightField &)
 Init function, must be called if the underlying heightfield changed.
void Step (int n)
 Simulate n step of stream power erosion.
void Step (int, const Vector2 &, double)
 Simulate n step of stream power erosion in a circular domain.
void SetUniforms (int erosionMode, float uplift, float k, float p_sa, float p_sl, float k_h, float k_d)
 Set the uniforms for the shader.
void SetDt (float dt) const
 Set the delta time for a simulation step.
void SetKParameter (ScalarField2 kParam)
 Set the map for the parameter 'k' (erosion strength) of the stream power erosion.
void UseKParameter (bool use=true)
 Flag for using the 'k' map or not.
void SetMParameter (ScalarField2 mParam)
 Set the map for the parameter 'm' (stream area exponent) of the stream power erosion.
void UseMParameter (bool use=true)
 Flag for using the 'm' map or not.
void SetNParameter (ScalarField2 nParam)
 Set the map for the parameter 'n' (slope exponent) of the stream power erosion.
void UseNParameter (bool use=true)
 Flag for using the 'n' map or not.
void SetLaplacianParameter (ScalarField2 laplacianParam)
 Set the map for the laplacian parameter 'l' of the stream power erosion.
void UseLaplacianParameter (bool use=true)
 Flag for using the 'laplacian' map or not.
void SetFlowMode (int flowMode)
 Set the flow mode. 0 = steepest, 1 = L-p with p the flow exponent.
void SetFlowExponent (float flow_p)
 Set the flow distribution exponent (only used if flowMode == 1). Using flow_p = 1 is equivalent to L-1, and flow_p = 2 is equivalent to L-2.
void SetUplift (const ScalarField2 &uplift)
 Set the uplift map.
void UseUplift (bool use=true)
 Flag for using the uplift map or not.
void SetBoundary (Array2I boundary)
 Set the boundary flag map. The array must be of the same size as the base heightfield.
void SetRetargeting (ScalarField2 retargetAlpha)
 Set the retargeting alpha map.
void UseRetargeting (bool use=true)
 Flag for using the retargeting alpha map or not.
void UseHardness (bool use=true)
 Flag for using the hardness function or not.
void SetHardnessFunc (int hardnessFunc)
 Flag for setting the hardness function index.
void UseDynamicHardness (bool use=true)
 Flag for using the dynamic, time-evolving hardness. Note that the simulation cannot converge if dynamic hardness is activated.
GLuint GetData () const
 Returns the OpenGL latest elevation buffer.
void GetData (ScalarField2 &)
 Reads back newest bedrock elevation from the GPU, into initialized scalarfields.
void GetData (ScalarField2 &, ScalarField2 &)
 Reads back newest bedrock elevation and stream area from the GPU, into initialized scalarfields.
void GetData (ScalarField2 &, ScalarField2 &, ScalarField2 &)
 Reads back newest bedrock elevation, stream area and hardness from the GPU, into initialized scalarfields.
void GetHardness (ScalarField2 &)
 Reads back newest hardness from the GPU, into initialized scalarfields.
double GetLastStepElevationDifference ()
 Computes the total difference of elevation for the last simulation step. Useful for knowing if the simulation has reached steady-state.

Protected Attributes

GLShader simulationShader
 Compute shader.
GLBuffer bedrockBuffer
 Bedrock elevation buffer.
GLBuffer outBedrockBuffer
 Output bedrock elevation buffer.
GLBuffer streamBuffer
 Water elevation buffer.
GLBuffer outStreamBuffer
 Output water elevation buffer.
GLBuffer outHardnessBuffer
 Output hardness buffer (to read back from the GPU).
GLOptionalStorageBuffer upliftBuffer
 Optional uplift buffer.
GLOptionalStorageBuffer boundaryBuffer
 Optional boundary buffer.
GLOptionalStorageBuffer mParamBuffer
 Optional exponent map buffer.
GLOptionalStorageBuffer nParamBuffer
 Optional exponent map buffer.
GLOptionalStorageBuffer kParamBuffer
 Optional erosion factor map buffer.
GLOptionalStorageBuffer retargetBuffer
 Optional retargeting alpha buffer.
GLOptionalStorageBuffer laplacianBuffer
 Optional laplacian factor buffer.
bool dynamicHardness
 Flag for dynamic hardness.
int totalBufferSize
 Total buffer size defined as nx * ny.
int dispatchSize
 Single dispatch size.
std::vector< float > tmpData
 Temporary array for retreiving GPU data.

Detailed Description

Stream power erosion simulation on the GPU.

Constructor & Destructor Documentation

◆ GPUStreamPowerOptimized()

GPUStreamPowerOptimized::GPUStreamPowerOptimized ( )

Default constructor.

Does not call OpenGL because context might not have been initialized yet.

Member Function Documentation

◆ Init()

void GPUStreamPowerOptimized::Init ( const HeightField & hf)

Init function, must be called if the underlying heightfield changed.

Initialize a default stream area buffer to zero and send it to the GPU.

OpenGL buffers are also initialized (just once) here.

◆ SetBoundary()

void GPUStreamPowerOptimized::SetBoundary ( Array2I boundary)

Set the boundary flag map. The array must be of the same size as the base heightfield.

Parameters
boundaryboundary map

◆ SetDt()

void GPUStreamPowerOptimized::SetDt ( float dt) const

Set the delta time for a simulation step.

Parameters
dtdelta time

◆ SetFlowExponent()

void GPUStreamPowerOptimized::SetFlowExponent ( float flow_p)

Set the flow distribution exponent (only used if flowMode == 1). Using flow_p = 1 is equivalent to L-1, and flow_p = 2 is equivalent to L-2.

Parameters
flow_pexponent

◆ SetFlowMode()

void GPUStreamPowerOptimized::SetFlowMode ( int flowMode)

Set the flow mode. 0 = steepest, 1 = L-p with p the flow exponent.

Parameters
flowModeflow mode index

◆ SetHardnessFunc()

void GPUStreamPowerOptimized::SetHardnessFunc ( int hardnessFunc)

Flag for setting the hardness function index.

Parameters
hardnessFunchardness function index on the GPU

◆ SetKParameter()

void GPUStreamPowerOptimized::SetKParameter ( ScalarField2 kParam)

Set the map for the parameter 'k' (erosion strength) of the stream power erosion.

Parameters
kParammap

◆ SetLaplacianParameter()

void GPUStreamPowerOptimized::SetLaplacianParameter ( ScalarField2 laplacianParam)

Set the map for the laplacian parameter 'l' of the stream power erosion.

Parameters
laplacianParamMap of the Laplacian parameter, resampled to the resolution of the simulation if needed.

◆ SetMParameter()

void GPUStreamPowerOptimized::SetMParameter ( ScalarField2 mParam)

Set the map for the parameter 'm' (stream area exponent) of the stream power erosion.

Parameters
mParammap

◆ SetNParameter()

void GPUStreamPowerOptimized::SetNParameter ( ScalarField2 nParam)

Set the map for the parameter 'n' (slope exponent) of the stream power erosion.

Parameters
nParamMap of the slope exponent, resampled to the resolution of the simulation if needed.

◆ SetRetargeting()

void GPUStreamPowerOptimized::SetRetargeting ( ScalarField2 retargetAlpha)

Set the retargeting alpha map.

Parameters
retargetAlpharetargeting map

◆ SetUniforms()

void GPUStreamPowerOptimized::SetUniforms ( int erosionMode,
float uplift,
float k,
float p_sa,
float p_sl,
float k_h,
float k_d )

Set the uniforms for the shader.

Parameters
erosionMode0 is stream power only, 1 is stream power + hillslope, 2 is stream power + hillslope + debris slope.
upliftuplift factor. Default is 0.0001
k'downlift' factor as in the stream power equation. Default is 0.05
p_sastream area exponent for the stream power equation. Default is 0.8
p_slslope exponent for the stream power equation. Default is 2.0
k_hhillslope erosion strength (for erosion mode 1/2)
k_ddebris slope erosion strength (for erosion mode 2)

◆ SetUplift()

void GPUStreamPowerOptimized::SetUplift ( const ScalarField2 & uplift)

Set the uplift map.

Parameters
upliftuplift map

◆ Step() [1/2]

void GPUStreamPowerOptimized::Step ( int n)

Simulate n step of stream power erosion.

This function doesn't get any data back on the CPU.

Parameters
nnumber of step

◆ Step() [2/2]

void GPUStreamPowerOptimized::Step ( int n,
const Vector2 & c,
double r )

Simulate n step of stream power erosion in a circular domain.

This function doesn't get any data back on the CPU.

Parameters
nnumber of step
ccenter of the domain
rradius of the domain

◆ UseDynamicHardness()

void GPUStreamPowerOptimized::UseDynamicHardness ( bool use = true)

Flag for using the dynamic, time-evolving hardness. Note that the simulation cannot converge if dynamic hardness is activated.

Parameters
use

◆ UseHardness()

void GPUStreamPowerOptimized::UseHardness ( bool use = true)

Flag for using the hardness function or not.

Parameters
use

◆ UseKParameter()

void GPUStreamPowerOptimized::UseKParameter ( bool use = true)

Flag for using the 'k' map or not.

Parameters
use

◆ UseLaplacianParameter()

void GPUStreamPowerOptimized::UseLaplacianParameter ( bool use = true)

Flag for using the 'laplacian' map or not.

Parameters
use

◆ UseMParameter()

void GPUStreamPowerOptimized::UseMParameter ( bool use = true)

Flag for using the 'm' map or not.

Parameters
use

◆ UseNParameter()

void GPUStreamPowerOptimized::UseNParameter ( bool use = true)

Flag for using the 'n' map or not.

Parameters
use

◆ UseRetargeting()

void GPUStreamPowerOptimized::UseRetargeting ( bool use = true)

Flag for using the retargeting alpha map or not.

Parameters
use

◆ UseUplift()

void GPUStreamPowerOptimized::UseUplift ( bool use = true)

Flag for using the uplift map or not.

Parameters
use