Pyrogenesis trunk
|
Class ShadowMap: Maintain the shadow map texture and perform necessary OpenGL setup, including matrix calculations. More...
#include <ShadowMap.h>
Public Member Functions | |
ShadowMap (Renderer::Backend::IDevice *device) | |
~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 | |
ShadowMapInternals * | m |
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.
ShadowMap::ShadowMap | ( | Renderer::Backend::IDevice * | device | ) |
ShadowMap::~ShadowMap | ( | ) |
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.
bounds | world space bounding box |
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.
bounds | world space bounding box |
void ShadowMap::BeginRender | ( | Renderer::Backend::IDeviceCommandContext * | deviceCommandContext | ) |
Sets backend state for rendering into the shadow map texture.
void ShadowMap::BindTo | ( | Renderer::Backend::IDeviceCommandContext * | deviceCommandContext, |
Renderer::Backend::IShaderProgram * | shader | ||
) | const |
Binds all needed resources and uniforms to draw shadows using the shader.
void ShadowMap::EndRender | ( | Renderer::Backend::IDeviceCommandContext * | deviceCommandContext | ) |
Finishes rendering into the shadow map.
int ShadowMap::GetCascadeCount | ( | ) | const |
Returns the current number of used cascades.
int ShadowMap::GetDepthTextureBits | ( | ) | const |
GetDepthTextureBits: Return the number of bits to use for depth textures when enabled.
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.
void ShadowMap::PrepareCamera | ( | Renderer::Backend::IDeviceCommandContext * | deviceCommandContext, |
const int | cascade | ||
) |
Sets the renderer camera for the cascade.
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.
void ShadowMap::RenderDebugBounds | ( | ) |
Visualize shadow mapping calculations to help in debugging and optimal shadow map usage.
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)
bits | number of bits |
SetupFrame: Configure light space for the given camera and light direction, create the shadow texture if necessary, etc.
camera | the camera that will be used for world rendering |
lightdir | the direction of the (directional) sunlight |
|
private |