Heightfield 1.0
|
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. | |
Parallelized heightfield analysis.
GPUHeightFieldAnalysis::GPUHeightFieldAnalysis | ( | ) |
Constructor.
Initialize everthing to zero.
ScalarField2 GPUHeightFieldAnalysis::Accessibility | ( | const HeightField & | hf, |
const double & | r, | ||
int | n, | ||
int | maxSteps = 2256 ) |
Compute accessibility.
hf | Heightfield |
r | Radius. |
n | Number of rays. |
maxSteps | Number of maximum steps for sphere tracing |
ScalarField2 GPUHeightFieldAnalysis::ClearSky | ( | const HeightField & | hf, |
double | r, | ||
int | n, | ||
int | maxSteps = 2256 ) |
Clear sky.
hf | Heightfield. |
r | maximum distance along a ray. |
n | Number of samples per cell. |
maxSteps | Number of maximum steps for sphere tracing |
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.
hf | Heightfield. |
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.
hfBuffer | Heightfield single precision gpu buffer, should already be initialized. |
nx,ny | Heightfield resolution. |
ScalarField2 GPUHeightFieldAnalysis::Diffuse | ( | const HeightField & | hf, |
const Vector & | l, | ||
double | s ) |
Compute diffuse shading.
hf | Heightfield. |
l | Light direction, should be normalized |
s | Shadow strength |
void GPUHeightFieldAnalysis::FractionalGradient | ( | const HeightField & | hf, |
double | s, | ||
int | m, | ||
VectorField2 & | grad, | ||
ScalarField2 & | gradNorm ) |
Compute fractional gradient and fractional gradient norm fields.
hf | heightfield |
s | Fractional parameter, should be in [0,1]. |
m | mask size |
grad | returned fractional gradient field |
gradNorm | returned fractional gradient norm |
ScalarField2 GPUHeightFieldAnalysis::FractionalLaplacian | ( | const HeightField & | hf, |
int | m, | ||
double | s ) |
Compute the fractional Laplacian.
hf | Heightfield |
m | Mask size |
s | Fractional parameter, should be in [0,1]. |
Vector2 GPUHeightFieldAnalysis::GetRange | ( | const HeightField & | hf | ) |
Computes the range of a heightfield on the GPU.
hf | the HeightField |
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.
hfBuffer | Heightfield gpu buffer, should be initialized. |
nx,ny | Heightfield dimensions. |
void GPUHeightFieldAnalysis::Gradient | ( | const HeightField & | hf, |
VectorField2 & | grad, | ||
ScalarField2 & | gradNorm ) |
Computes the gradient vector field and gradient norm scalar field of a given heightfield.
hf | the heightfield |
grad | returned gradient vector field |
gradNorm | returned gardient norm scalar field |
|
protected |
Init function, used in the context of an already existing GPU buffer from the QOpenGL widget.
nx,ny | Heightfield dimensions, should match the size of the GPU buffer. |
|
protected |
Init function from a given heightfield.
Initialize a double precision GPU buffer.
hf | Heightfield |
|
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.
hf | Heightfield. |
|
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.
hf | Heightfield. |
ScalarField2 GPUHeightFieldAnalysis::Laplacian | ( | const HeightField & | hf | ) |
Computes the Laplacian of the heightfield in double precision on the GPU.
hf | the heightfield |
ScalarField2 GPUHeightFieldAnalysis::Shadow | ( | const HeightField & | hf, |
const Vector & | l, | ||
int | maxSteps = 2256 ) |
Compute shadows.
hf | Heightfield. |
l | Light direction, should be normalized |
maxSteps | Number of maximum steps for sphere tracing |
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.
hf | Heightfield. |
l | Light direction, should be normalized |
s | Shadow strength |
maxSteps | Number of maximum steps for sphere tracing |
ScalarField2 GPUHeightFieldAnalysis::Visibility | ( | const HeightField & | hf, |
const Vector & | sun, | ||
int | maxSteps = 2256 ) |
Computes the visibility of the sun on the terrain.
hf | The HeightField |
sun | The sun vector |
maxSteps | Number of maximum steps for sphere tracing |