|
Heightfield 1.0
|
Hydraulic erosion simulation on the GPU. More...
#include <gputerrainsimu.h>
Public Member Functions | |
| GPUHydraulicErosionParticle () | |
| Constructor. Initialize everthing to zero. | |
| ~GPUHydraulicErosionParticle () | |
| Destructor. Destroys OpenGl buffers and shader program. | |
| void | Init (const HeightField &hf) |
| Initialize the erosion engine from a heightfield. Must be called before any Step(). | |
| void | Step (int n) |
| Performs N step of hydraulic erosion on the underlying heightfield. | |
| void | SetUniforms (float inertia, float sedimentCapacity, float depositSpeed, float evaporateSpeed, float erodeSpeed, int maxLifetime, int erosionBrushRadius) |
| Set the uniforms in the shader. | |
| void | SetUniforms (float depositSpeed, float erosionSpeed, float evaporationSpeed, float randomSedimentation, float randomSedFreq, float randomSedAmp) |
| Set the uniforms in the shader. | |
| void | SetUniforms (float depositSpeed, float erosionSpeed, float evaporationSpeed, int erosionBrushRadius, int maxLifeTime) |
| Set the uniforms in the shader. | |
| void | SetGlobalSpeed (float globalSpeed) |
| Set the global erosion speed uniform which affects both erosion and deposition. | |
| void | SetHardnessAlpha (const ScalarField2 &hardness) |
| Set the hardness alpha map in a buffer. | |
| void | UseHardness (bool use=true) |
| Flag for using the hardness alpha map or not. | |
| void | SetHardnessFunction (int index) |
| Set the hardness function to use in the shader. See function GetHardness in the shader for more details. | |
| void | UsePrecipitation (bool use=true) |
| Flag for using the precipitation map or not. | |
| void | SetPrecipitation (const ScalarField2 &precipitation) |
| Set the precipitation map. | |
| void | GetData (ScalarField2 &hf) |
| Reads back newest bedrock and sediment elevation from the GPU, into initialized scalarfields. | |
| void | GetData (ScalarField2 &bedrock, ScalarField2 &sediments) |
| Reads back newest bedrock and sediment elevation from the GPU, into initialized scalarfields. The sediment scalarfield is normalized. | |
| void | GetDataHardness (ScalarField2 &hardness) |
| Get hardness data back from the GPU and store it in a scalar field. | |
Protected Attributes | |
| GLShader | simulationShader |
| Compute shader. | |
| GLBuffer | bedrockBuffer |
| Bedrock buffer. | |
| GLBuffer | sedimentBuffer |
| Sediment buffer. | |
| GLBuffer | randomIndicesBuffer |
| Random number buffer. Easier than generating random number on the GPU. | |
| GLBuffer | brushIndicesBuffer |
| Compute buffer. | |
| GLBuffer | brushWeightsBuffer |
| Compute buffer. | |
| GLOptionalStorageBuffer | hardnessBuffer |
| Optional Hardness buffer. | |
| GLBuffer | outHardnessBuffer |
| Output hardness buffer (useful if we use the GPU function to generate hardness on the fly) | |
| GLOptionalStorageBuffer | precipitationBuffer |
| Precipitation buffer. | |
| int | totalBufferSize |
| Total buffer size defined as nx * ny. | |
| int | dispatchSize |
| Single dispatch size. | |
| int | nx |
| Heightfield dimension. | |
| int | ny |
| Heightfield dimension. | |
| double | scaleZa |
| Heightfield min elevation. | |
| double | scaleZb |
| Heightfield max elevation. | |
| std::vector< int > | randomIndices |
| Random indices for the algorithm. | |
| std::vector< float > | tmpData |
| Temporary array for retreiving GPU data. | |
Hydraulic erosion simulation on the GPU.
The algorithm uses a particle-based approach all simulated independently on the terrain.
The implementation is based on https://github.com/SebLague/Hydraulic-Erosion It has a race condition: multiple threads can be writing to the elevation buffer at the same time, Thus making some operations not taken into account. The original shader suffers from the same issue.
AXEL : this doesn't work anymore, have to figure it out. Weird buffer issue ?
| void GPUHydraulicErosionParticle::GetDataHardness | ( | ScalarField2 & | hardness | ) |
Get hardness data back from the GPU and store it in a scalar field.
| hardness | the returned hardness data |
| void GPUHydraulicErosionParticle::Init | ( | const HeightField & | hf | ) |
Initialize the erosion engine from a heightfield. Must be called before any Step().
| hf | heightfield |
| void GPUHydraulicErosionParticle::SetGlobalSpeed | ( | float | globalSpeed | ) |
Set the global erosion speed uniform which affects both erosion and deposition.
| globalSpeed | speed, should be between [0, 1] |
| void GPUHydraulicErosionParticle::SetHardnessAlpha | ( | const ScalarField2 & | hardness | ) |
Set the hardness alpha map in a buffer.
| hardness | hardness alpja. |
| void GPUHydraulicErosionParticle::SetHardnessFunction | ( | int | index | ) |
Set the hardness function to use in the shader. See function GetHardness in the shader for more details.
| index | 0 = Simple strata 1 = Warped strata 2 = 3D noise 3 = Faulting The hardness function can be combined with an alpha map |
| void GPUHydraulicErosionParticle::SetPrecipitation | ( | const ScalarField2 & | precipitation | ) |
Set the precipitation map.
| precipitation | the map |
| void GPUHydraulicErosionParticle::SetUniforms | ( | float | depositSpeed, |
| float | erosionSpeed, | ||
| float | evaporationSpeed, | ||
| float | randomSedimentation, | ||
| float | randomSedFreq, | ||
| float | randomSedAmp ) |
Set the uniforms in the shader.
| depositSpeed | |
| erosionSpeed | |
| evaporationSpeed | |
| randomSedimentation | |
| randomSedFreq | |
| randomSedAmp |
| void GPUHydraulicErosionParticle::SetUniforms | ( | float | depositSpeed, |
| float | erosionSpeed, | ||
| float | evaporationSpeed, | ||
| int | erosionBrushRadius, | ||
| int | maxLifeTime ) |
Set the uniforms in the shader.
| depositSpeed | |
| erosionSpeed | |
| evaporationSpeed | |
| erosionBrushRadius | |
| maxLifeTime |
| void GPUHydraulicErosionParticle::SetUniforms | ( | float | inertia, |
| float | sedimentCapacity, | ||
| float | depositSpeed, | ||
| float | evaporateSpeed, | ||
| float | erodeSpeed, | ||
| int | maxLifetime, | ||
| int | erosionBrushRadius ) |
Set the uniforms in the shader.
| inertia | |
| sedimentCapacity | |
| depositSpeed | |
| evaporateSpeed | |
| erodeSpeed | |
| maxLifetime | |
| erosionBrushRadius |
| void GPUHydraulicErosionParticle::Step | ( | int | n | ) |
Performs N step of hydraulic erosion on the underlying heightfield.
| n | step count |
| void GPUHydraulicErosionParticle::UseHardness | ( | bool | use = true | ) |
Flag for using the hardness alpha map or not.
| use |
| void GPUHydraulicErosionParticle::UsePrecipitation | ( | bool | use = true | ) |
Flag for using the precipitation map or not.
| use |