When rendering into a shadow map, SHADOW_MAP_FRAMEBUFFER is set to 1 in the depth shader by the ShadowMap's framebuffer.
More...
Inherits G3D::ReferenceCountedObject.
|
float | backfacePolygonOffset () const |
|
float | bias () const |
| Distance in meters to pull surfaces forward towards the light (along the -z axis) during shadow map rendering. More...
|
|
const shared_ptr< Texture > & | depthTexture () const |
|
bool | enabled () const |
|
const shared_ptr< Framebuffer > & | framebuffer () const |
| The framebuffer used for rendering to the texture. More...
|
|
RealTime | lastUpdateTime () const |
| Wall-clock time at which updateDepth() was last invoked. More...
|
|
const CoordinateFrame & | lightFrame () const |
| The coordinate frame of the light source. More...
|
|
const Matrix4 & | lightMVP () const |
| Model-View-Projection matrix that maps world space to the shadow map pixels; used for rendering the shadow map itself. More...
|
|
const Matrix4 & | lightProjection () const |
| Projection matrix for the light, biased to avoid self-shadowing. More...
|
|
const String & | name () const |
| For debugging purposes. More...
|
|
float | polygonOffset () const |
|
const Projection & | projection () const |
|
Projection & | projection () |
|
Rect2D | rect2DBounds () const |
|
void | setBias (float f) |
|
Distance in meters to pull surfaces forward towards the light (along the -z axis) during shadow map rendering. Call before updateDepth. More...
|
|
void | setPolygonOffset (float s, float b=nan()) |
| Increase to hide self-shadowing artifacts, decrease to avoid gap between shadow and object. More...
|
|
void | setShaderArgsRead (class UniformTable &args, const String &prefix) const |
|
Binds these parameters: More...
|
|
virtual void | setSize (Vector2int16 desiredSize=Vector2int16(1024, 1024)) |
| Call with desiredSize = 0 to turn off shadow maps. More...
|
|
const Matrix4 & | unitLightMVP () const |
| MVP adjusted to map to [0,0], [1,1] texture coordinates. More...
|
|
const Matrix4 & | unitLightProjection () const |
| Unit projection matrix for the light, biased to avoid self-shadowing. More...
|
|
virtual void | updateDepth (class RenderDevice *renderDevice, const CoordinateFrame &lightFrame, const Matrix4 &lightProjectionMatrix, const Array< shared_ptr< Surface >> &shadowCaster, CullFace cullFace=CullFace::BACK, const Color3 &transmissionWeight=Color3::white()/3.0f, const RenderPassType passType=RenderPassType::SHADOW_MAP) |
|
Assumes that the caller has ensured that shadowCaster contains only shadow-casting surfaces. More...
|
|
bool | useVarianceShadowMap () const |
|
const shared_ptr< Texture > & | vsm () const |
|
|
static void | computeMatrices (const shared_ptr< Light > &light, AABox shadowCasterBounds, CFrame &lightFrame, Projection &projection, Matrix4 &lightProjectionMatrix, float lightProjX=20, float lightProjY=20, float lightProjNearMin=0.3f, float lightProjFarMax=500.0f, float intensityCutoff=1/255.0f) |
|
Computes a reference frame (as a camera) and projection matrix for the light. More...
|
|
static shared_ptr< ShadowMap > | create (const String &name="Shadow Map", Vector2int16 desiredSize=Vector2int16(1024, 1024), const VSMSettings &vsmSettings=VSMSettings()) |
|
|
template<class T , class ... ArgTypes> |
static shared_ptr< T > | createShared (ArgTypes &&... args) |
| Like std::make_shared, but works for protected constructors. More...
|
|
When rendering into a shadow map, SHADOW_MAP_FRAMEBUFFER is set to 1 in the depth shader by the ShadowMap's framebuffer.
◆ ShadowMap()
G3D::ShadowMap::ShadowMap |
( |
const String & |
name | ) |
|
|
protected |
◆ backfacePolygonOffset()
float G3D::ShadowMap::backfacePolygonOffset |
( |
| ) |
const |
|
inline |
◆ bias()
float G3D::ShadowMap::bias |
( |
| ) |
const |
|
inline |
Distance in meters to pull surfaces forward towards the light (along the -z axis) during shadow map rendering.
This is typically on the scale of centimeters. During shadow map testing, surfaces are pulled three times this distance along their surface normal, so that faces in direct light are not shadowed by themselves.
◆ computeMatrices()
static void G3D::ShadowMap::computeMatrices |
( |
const shared_ptr< Light > & |
light, |
|
|
AABox |
shadowCasterBounds, |
|
|
CFrame & |
lightFrame, |
|
|
Projection & |
projection, |
|
|
Matrix4 & |
lightProjectionMatrix, |
|
|
float |
lightProjX = 20 , |
|
|
float |
lightProjY = 20 , |
|
|
float |
lightProjNearMin = 0.3f , |
|
|
float |
lightProjFarMax = 500.0f , |
|
|
float |
intensityCutoff = 1/255.0f |
|
) |
| |
|
static |
Computes a reference frame (as a camera) and projection matrix for the light.
- Parameters
-
lightFrame | For a directional light, this is a finite reference frame. |
projection | For a SPOT light, this is the perspective projection. |
lightProjX | Scene bounds in the light's reference frame for a directional light. Not needed for a spot light |
lightProjY | Scene bounds in the light's reference frame for a directional light. Not needed for a spot light |
lightProjNearMin | Shadow map near plane depth in the light's reference frame for a directional light. For a spot light, a larger value will be chosen if the method determines that it can safely do so. For directional and point lights, this value is used directly. |
lightProjFarMax | Shadow map far plane depth in the light's reference frame for a directional light. For a spot light, a smaller value will be chosen if the method determines that it can safely do so. For directional and point lights, this value is used directly.
|
intensityCutoff | Don't bother shadowing objects that cannot be brighter than this value. Set to 0 to cast shadows as far as the entire scene. |
◆ create()
◆ createShared()
template<class T , class ... ArgTypes>
static shared_ptr<T> G3D::ReferenceCountedObject::createShared |
( |
ArgTypes &&... |
args | ) |
|
|
inlinestaticprotectedinherited |
Like std::make_shared, but works for protected constructors.
Call as createShared<myclass>.
◆ depthTexture()
const shared_ptr<Texture>& G3D::ShadowMap::depthTexture |
( |
| ) |
const |
|
inline |
◆ enabled()
bool G3D::ShadowMap::enabled |
( |
| ) |
const |
◆ framebuffer()
const shared_ptr<Framebuffer>& G3D::ShadowMap::framebuffer |
( |
| ) |
const |
|
inline |
The framebuffer used for rendering to the texture.
◆ lastUpdateTime()
RealTime G3D::ShadowMap::lastUpdateTime |
( |
| ) |
const |
|
inline |
Wall-clock time at which updateDepth() was last invoked.
Used to avoid recomputing shadow maps for static lights and objects. Calling a mutating method like setSize() resets this to zero.
◆ lightFrame()
The coordinate frame of the light source.
◆ lightMVP()
const Matrix4& G3D::ShadowMap::lightMVP |
( |
| ) |
const |
|
inline |
Model-View-Projection matrix that maps world space to the shadow map pixels; used for rendering the shadow map itself.
Note that this maps XY to [-1,-1],[1,1]. Most applications will use biasedLightMVP to avoid self-shadowing problems.
◆ lightProjection()
const Matrix4& G3D::ShadowMap::lightProjection |
( |
| ) |
const |
|
inline |
Projection matrix for the light, biased to avoid self-shadowing.
◆ name()
const String& G3D::ShadowMap::name |
( |
| ) |
const |
|
inline |
◆ polygonOffset()
float G3D::ShadowMap::polygonOffset |
( |
| ) |
const |
|
inline |
◆ projection() [1/2]
const Projection& G3D::ShadowMap::projection |
( |
| ) |
const |
|
inline |
◆ projection() [2/2]
◆ rect2DBounds()
Rect2D G3D::ShadowMap::rect2DBounds |
( |
| ) |
const |
◆ setBias()
void G3D::ShadowMap::setBias |
( |
float |
f | ) |
|
|
inline |
Distance in meters to pull surfaces forward towards the light (along the -z axis) during shadow map rendering. Call before updateDepth.
- See also
- bias
◆ setPolygonOffset()
void G3D::ShadowMap::setPolygonOffset |
( |
float |
s, |
|
|
float |
b = nan() |
|
) |
| |
|
inline |
Increase to hide self-shadowing artifacts, decrease to avoid gap between shadow and object.
Default = 0.0.
- Parameters
-
b | if nan(), the backface offset is set to s, otherwise it is set to b |
◆ setShaderArgsRead()
void G3D::ShadowMap::setShaderArgsRead |
( |
class UniformTable & |
args, |
|
|
const String & |
prefix |
|
) |
| const |
Binds these parameters:
#expect prefix_notNull "Defined if the shadow map is bound"
uniform mat4 prefix_lightMVP;
uniform float prefix_bias;
Plus all of the Texture::setShaderArgs values for prefix_depth
◆ setSize()
Call with desiredSize = 0 to turn off shadow maps.
◆ unitLightMVP()
const Matrix4& G3D::ShadowMap::unitLightMVP |
( |
| ) |
const |
|
inline |
◆ unitLightProjection()
const Matrix4& G3D::ShadowMap::unitLightProjection |
( |
| ) |
const |
|
inline |
Unit projection matrix for the light, biased to avoid self-shadowing.
◆ updateDepth()
Assumes that the caller has ensured that shadowCaster contains only shadow-casting surfaces.
- Parameters
-
cullFace | Use NONE or BACK. Culling FRONT faces will create light leaks with our "normal offset" scheme. |
◆ useVarianceShadowMap()
bool G3D::ShadowMap::useVarianceShadowMap |
( |
| ) |
const |
|
inline |
◆ vsm()
const shared_ptr<Texture>& G3D::ShadowMap::vsm |
( |
| ) |
const |
◆ m_backfacePolygonOffset
float G3D::ShadowMap::m_backfacePolygonOffset |
|
protected |
◆ m_baseLayer
Layer G3D::ShadowMap::m_baseLayer |
|
protected |
For Surface::canMove() == false surfaces, regardless of whether they actually behave correctly and don't move.
If the surfaces in here do move (e.g., because the scene is being edited), then the shadow map will render a little more slowly due to excessive updates but will still be correct.
◆ m_bias
float G3D::ShadowMap::m_bias |
|
protected |
◆ m_dynamicLayer
Layer G3D::ShadowMap::m_dynamicLayer |
|
protected |
◆ m_lightFrame
◆ m_lightMVP
◆ m_lightProjection
Matrix4 G3D::ShadowMap::m_lightProjection |
|
protected |
◆ m_name
◆ m_polygonOffset
float G3D::ShadowMap::m_polygonOffset |
|
protected |
◆ m_projection
◆ m_unitLightMVP
Matrix4 G3D::ShadowMap::m_unitLightMVP |
|
protected |
Maps projected homogeneous coordinates to [0, 1]
Referenced by unitLightMVP().
◆ m_unitLightProjection
Matrix4 G3D::ShadowMap::m_unitLightProjection |
|
protected |
◆ m_vsmFinalFB
m_vsmRawFB after vertical filtering.
This is used for reading
◆ m_vsmHBlurFB
m_vsmRawFB after horizontal filtering
◆ m_vsmRawFB
m_vsmSourceDynamicLayer converted to VSM format (mean + variance) before filtering
◆ m_vsmSettings
◆ m_vsmSourceBaseLayer
Layer G3D::ShadowMap::m_vsmSourceBaseLayer |
|
protected |
For Surface::canMove() == false surfaces that want to be in the VSM.
◆ m_vsmSourceDynamicLayer
Layer G3D::ShadowMap::m_vsmSourceDynamicLayer |
|
protected |
For Surface::canMove() == true surfaces that want to be in the VSM.