Maya 1.0
TerrainRaytracingWidget Class Reference

Heightfield rendering widget based on sphere-tracing. More...

#include <realtime.h>

Public Member Functions

 TerrainRaytracingWidget (QWidget *parent=nullptr)
 Default constructor.
 
 ~TerrainRaytracingWidget ()
 Destructor. Release shader program, vao and textures.
 
virtual void SetHeightField (ScalarField2 *hfPtr)
 Internal update function of the widget.
 
virtual void UpdateInternal ()
 Update the GPU data from the internal CPU heightfield pointer.
 
void UpdateBuffer (GLuint)
 Manually change the underlying heightfield buffer.
 
void SetShading (const ScalarField2 &)
 Set the additional shading buffer that can be used by the glsl.
 
void UseShading (const bool &=true)
 Set the additional shading flag.
 
void SetExternAlbedo (GLuint)
 Update the albedo texture with an existing OpenGL texture. UseAlbedo(true) should have been called before, or no update will be performed.
 
void UseExternAlbedo (const bool &=true)
 Update the albedo texture flag.
 
void SetAlbedo (const QImage &)
 Update the albedo texture. UseAlbedo(true) should have been called before, or no update will be performed.
 
void UseAlbedo (const bool &=true)
 Update the internal albedo texture flag.
 
void UseWireframe (const bool &=true)
 Set the wireframe flag.
 
void UseCost (const bool &=true)
 Set the cost shading flag.
 
void UseElevationShading (const bool &)
 Set the elevation shading flag.
 
void UseGreenBrownYellowShading (const bool &)
 Set the shading from color map flag.
 
void SetCamera (const Camera &)
 Function override from AbstractTerrainWidget.
 
void Reload ()
 Hot reload of the glsl program. Properly rebinds the albedo texture.
 
void SetElevationRange (double, double)
 Set the elevation range for the terrain.
 
void SetSteps (int)
 Set the maximum number of raymarching step.
 
void SetEpsilon (float)
 Set the minimum stepping distance for raymarching.
 
void SetLight (const Vector &)
 Set the directional light.
 
void SetAntialiasing (int)
 Set the amount of antialiasing.
 
void UseSmoothShadow (const bool &=true)
 Set the smooth shadow flag.
 
void SetSmoothShadowSteps (int)
 Set the number of smooth shadow steps.
 
void SetSmoothShadowMarchingSteps (int)
 Set the maximum number of smooth shadow raymarching steps.
 
void SetSmoothShadowMarchingEpsilon (float)
 Set the minimum marching epsilon for smooth shadow rays.
 
void SetSmoothShadowStrength (float)
 Set the smooth shadow strength.
 
void UseSelfShadow (const bool &=true)
 Set the smooth shadow flag.
 
void SetSelfShadowMarchingSteps (int)
 Set the maximum number of self shadow raymarching steps.
 
void SetSelfShadowMarchingEpsilon (float)
 Set the minimum marching epsilon for self shadow rays.
 
void SetSelfShadowStrength (float)
 Set the self shadow strength.
 

Protected Member Functions

virtual void paintGL ()
 Renders the scene.
 
virtual void initializeGL ()
 Initialize OpenGL, shaders and a camera centered at origin.
 
virtual void ReloadShaders ()
 Reload the shaders of the widget. Useful for realtime editing and fine tuning of the rendering.
 

Protected Attributes

ScalarField2sf = nullptr
 Pointer to heightfield.
 
Box2 bbox
 Bounding box of the heightfield.
 
float zMax = 0.0
 Min/max elevation of the heighfield.
 
float K = 1.0
 Global Lipschitz constant of the heightfield.
 
int ny = 0
 Grid sizes.
 
GLuint shaderProgram = 0
 GL program for shader.
 
GLuint raytraceVAO = 0
 Raytracer VAO.
 
GLBuffer hfBuffer
 Heightfield elevation buffer.
 
GLBuffer shadingBuffer
 Shading buffer.
 
std::vector< float > tmpData
 Temporary float vector.
 
GLuint albedoTextureBuffer = 0
 Albedo texture buffer.
 
GLuint externAlbedo = 0
 Extern albedo texture buffer.
 
bool useAlbedo = false
 Albedo texture flag.
 
bool useWireframe = false
 Wireframe flag.
 
bool useCost = false
 Cost shading flag.
 
bool useElevationShading = false
 Elevation shading flag.
 
bool useGreenBrownYellow = false
 Shading from color map flag.
 
bool useShadingBuffer = false
 Additional shading buffer use flag.
 

Detailed Description

Heightfield rendering widget based on sphere-tracing.

Member Function Documentation

◆ SetAlbedo()

void TerrainRaytracingWidget::SetAlbedo ( const QImage & albedo)

Update the albedo texture. UseAlbedo(true) should have been called before, or no update will be performed.

Parameters
albedotexture

References albedoTextureBuffer, sf, and shaderProgram.

◆ SetAntialiasing()

void TerrainRaytracingWidget::SetAntialiasing ( int AA)

Set the amount of antialiasing.

Parameters
AAantialiasing, should be between [1, 128].

References shaderProgram.

◆ SetCamera()

void TerrainRaytracingWidget::SetCamera ( const Camera & cam)

Function override from AbstractTerrainWidget.

Used to store the camera vertical angle of view, which avoids calling atan() intensively.

Parameters
camnew camera

◆ SetElevationRange()

void TerrainRaytracingWidget::SetElevationRange ( double min,
double max )

Set the elevation range for the terrain.

Parameters
min,maxelevation range

References zMax.

◆ SetEpsilon()

void TerrainRaytracingWidget::SetEpsilon ( float eps)

Set the minimum stepping distance for raymarching.

Parameters
epsminimum stepping distance

References shaderProgram.

◆ SetExternAlbedo()

void TerrainRaytracingWidget::SetExternAlbedo ( GLuint texture)

Update the albedo texture with an existing OpenGL texture. UseAlbedo(true) should have been called before, or no update will be performed.

Parameters
albedotexture

References externAlbedo, sf, and shaderProgram.

◆ SetHeightField()

void TerrainRaytracingWidget::SetHeightField ( ScalarField2 * sfPtr)
virtual

Internal update function of the widget.

Updates the internal height buffer from the heightfield pointer, recomputes the Lipschitz constant and min/max elevations.

References sf, and UpdateInternal().

◆ SetLight()

void TerrainRaytracingWidget::SetLight ( const Vector & light)

Set the directional light.

Parameters
lightlight direction

References shaderProgram, and VectorFloat::z.

◆ SetSelfShadowMarchingEpsilon()

void TerrainRaytracingWidget::SetSelfShadowMarchingEpsilon ( float eps)

Set the minimum marching epsilon for self shadow rays.

Parameters
epsmarching epsilon

References shaderProgram.

◆ SetSelfShadowMarchingSteps()

void TerrainRaytracingWidget::SetSelfShadowMarchingSteps ( int steps)

Set the maximum number of self shadow raymarching steps.

Parameters
stepsmax number of steps

References shaderProgram.

◆ SetSelfShadowStrength()

void TerrainRaytracingWidget::SetSelfShadowStrength ( float strength)

Set the self shadow strength.

Parameters
strength

References shaderProgram.

◆ SetShading()

void TerrainRaytracingWidget::SetShading ( const ScalarField2 & shading)

Set the additional shading buffer that can be used by the glsl.

Parameters
shading2D shading map, must be the same size as the underlying heightfield.

References ScalarField2::at(), sf, shadingBuffer, and tmpData.

◆ SetSmoothShadowMarchingEpsilon()

void TerrainRaytracingWidget::SetSmoothShadowMarchingEpsilon ( float eps)

Set the minimum marching epsilon for smooth shadow rays.

Parameters
epsmarching epsilon

References shaderProgram.

◆ SetSmoothShadowMarchingSteps()

void TerrainRaytracingWidget::SetSmoothShadowMarchingSteps ( int steps)

Set the maximum number of smooth shadow raymarching steps.

Parameters
stepsmax number of steps

References shaderProgram.

◆ SetSmoothShadowSteps()

void TerrainRaytracingWidget::SetSmoothShadowSteps ( int steps)

Set the number of smooth shadow steps.

Parameters
stepsnumber of steps

References shaderProgram.

◆ SetSmoothShadowStrength()

void TerrainRaytracingWidget::SetSmoothShadowStrength ( float strength)

Set the smooth shadow strength.

Parameters
strength

References shaderProgram.

◆ SetSteps()

void TerrainRaytracingWidget::SetSteps ( int s)

Set the maximum number of raymarching step.

Parameters
ssteps

References shaderProgram.

◆ UpdateBuffer()

void TerrainRaytracingWidget::UpdateBuffer ( GLuint buffer)

Manually change the underlying heightfield buffer.

This function is useful when performing erosion on the gpu - no need to retrieve the data on the CPU and manually recreate all the buffers.

Note that the buffer must contain data whose size is equal to the base heightfield.

Parameters
bufferinitialized buffer with elevation data.

References hfBuffer.

◆ UpdateInternal()

void TerrainRaytracingWidget::UpdateInternal ( )
virtual

Update the GPU data from the internal CPU heightfield pointer.

This function is computationally intensive as it recomputes the Lipschitz constant of the terrain and send data to the GPU.

References bbox, hfBuffer, K, ny, sf, shadingBuffer, tmpData, and zMax.

Referenced by SetHeightField().

◆ UseAlbedo()

void TerrainRaytracingWidget::UseAlbedo ( const bool & u = true)

Update the internal albedo texture flag.

Parameters
unew value for albedo flag.

References useAlbedo.

◆ UseCost()

void TerrainRaytracingWidget::UseCost ( const bool & cost = true)

Set the cost shading flag.

Parameters
costflag

References useCost.

◆ UseElevationShading()

void TerrainRaytracingWidget::UseElevationShading ( const bool & u)

Set the elevation shading flag.

Parameters
uflag

References useElevationShading, and useGreenBrownYellow.

◆ UseExternAlbedo()

void TerrainRaytracingWidget::UseExternAlbedo ( const bool & u = true)

Update the albedo texture flag.

Parameters
unew value for albedo flag.

◆ UseGreenBrownYellowShading()

void TerrainRaytracingWidget::UseGreenBrownYellowShading ( const bool & u)

Set the shading from color map flag.

Parameters
uflag

References useElevationShading, and useGreenBrownYellow.

◆ UseSelfShadow()

void TerrainRaytracingWidget::UseSelfShadow ( const bool & use = true)

Set the smooth shadow flag.

Parameters
useflag

References shaderProgram.

◆ UseShading()

void TerrainRaytracingWidget::UseShading ( const bool & use = true)

Set the additional shading flag.

Parameters
useflag

References useShadingBuffer.

◆ UseSmoothShadow()

void TerrainRaytracingWidget::UseSmoothShadow ( const bool & use = true)

Set the smooth shadow flag.

Parameters
useflag

References shaderProgram.

◆ UseWireframe()

void TerrainRaytracingWidget::UseWireframe ( const bool & wire = true)

Set the wireframe flag.

Parameters
wireflag

References useWireframe.