Pyrogenesis  trunk
Public Member Functions | Private Attributes | List of all members
ShadowMap Class Reference

Class ShadowMap: Maintain the shadow map texture and perform necessary OpenGL setup, including matrix calculations. More...

#include <ShadowMap.h>

Collaboration diagram for ShadowMap:
Collaboration graph
[legend]

Public Member Functions

 ShadowMap ()
 
 ~ShadowMap ()
 
void RecreateTexture ()
 RecreateTexture: Destroy the current shadow texture and force creation of a new one. More...
 
int GetDepthTextureBits () const
 GetDepthTextureBits: Return the number of bits to use for depth textures when enabled. More...
 
void SetDepthTextureBits (int bits)
 SetDepthTextureBits: Sets the number of bits to use for depth textures when enabled. More...
 
void SetupFrame (const CCamera &camera, const CVector3D &lightdir)
 SetupFrame: Configure light space for the given camera and light direction, create the shadow texture if necessary, etc. More...
 
void AddShadowCasterBound (const int cascade, const CBoundingBoxAligned &bounds)
 Add the bounding box of an object that will cast a shadow. More...
 
void AddShadowReceiverBound (const CBoundingBoxAligned &bounds)
 Add the bounding box of an object that will receive a shadow. More...
 
CFrustum GetShadowCasterCullFrustum (const int cascade)
 Compute the frustum originating at the light source, that encompasses all the objects passed into AddShadowReceiverBound so far. More...
 
void BeginRender (Renderer::Backend::IDeviceCommandContext *deviceCommandContext)
 Sets backend state for rendering into the shadow map texture. More...
 
void EndRender (Renderer::Backend::IDeviceCommandContext *deviceCommandContext)
 Finishes rendering into the shadow map. More...
 
int GetCascadeCount () const
 Returns the current number of used cascades. More...
 
void PrepareCamera (Renderer::Backend::IDeviceCommandContext *deviceCommandContext, const int cascade)
 Sets the renderer camera for the cascade. More...
 
void BindTo (Renderer::Backend::IDeviceCommandContext *deviceCommandContext, Renderer::Backend::IShaderProgram *shader) const
 Binds all needed resources and uniforms to draw shadows using the shader. More...
 
void RenderDebugBounds ()
 Visualize shadow mapping calculations to help in debugging and optimal shadow map usage. More...
 

Private Attributes

ShadowMapInternalsm
 

Detailed Description

Class ShadowMap: Maintain the shadow map texture and perform necessary OpenGL setup, including matrix calculations.

The class will automatically generate a texture the first time the shadow map is rendered into. The texture will not be resized afterwards.

Constructor & Destructor Documentation

◆ ShadowMap()

ShadowMap::ShadowMap ( )

◆ ~ShadowMap()

ShadowMap::~ShadowMap ( )

Member Function Documentation

◆ AddShadowCasterBound()

void ShadowMap::AddShadowCasterBound ( const int  cascade,
const CBoundingBoxAligned bounds 
)

Add the bounding box of an object that will cast a shadow.

This is used to calculate the bounds for the shadow map.

Parameters
boundsworld space bounding box

◆ AddShadowReceiverBound()

void ShadowMap::AddShadowReceiverBound ( const CBoundingBoxAligned bounds)

Add the bounding box of an object that will receive a shadow.

This is used to calculate the bounds for the shadow map.

Parameters
boundsworld space bounding box

◆ BeginRender()

void ShadowMap::BeginRender ( Renderer::Backend::IDeviceCommandContext deviceCommandContext)

Sets backend state for rendering into the shadow map texture.

◆ BindTo()

void ShadowMap::BindTo ( Renderer::Backend::IDeviceCommandContext deviceCommandContext,
Renderer::Backend::IShaderProgram shader 
) const

Binds all needed resources and uniforms to draw shadows using the shader.

◆ EndRender()

void ShadowMap::EndRender ( Renderer::Backend::IDeviceCommandContext deviceCommandContext)

Finishes rendering into the shadow map.

◆ GetCascadeCount()

int ShadowMap::GetCascadeCount ( ) const

Returns the current number of used cascades.

◆ GetDepthTextureBits()

int ShadowMap::GetDepthTextureBits ( ) const

GetDepthTextureBits: Return the number of bits to use for depth textures when enabled.

Returns
depth texture bit depth

◆ GetShadowCasterCullFrustum()

CFrustum ShadowMap::GetShadowCasterCullFrustum ( const int  cascade)

Compute the frustum originating at the light source, that encompasses all the objects passed into AddShadowReceiverBound so far.

This frustum can be used to determine which objects might cast a visible shadow. Those objects should be passed to AddShadowCasterBound and then should be rendered into the shadow map.

◆ PrepareCamera()

void ShadowMap::PrepareCamera ( Renderer::Backend::IDeviceCommandContext deviceCommandContext,
const int  cascade 
)

Sets the renderer camera for the cascade.

◆ RecreateTexture()

void ShadowMap::RecreateTexture ( )

RecreateTexture: Destroy the current shadow texture and force creation of a new one.

Useful when the renderer's size has changed and the texture should be resized too.

◆ RenderDebugBounds()

void ShadowMap::RenderDebugBounds ( )

Visualize shadow mapping calculations to help in debugging and optimal shadow map usage.

◆ SetDepthTextureBits()

void ShadowMap::SetDepthTextureBits ( int  bits)

SetDepthTextureBits: Sets the number of bits to use for depth textures when enabled.

Possible values are 16, 24, 32 and 0 (= use default)

Parameters
bitsnumber of bits

◆ SetupFrame()

void ShadowMap::SetupFrame ( const CCamera camera,
const CVector3D lightdir 
)

SetupFrame: Configure light space for the given camera and light direction, create the shadow texture if necessary, etc.

Parameters
camerathe camera that will be used for world rendering
lightdirthe direction of the (directional) sunlight

Member Data Documentation

◆ m

ShadowMapInternals* ShadowMap::m
private

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