Heightfield 1.0
GPUHeightFieldAnalysis Class Reference

Parallelized heightfield analysis. More...

#include <gputerrainsimu.h>

Public Member Functions

 GPUHeightFieldAnalysis ()
 Constructor.
 
 ~GPUHeightFieldAnalysis ()
 Destroys OpenGl buffers and shader program.
 
ScalarField2 FractionalLaplacian (const HeightField &, int, double)
 Compute the fractional Laplacian.
 
ScalarField2 Laplacian (const HeightField &)
 Computes the Laplacian of the heightfield in double precision on the GPU.
 
void FractionalGradient (const HeightField &, double, int, VectorField2 &, ScalarField2 &)
 Compute fractional gradient and fractional gradient norm fields.
 
void Gradient (const HeightField &, VectorField2 &, ScalarField2 &)
 Computes the gradient vector field and gradient norm scalar field of a given heightfield.
 
ScalarField2 Accessibility (const HeightField &, const double &, int, int=2256)
 Compute accessibility.
 
ScalarField2 ClearSky (const HeightField &, double, int, int=2256)
 Clear sky.
 
ScalarField2 Shadow (const HeightField &, const Vector &, int=2256)
 Compute shadows.
 
ScalarField2 SoftShadows (const HeightField &, const Vector &, double, int=2256)
 Compute soft shadows. The code is the same as the SmoothShadow() function in LibMaya/Shaders/heightfield_raytrace.glsl file.
 
ScalarField2 Diffuse (const HeightField &, const Vector &, double)
 Compute diffuse shading.
 
int CountPits (const HeightField &)
 Compute the amount of pits in a given GPU heightfield.
 
int CountPits (GLuint hfBuffer, int nx, int ny)
 Compute the amount of pits in a given GPU heightfield buffer with single precision. Results may differ from a CPU computation to the floating-point precision.
 
Vector2 GetRange (const HeightField &)
 Computes the range of a heightfield on the GPU.
 
Vector2 GetRange (GLuint hfBuffer, int nx, int ny)
 Computes the range of a heightfield given an already initialized GPU heightfield buffer.
 
ScalarField2 Visibility (const HeightField &, const Vector &, int=2256)
 Computes the visibility of the sun on the terrain.
 

Protected Member Functions

void Init (int nx, int ny)
 Init function, used in the context of an already existing GPU buffer from the QOpenGL widget.
 
void InitForSingleBuffer (const HeightField &)
 Init function from a given heightfield.
 
void InitForDoubleBuffer (const HeightField &)
 Init function from a given heightfield.
 
void InitForTexture (const HeightField &)
 Init function from a given heightfield.
 
double C (int, const double &) const
 Not used in the class, but here as a reminder for the fractional gradient computation.
 
ScalarField2 GetDataToScalarField () const
 Get float buffer data from the GPU and convert it to the ScalarField2 double format.
 

Protected Attributes

GLShader shader
 Glsl program.
 
GLuint hfTextureBuffer = 0
 Heightfield texture.
 
GLBuffer inHfBuffer
 Heightfield buffer, used by CountPits(), with single precision.
 
GLBuffer inHfBufferDouble
 Heightfield buffer, with double precision.
 
GLBuffer outBuffer
 Output scalar buffer.
 
GLBuffer outVecBuffer
 Output 2D vector buffer.
 
GLBuffer outIntBuffer
 Output integer buffer.
 
GLBuffer outDoubleBuffer
 Output double buffer.
 

Detailed Description

Parallelized heightfield analysis.

Constructor & Destructor Documentation

◆ GPUHeightFieldAnalysis()

GPUHeightFieldAnalysis::GPUHeightFieldAnalysis ( )

Constructor.

Initialize everthing to zero.

Member Function Documentation

◆ Accessibility()

ScalarField2 GPUHeightFieldAnalysis::Accessibility ( const HeightField & hf,
const double & r,
int n,
int maxSteps = 2256 )

Compute accessibility.

See also
HeightField::Accessbility
Parameters
hfHeightfield
rRadius.
nNumber of rays.
maxStepsNumber of maximum steps for sphere tracing

◆ ClearSky()

ScalarField2 GPUHeightFieldAnalysis::ClearSky ( const HeightField & hf,
double r,
int n,
int maxSteps = 2256 )

Clear sky.

Parameters
hfHeightfield.
rmaximum distance along a ray.
nNumber of samples per cell.
maxStepsNumber of maximum steps for sphere tracing

◆ CountPits() [1/2]

int GPUHeightFieldAnalysis::CountPits ( const HeightField & hf)

Compute the amount of pits in a given GPU heightfield.

This function uses a double precision buffer, so the results should be equivalent to a CPU computation.

Parameters
hfHeightfield.

◆ CountPits() [2/2]

int GPUHeightFieldAnalysis::CountPits ( GLuint hfBuffer,
int nx,
int ny )

Compute the amount of pits in a given GPU heightfield buffer with single precision. Results may differ from a CPU computation to the floating-point precision.

Parameters
hfBufferHeightfield single precision gpu buffer, should already be initialized.
nx,nyHeightfield resolution.

◆ Diffuse()

ScalarField2 GPUHeightFieldAnalysis::Diffuse ( const HeightField & hf,
const Vector & l,
double s )

Compute diffuse shading.

Parameters
hfHeightfield.
lLight direction, should be normalized
sShadow strength

◆ FractionalGradient()

void GPUHeightFieldAnalysis::FractionalGradient ( const HeightField & hf,
double s,
int m,
VectorField2 & grad,
ScalarField2 & gradNorm )

Compute fractional gradient and fractional gradient norm fields.

Parameters
hfheightfield
sFractional parameter, should be in [0,1].
mmask size
gradreturned fractional gradient field
gradNormreturned fractional gradient norm

◆ FractionalLaplacian()

ScalarField2 GPUHeightFieldAnalysis::FractionalLaplacian ( const HeightField & hf,
int m,
double s )

Compute the fractional Laplacian.

Parameters
hfHeightfield
mMask size
sFractional parameter, should be in [0,1].

◆ GetRange() [1/2]

Vector2 GPUHeightFieldAnalysis::GetRange ( const HeightField & hf)

Computes the range of a heightfield on the GPU.

Parameters
hfthe HeightField

◆ GetRange() [2/2]

Vector2 GPUHeightFieldAnalysis::GetRange ( GLuint hfBuffer,
int nx,
int ny )

Computes the range of a heightfield given an already initialized GPU heightfield buffer.

The architecture is not the most efficient, but it avoids the need to get the data back on the CPU for computing the elevation range, which is slow for large heightfields.

Parameters
hfBufferHeightfield gpu buffer, should be initialized.
nx,nyHeightfield dimensions.

◆ Gradient()

void GPUHeightFieldAnalysis::Gradient ( const HeightField & hf,
VectorField2 & grad,
ScalarField2 & gradNorm )

Computes the gradient vector field and gradient norm scalar field of a given heightfield.

Parameters
hfthe heightfield
gradreturned gradient vector field
gradNormreturned gardient norm scalar field

◆ Init()

void GPUHeightFieldAnalysis::Init ( int nx,
int ny )
protected

Init function, used in the context of an already existing GPU buffer from the QOpenGL widget.

Parameters
nx,nyHeightfield dimensions, should match the size of the GPU buffer.

◆ InitForDoubleBuffer()

void GPUHeightFieldAnalysis::InitForDoubleBuffer ( const HeightField & hf)
protected

Init function from a given heightfield.

Initialize a double precision GPU buffer.

Parameters
hfHeightfield

◆ InitForSingleBuffer()

void GPUHeightFieldAnalysis::InitForSingleBuffer ( const HeightField & hf)
protected

Init function from a given heightfield.

Initialize a single precision GPU buffer (and not a texture).

This function is useful when the single precision is not an issue for the calling function. It also allows for a simple API for functions taking both an existing buffer or a heightfield.

Parameters
hfHeightfield.

◆ InitForTexture()

void GPUHeightFieldAnalysis::InitForTexture ( const HeightField & hf)
protected

Init function from a given heightfield.

Initialize a GPU texture (and not a buffer).

This function is useful when the single precision is not an issue for the calling function.

Parameters
hfHeightfield.

◆ Laplacian()

ScalarField2 GPUHeightFieldAnalysis::Laplacian ( const HeightField & hf)

Computes the Laplacian of the heightfield in double precision on the GPU.

Parameters
hfthe heightfield

◆ Shadow()

ScalarField2 GPUHeightFieldAnalysis::Shadow ( const HeightField & hf,
const Vector & l,
int maxSteps = 2256 )

Compute shadows.

Parameters
hfHeightfield.
lLight direction, should be normalized
maxStepsNumber of maximum steps for sphere tracing

◆ SoftShadows()

ScalarField2 GPUHeightFieldAnalysis::SoftShadows ( const HeightField & hf,
const Vector & l,
double s,
int maxSteps = 2256 )

Compute soft shadows. The code is the same as the SmoothShadow() function in LibMaya/Shaders/heightfield_raytrace.glsl file.

Parameters
hfHeightfield.
lLight direction, should be normalized
sShadow strength
maxStepsNumber of maximum steps for sphere tracing

◆ Visibility()

ScalarField2 GPUHeightFieldAnalysis::Visibility ( const HeightField & hf,
const Vector & sun,
int maxSteps = 2256 )

Computes the visibility of the sun on the terrain.

Parameters
hfThe HeightField
sunThe sun vector
maxStepsNumber of maximum steps for sphere tracing