SLProject 4.0.000
SLShadowMap Class Reference

Class for standard and cascaded shadow mapping. More...

#include <SLShadowMap.h>

Public Member Functions

 SLShadowMap (SLLight *light, const SLfloat lightClipNear=0.1f, const SLfloat lightClipFar=20.0f, const SLVec2f &size=SLVec2f(8, 8), const SLVec2i &texSize=SLVec2i(1024, 1024))
 Ctor for standard fixed sized shadow mapping without cascades. More...
 
 SLShadowMap (SLLight *light, SLCamera *camera, const SLVec2i &texSize=SLVec2i(1024, 1024), const SLint numCascades=4)
 Ctor for standard auto sized shadow mapping with cascades. More...
 
 ~SLShadowMap ()
 
void renderShadows (SLSceneView *sv, SLNode *root)
 
void drawFrustum ()
 SLShadowMap::drawFrustum draws the volume affected by the shadow map. More...
 
void drawRays ()
 
void useCubemap (SLbool useCubemap)
 
void rayCount (const SLVec2i &rayCount)
 
void clipNear (SLfloat clipNear)
 
void clipFar (SLfloat clipFar)
 
void size (const SLVec2f &size)
 
void textureSize (const SLVec2i &textureSize)
 
void numCascades (int numCascades)
 
void cascadesFactor (float factor)
 
SLProjType projection ()
 
SLbool useCubemap () const
 
SLbool useCascaded () const
 
SLMat4flightSpace ()
 
SLGLDepthBufferdepthBuffer ()
 
SLGLVDepthBuffer depthBuffers ()
 
SLVec2i rayCount ()
 
SLfloat lightClipNear ()
 
SLfloat lightClipFar ()
 
SLVec2f size ()
 
SLVec2i textureSize ()
 
int numCascades ()
 
int maxCascades ()
 
float cascadesFactor ()
 
SLCameracamera ()
 

Static Public Attributes

static SLuint drawCalls = 0
 NO. of draw calls for shadow mapping. More...
 

Private Member Functions

void updateLightSpaces ()
 SLShadowMap::updateLightSpaces updates a light view projection matrix. More...
 
void renderDirectionalLightCascaded (SLSceneView *sv, SLNode *root)
 
SLVVec2f getShadowMapCascades (int numCascades, float camClipNear, float camClipFar)
 
void drawNodesIntoDepthBufferRec (SLNode *node, SLSceneView *sv, SLMat4f &lightView)
 
void lightCullingAdaptiveRec (SLNode *node, SLMat4f &lightProj, SLMat4f &lightView, SLPlane *lightFrustumPlanes, SLVNode &visibleNodes)
 
void drawNodesDirectionalCulling (SLVNode visibleNodes, SLSceneView *sv, SLMat4f &lightView)
 

Private Attributes

SLLight_light
 The light which uses this shadow map. More...
 
SLProjType _projection
 Projection to use to create shadow map. More...
 
SLbool _useCubemap
 Flag if cubemap should be used for perspective projections. More...
 
SLbool _useCascaded
 Flag if cascaded shadow maps should be used. More...
 
SLint _numCascades
 Number of cascades for directional light shadow mapping. More...
 
SLint _maxCascades
 Max. number of cascades for for which the shader gets generated. More...
 
SLfloat _cascadesFactor
 Factor that determines the cascades distribution. More...
 
SLMat4f _lightView [6]
 Light view matrices. More...
 
SLMat4f _lightProj [6]
 Light projection matrices. More...
 
SLMat4f _lightSpace [6]
 Light space matrices (= _lightProj * _lightView) More...
 
SLGLVDepthBuffer _depthBuffers
 Vector of framebuffers with texture. More...
 
SLGLVertexArrayExt_frustumVAO
 Visualization of light-space-frustum. More...
 
SLVec2i _rayCount
 Amount of rays drawn by drawRays() More...
 
SLMaterial_material
 Material used to render the shadow map. More...
 
SLfloat _lightClipNear
 Light frustum near clipping plane. More...
 
SLfloat _lightClipFar
 Light frustum far clipping plane. More...
 
SLVec2f _size
 Height and width of the frustum (only for SLLightDirect non cascaded) More...
 
SLVec2f _halfSize
 _size divided by two (only for SLLightDirect non cascaded) More...
 
SLVec2i _textureSize
 Size of the shadow map texture. More...
 
SLCamera_camera
 Camera to witch the light frustums are adapted. More...
 

Detailed Description

Class for standard and cascaded shadow mapping.

Shadow mapping is a technique to render shadows. The scene gets rendered from the point of view of the lights which cast shadows. The resulting depth-map of that render-pass can be used to determine which fragments are affected by which lights. The standard fixed size shadow maps can be used with all light types. The auto sized shadow maps get automatically sized to a specified camera. At the moment only directional light get supported with multiple cascaded shadow maps.

Constructor & Destructor Documentation

◆ SLShadowMap() [1/2]

SLShadowMap::SLShadowMap ( SLLight light,
const SLfloat  lightClipNear = 0.1f,
const SLfloat  lightClipFar = 20.0f,
const SLVec2f size = SLVec2f(8, 8),
const SLVec2i texSize = SLVec2i(1024, 1024) 
)

Ctor for standard fixed sized shadow mapping without cascades.

Ctor for standard fixed size shadow map for any type of light

Parameters
lightPointer to the light for which the shadow is created
lightClipNearThe light frustums near clipping distance
lightClipFarThe light frustums near clipping distance
sizeIgnored for rectangular lights
texSizeShadow texture map size

◆ SLShadowMap() [2/2]

SLShadowMap::SLShadowMap ( SLLight light,
SLCamera camera,
const SLVec2i texSize = SLVec2i(1024, 1024),
const SLint  numCascades = 4 
)

Ctor for standard auto sized shadow mapping with cascades.

Ctor for auto sized cascaded shadow mapping

Parameters
lightPointer to the light for which the shadow is created
cameraPointer to the camera for witch the shadow map gets sized
texSizeShadow texture map size (equal for all cascades)
numCascadesNO. of cascades for cascaded shadow mapping

◆ ~SLShadowMap()

SLShadowMap::~SLShadowMap ( )

Member Function Documentation

◆ camera()

SLCamera * SLShadowMap::camera ( )
inline

◆ cascadesFactor() [1/2]

float SLShadowMap::cascadesFactor ( )
inline

◆ cascadesFactor() [2/2]

void SLShadowMap::cascadesFactor ( float  factor)
inline

◆ clipFar()

void SLShadowMap::clipFar ( SLfloat  clipFar)
inline

◆ clipNear()

void SLShadowMap::clipNear ( SLfloat  clipNear)
inline

◆ depthBuffer()

SLGLDepthBuffer * SLShadowMap::depthBuffer ( )
inline

◆ depthBuffers()

SLGLVDepthBuffer SLShadowMap::depthBuffers ( )
inline

◆ drawFrustum()

void SLShadowMap::drawFrustum ( )

SLShadowMap::drawFrustum draws the volume affected by the shadow map.

◆ drawNodesDirectionalCulling()

void SLShadowMap::drawNodesDirectionalCulling ( SLVNode  visibleNodes,
SLSceneView sv,
SLMat4f lightView 
)
private

SLShadowMap::drawNodesDirectionalCulling draw all nodes in the vector visibleNodes.

Parameters
visibleNodesVector of visible nodes
svPointer to the sceneview
lightViewThe light view matrix

◆ drawNodesIntoDepthBufferRec()

void SLShadowMap::drawNodesIntoDepthBufferRec ( SLNode node,
SLSceneView sv,
SLMat4f lightView 
)
private

Recursive node drawing function for standard shadow map drawing.

Parameters
nodeThe node do draw
svPointer to the sceneview
lightViewThe light view matrix

◆ drawRays()

void SLShadowMap::drawRays ( )

SLShadowMap::drawRays draws sample rays of the light for visualization purpose only. Gets turned on when the light node is selected.

◆ getShadowMapCascades()

SLVVec2f SLShadowMap::getShadowMapCascades ( int  numCascades,
float  camClipNear,
float  camClipFar 
)
private

Returns a vector of near and far clip distances for all shadow cascades along the cameras view direction.

Parameters
numCascadesNO. of cascades
camClipNearThe cameras near clipping distance
camClipFarThe cameras far clipping distance
Returns
A SLVVec2f vector with the near and far clip distances

◆ lightClipFar()

SLfloat SLShadowMap::lightClipFar ( )
inline

◆ lightClipNear()

SLfloat SLShadowMap::lightClipNear ( )
inline

◆ lightCullingAdaptiveRec()

void SLShadowMap::lightCullingAdaptiveRec ( SLNode node,
SLMat4f lightProj,
SLMat4f lightView,
SLPlane lightFrustumPlanes,
SLVNode visibleNodes 
)
private

Returns the visible nodes inside the light frustum Check if the passed node is inside the light frustum and add if so to the visibleNodes vector. The goal is to exit this function as fast as possible if the node is not visible from the light hence gets not lighted.

Parameters
nodeNode to cull or add to to visibleNodes vector
lightProjThe cascades light projection matrix that gets adapted
lightViewThe cascades light view matrix
lightFrustumPlanesThe six light frustum planes
visibleNodesVector to push the lighted nodes

◆ lightSpace()

SLMat4f * SLShadowMap::lightSpace ( )
inline

◆ maxCascades()

int SLShadowMap::maxCascades ( )
inline

◆ numCascades() [1/2]

int SLShadowMap::numCascades ( )
inline

◆ numCascades() [2/2]

void SLShadowMap::numCascades ( int  numCascades)
inline

◆ projection()

SLProjType SLShadowMap::projection ( )
inline

◆ rayCount() [1/2]

SLVec2i SLShadowMap::rayCount ( )
inline

◆ rayCount() [2/2]

void SLShadowMap::rayCount ( const SLVec2i rayCount)
inline

◆ renderDirectionalLightCascaded()

void SLShadowMap::renderDirectionalLightCascaded ( SLSceneView sv,
SLNode root 
)
private

Renders the nodes into cascaded shadow maps for directional lights

Parameters
svPointer of the sceneview
rootPointer to the root node of the scene

◆ renderShadows()

void SLShadowMap::renderShadows ( SLSceneView sv,
SLNode root 
)

SLShadowMap::render Toplevel entry function for shadow map rendering.

Parameters
svPointer of the sceneview
rootPointer to the root node of the scene

◆ size() [1/2]

SLVec2f SLShadowMap::size ( )
inline

◆ size() [2/2]

void SLShadowMap::size ( const SLVec2f size)
inline

◆ textureSize() [1/2]

SLVec2i SLShadowMap::textureSize ( )
inline

◆ textureSize() [2/2]

void SLShadowMap::textureSize ( const SLVec2i textureSize)
inline

◆ updateLightSpaces()

void SLShadowMap::updateLightSpaces ( )
private

SLShadowMap::updateLightSpaces updates a light view projection matrix.

◆ useCascaded()

SLbool SLShadowMap::useCascaded ( ) const
inline

◆ useCubemap() [1/2]

SLbool SLShadowMap::useCubemap ( ) const
inline

◆ useCubemap() [2/2]

void SLShadowMap::useCubemap ( SLbool  useCubemap)
inline

Member Data Documentation

◆ _camera

SLCamera* SLShadowMap::_camera
private

Camera to witch the light frustums are adapted.

◆ _cascadesFactor

SLfloat SLShadowMap::_cascadesFactor
private

Factor that determines the cascades distribution.

◆ _depthBuffers

SLGLVDepthBuffer SLShadowMap::_depthBuffers
private

Vector of framebuffers with texture.

◆ _frustumVAO

SLGLVertexArrayExt* SLShadowMap::_frustumVAO
private

Visualization of light-space-frustum.

◆ _halfSize

SLVec2f SLShadowMap::_halfSize
private

_size divided by two (only for SLLightDirect non cascaded)

◆ _light

SLLight* SLShadowMap::_light
private

The light which uses this shadow map.

◆ _lightClipFar

SLfloat SLShadowMap::_lightClipFar
private

Light frustum far clipping plane.

◆ _lightClipNear

SLfloat SLShadowMap::_lightClipNear
private

Light frustum near clipping plane.

◆ _lightProj

SLMat4f SLShadowMap::_lightProj[6]
private

Light projection matrices.

◆ _lightSpace

SLMat4f SLShadowMap::_lightSpace[6]
private

Light space matrices (= _lightProj * _lightView)

◆ _lightView

SLMat4f SLShadowMap::_lightView[6]
private

Light view matrices.

◆ _material

SLMaterial* SLShadowMap::_material
private

Material used to render the shadow map.

◆ _maxCascades

SLint SLShadowMap::_maxCascades
private

Max. number of cascades for for which the shader gets generated.

◆ _numCascades

SLint SLShadowMap::_numCascades
private

Number of cascades for directional light shadow mapping.

◆ _projection

SLProjType SLShadowMap::_projection
private

Projection to use to create shadow map.

◆ _rayCount

SLVec2i SLShadowMap::_rayCount
private

Amount of rays drawn by drawRays()

◆ _size

SLVec2f SLShadowMap::_size
private

Height and width of the frustum (only for SLLightDirect non cascaded)

◆ _textureSize

SLVec2i SLShadowMap::_textureSize
private

Size of the shadow map texture.

◆ _useCascaded

SLbool SLShadowMap::_useCascaded
private

Flag if cascaded shadow maps should be used.

◆ _useCubemap

SLbool SLShadowMap::_useCubemap
private

Flag if cubemap should be used for perspective projections.

◆ drawCalls

SLuint SLShadowMap::drawCalls = 0
static

NO. of draw calls for shadow mapping.


The documentation for this class was generated from the following files: