SLProject 4.0.000
|
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 |
SLMat4f * | lightSpace () |
SLGLDepthBuffer * | depthBuffer () |
SLGLVDepthBuffer | depthBuffers () |
SLVec2i | rayCount () |
SLfloat | lightClipNear () |
SLfloat | lightClipFar () |
SLVec2f | size () |
SLVec2i | textureSize () |
int | numCascades () |
int | maxCascades () |
float | cascadesFactor () |
SLCamera * | camera () |
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.
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 |
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 |
SLShadowMap::~SLShadowMap | ( | ) |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void SLShadowMap::drawFrustum | ( | ) |
SLShadowMap::drawFrustum draws the volume affected by the shadow map.
|
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 |
|
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 |
void SLShadowMap::drawRays | ( | ) |
SLShadowMap::drawRays draws sample rays of the light for visualization purpose only. Gets turned on when the light node is selected.
|
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 |
|
inline |
|
inline |
|
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 |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
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 |
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 |
|
inline |
|
inline |
|
inline |
|
inline |
|
private |
SLShadowMap::updateLightSpaces updates a light view projection matrix.
|
inline |
|
inline |
|
inline |
|
private |
Camera to witch the light frustums are adapted.
|
private |
Factor that determines the cascades distribution.
|
private |
Vector of framebuffers with texture.
|
private |
Visualization of light-space-frustum.
|
private |
_size divided by two (only for SLLightDirect non cascaded)
|
private |
The light which uses this shadow map.
|
private |
Light frustum far clipping plane.
|
private |
Light frustum near clipping plane.
|
private |
Light projection matrices.
|
private |
Light space matrices (= _lightProj * _lightView)
|
private |
Light view matrices.
|
private |
Material used to render the shadow map.
|
private |
Max. number of cascades for for which the shader gets generated.
|
private |
Number of cascades for directional light shadow mapping.
|
private |
Projection to use to create shadow map.
|
private |
Amount of rays drawn by drawRays()
|
private |
Height and width of the frustum (only for SLLightDirect non cascaded)
|
private |
Size of the shadow map texture.
|
private |
Flag if cascaded shadow maps should be used.
|
private |
Flag if cubemap should be used for perspective projections.
|
static |
NO. of draw calls for shadow mapping.