SLProject
4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
|
Class for standard and cascaded shadow mapping. More...
#include <SLShadowMap.h>
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... | |
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.
Definition at line 38 of file SLShadowMap.h.
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
light | Pointer to the light for which the shadow is created |
lightClipNear | The light frustums near clipping distance |
lightClipFar | The light frustums near clipping distance |
size | Ignored for rectangular lights |
texSize | Shadow texture map size |
Definition at line 38 of file SLShadowMap.cpp.
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
light | Pointer to the light for which the shadow is created |
camera | Pointer to the camera for witch the shadow map gets sized |
texSize | Shadow texture map size (equal for all cascades) |
numCascades | NO. of cascades for cascaded shadow mapping |
Definition at line 81 of file SLShadowMap.cpp.
SLShadowMap::~SLShadowMap | ( | ) |
Definition at line 116 of file SLShadowMap.cpp.
|
inline |
Definition at line 90 of file SLShadowMap.h.
|
inline |
Definition at line 89 of file SLShadowMap.h.
|
inline |
Definition at line 73 of file SLShadowMap.h.
Definition at line 65 of file SLShadowMap.h.
Definition at line 64 of file SLShadowMap.h.
|
inline |
Definition at line 80 of file SLShadowMap.h.
|
inline |
Definition at line 81 of file SLShadowMap.h.
void SLShadowMap::drawFrustum | ( | ) |
SLShadowMap::drawFrustum draws the volume affected by the shadow map.
Definition at line 124 of file SLShadowMap.cpp.
|
private |
SLShadowMap::drawNodesDirectionalCulling draw all nodes in the vector visibleNodes.
visibleNodes | Vector of visible nodes |
sv | Pointer to the sceneview |
lightView | The light view matrix |
Definition at line 397 of file SLShadowMap.cpp.
|
private |
Recursive node drawing function for standard shadow map drawing.
node | The node do draw |
sv | Pointer to the sceneview |
lightView | The light view matrix |
Definition at line 422 of file SLShadowMap.cpp.
void SLShadowMap::drawRays | ( | ) |
SLShadowMap::drawRays draws sample rays of the light for visualization purpose only. Gets turned on when the light node is selected.
Definition at line 188 of file SLShadowMap.cpp.
|
private |
Returns a vector of near and far clip distances for all shadow cascades along the cameras view direction.
numCascades | NO. of cascades |
camClipNear | The cameras near clipping distance |
camClipFar | The cameras far clipping distance |
Definition at line 536 of file SLShadowMap.cpp.
|
inline |
Definition at line 84 of file SLShadowMap.h.
|
inline |
Definition at line 83 of file SLShadowMap.h.
|
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.
node | Node to cull or add to to visibleNodes vector |
lightProj | The cascades light projection matrix that gets adapted |
lightView | The cascades light view matrix |
lightFrustumPlanes | The six light frustum planes |
visibleNodes | Vector to push the lighted nodes |
Definition at line 310 of file SLShadowMap.cpp.
|
inline |
Definition at line 79 of file SLShadowMap.h.
|
inline |
Definition at line 88 of file SLShadowMap.h.
|
inline |
Definition at line 87 of file SLShadowMap.h.
|
inline |
Definition at line 72 of file SLShadowMap.h.
|
inline |
Definition at line 76 of file SLShadowMap.h.
|
inline |
Definition at line 82 of file SLShadowMap.h.
Definition at line 63 of file SLShadowMap.h.
|
private |
Renders the nodes into cascaded shadow maps for directional lights
sv | Pointer of the sceneview |
root | Pointer to the root node of the scene |
Definition at line 561 of file SLShadowMap.cpp.
void SLShadowMap::renderShadows | ( | SLSceneView * | sv, |
SLNode * | root | ||
) |
SLShadowMap::render Toplevel entry function for shadow map rendering.
sv | Pointer of the sceneview |
root | Pointer to the root node of the scene |
Definition at line 450 of file SLShadowMap.cpp.
|
inline |
Definition at line 85 of file SLShadowMap.h.
|
inline |
Definition at line 86 of file SLShadowMap.h.
Definition at line 71 of file SLShadowMap.h.
|
private |
SLShadowMap::updateLightSpaces updates a light view projection matrix.
Definition at line 240 of file SLShadowMap.cpp.
|
inline |
Definition at line 78 of file SLShadowMap.h.
|
inline |
Definition at line 77 of file SLShadowMap.h.
Definition at line 62 of file SLShadowMap.h.
|
private |
Camera to witch the light frustums are adapted.
Definition at line 132 of file SLShadowMap.h.
|
private |
Factor that determines the cascades distribution.
Definition at line 119 of file SLShadowMap.h.
|
private |
Vector of framebuffers with texture.
Definition at line 123 of file SLShadowMap.h.
|
private |
Visualization of light-space-frustum.
Definition at line 124 of file SLShadowMap.h.
|
private |
_size divided by two (only for SLLightDirect non cascaded)
Definition at line 130 of file SLShadowMap.h.
|
private |
The light which uses this shadow map.
Definition at line 113 of file SLShadowMap.h.
|
private |
Light frustum far clipping plane.
Definition at line 128 of file SLShadowMap.h.
|
private |
Light frustum near clipping plane.
Definition at line 127 of file SLShadowMap.h.
|
private |
Light projection matrices.
Definition at line 121 of file SLShadowMap.h.
|
private |
Light space matrices (= _lightProj * _lightView)
Definition at line 122 of file SLShadowMap.h.
|
private |
Light view matrices.
Definition at line 120 of file SLShadowMap.h.
|
private |
Material used to render the shadow map.
Definition at line 126 of file SLShadowMap.h.
|
private |
Max. number of cascades for for which the shader gets generated.
Definition at line 118 of file SLShadowMap.h.
|
private |
Number of cascades for directional light shadow mapping.
Definition at line 117 of file SLShadowMap.h.
|
private |
Projection to use to create shadow map.
Definition at line 114 of file SLShadowMap.h.
|
private |
Amount of rays drawn by drawRays()
Definition at line 125 of file SLShadowMap.h.
|
private |
Height and width of the frustum (only for SLLightDirect non cascaded)
Definition at line 129 of file SLShadowMap.h.
|
private |
Size of the shadow map texture.
Definition at line 131 of file SLShadowMap.h.
|
private |
Flag if cascaded shadow maps should be used.
Definition at line 116 of file SLShadowMap.h.
|
private |
Flag if cubemap should be used for perspective projections.
Definition at line 115 of file SLShadowMap.h.
|
static |
NO. of draw calls for shadow mapping.
Definition at line 92 of file SLShadowMap.h.