MinimalShadowMap
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*
* ViewDependentShadow codes Copyright (C) 2008 Wojciech Lewandowski
* Thanks to to my company http://www.ai.com.pl for allowing me free this work.
*/
#ifndef OSGSHADOW_MINIMALSHADOWMAP
#define OSGSHADOW_MINIMALSHADOWMAP 1
#include <osgShadow/StandardShadowMap>
namespace osgShadow {
class OSGSHADOW_EXPORT MinimalShadowMap : public StandardShadowMap
{
public :
typedef MinimalShadowMap ThisClass;
typedef StandardShadowMap BaseClass;
MinimalShadowMap();
MinimalShadowMap(
const MinimalShadowMap& msm,
const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object( osgShadow, MinimalShadowMap );
void setModellingSpaceToWorldTransform( const osg::Matrix & modellingSpaceToWorld )
{ _modellingSpaceToWorld = modellingSpaceToWorld; }
const osg::Matrix & getModellingSpaceToWorldTransform( void ) const
{ return _modellingSpaceToWorld; }
float getMaxFarPlane( ) const
{ return _maxFarPlane; }
void setMaxFarPlane( float maxFarPlane )
{ _maxFarPlane = maxFarPlane; }
float getMinLightMargin( ) const
{ return _minLightMargin; }
void setMinLightMargin( float minLightMargin )
{ _minLightMargin = minLightMargin; }
enum ShadowReceivingCoarseBoundAccuracy {
EMPTY_BOX,
BOUNDING_SPHERE,
BOUNDING_BOX,
DEFAULT_ACCURACY = BOUNDING_BOX
};
void setShadowReceivingCoarseBoundAccuracy
( ShadowReceivingCoarseBoundAccuracy accuracy )
{ _shadowReceivingCoarseBoundAccuracy = accuracy; }
ShadowReceivingCoarseBoundAccuracy
getShadowReceivingCoarseBoundAccuracy() const
{ return _shadowReceivingCoarseBoundAccuracy; }
protected:
virtual ~MinimalShadowMap(void);
protected:
// Matrix modellingSpaceToWorld and its inverse
// are used to define Modelling Space where shadowed scene drawables
// have minimal (smallest possible extent) bounding boxes.
// Computing visible shadow range in this space
// allows for optimal use of ShadowMap resolution.
// By default it is set to identity ie computations are in world space.
// But it should be set to ElipsoidModel::localToWorld
// when scene objects are put on earth ellipsoid surface.
// Other scenarios are also possible for example when models are
// built in XZY space which would require identity matrix with swapped columns
osg::Matrix _modellingSpaceToWorld;
float _maxFarPlane;
float _minLightMargin;
ShadowReceivingCoarseBoundAccuracy _shadowReceivingCoarseBoundAccuracy;
struct OSGSHADOW_EXPORT ViewData: public BaseClass::ViewData
{
osg::Matrix *_modellingSpaceToWorldPtr;
float *_maxFarPlanePtr;
float *_minLightMarginPtr;
int _frameShadowCastingCameraPasses;
ConvexPolyhedron _sceneReceivingShadowPolytope;
std::vector< osg::Vec3d > _sceneReceivingShadowPolytopePoints;
osg::Matrixd _clampedProjection;
virtual void init( ThisClass * st, osgUtil::CullVisitor * cv );
virtual osg::BoundingBox computeShadowReceivingCoarseBounds( );
virtual void cullShadowReceivingScene( );
virtual void aimShadowCastingCamera(
const osg::BoundingSphere &bounds,
const osg::Light *light,
const osg::Vec4 &worldLightPos,
const osg::Vec3 &worldLightDir,
const osg::Vec3 &worldLightUp = osg::Vec3(0,1,0) );
virtual void aimShadowCastingCamera( const osg::Light *light,
const osg::Vec4 &worldLightPos,
const osg::Vec3 &worldLightDir,
const osg::Vec3 &worldLightUp
= osg::Vec3(0,1,0) );
virtual void frameShadowCastingCamera
( const osg::Camera* cameraMain, osg::Camera* cameraShadow, int pass = 1 );
void cutScenePolytope( const osg::Matrix & matrix,
const osg::Matrix & inverse,
const osg::BoundingBox &bb =
osg::BoundingBox(-1,-1,-1,1,1,1) );
osg::BoundingBox computeScenePolytopeBounds();
osg::BoundingBox computeScenePolytopeBounds(const osg::Matrix& m);
// Utility methods for adjusting projection matrices
// Modify projection matrix so that some output subrange
// is remapped to whole clip space (-1..1,-1..1,-1..1).
// Bit mask can be used to limit remaping to selected bounds only.
static void trimProjection
( osg::Matrixd & projection, osg::BoundingBox subrange,
unsigned int trimMask = (1|2|4|8|16|32)
/*1=left|2=right|4=bottom|8=top|16=near|32=far*/);
static void clampProjection
( osg::Matrixd & projection, float n = 0, float f = FLT_MAX );
static void extendProjection
( osg::Matrixd & projection, osg::Viewport * viewport, const osg::Vec2& margin );
};
META_ViewDependentShadowTechniqueData( ThisClass, ThisClass::ViewData )
};
} // namespace osgShadow
#endif
StandardShadowMap
META_ViewDependentShadowTechniqueData
#define META_ViewDependentShadowTechniqueData(ShadowTechnique, TechniqueData)
Definition ViewDependentShadowTechnique:32
osgShadow::ConvexPolyhedron
Definition ConvexPolyhedron:36
osgShadow::MinimalShadowMap::MinimalShadowMap
MinimalShadowMap(const MinimalShadowMap &msm, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
osgShadow::MinimalShadowMap::getModellingSpaceToWorldTransform
const osg::Matrix & getModellingSpaceToWorldTransform(void) const
Definition MinimalShadowMap:46
osgShadow::MinimalShadowMap::BaseClass
StandardShadowMap BaseClass
Definition MinimalShadowMap:30
osgShadow::MinimalShadowMap::_shadowReceivingCoarseBoundAccuracy
ShadowReceivingCoarseBoundAccuracy _shadowReceivingCoarseBoundAccuracy
Definition MinimalShadowMap:98
osgShadow::MinimalShadowMap::setMaxFarPlane
void setMaxFarPlane(float maxFarPlane)
Definition MinimalShadowMap:52
osgShadow::MinimalShadowMap::~MinimalShadowMap
virtual ~MinimalShadowMap(void)
osgShadow::MinimalShadowMap::getShadowReceivingCoarseBoundAccuracy
ShadowReceivingCoarseBoundAccuracy getShadowReceivingCoarseBoundAccuracy() const
Definition MinimalShadowMap:73
osgShadow::MinimalShadowMap::setMinLightMargin
void setMinLightMargin(float minLightMargin)
Definition MinimalShadowMap:58
osgShadow::MinimalShadowMap::_minLightMargin
float _minLightMargin
Definition MinimalShadowMap:97
osgShadow::MinimalShadowMap::_maxFarPlane
float _maxFarPlane
Definition MinimalShadowMap:96
osgShadow::MinimalShadowMap::ShadowReceivingCoarseBoundAccuracy
ShadowReceivingCoarseBoundAccuracy
Definition MinimalShadowMap:61
osgShadow::MinimalShadowMap::BOUNDING_BOX
@ BOUNDING_BOX
Definition MinimalShadowMap:64
osgShadow::MinimalShadowMap::EMPTY_BOX
@ EMPTY_BOX
Definition MinimalShadowMap:62
osgShadow::MinimalShadowMap::DEFAULT_ACCURACY
@ DEFAULT_ACCURACY
Definition MinimalShadowMap:65
osgShadow::MinimalShadowMap::BOUNDING_SPHERE
@ BOUNDING_SPHERE
Definition MinimalShadowMap:63
osgShadow::MinimalShadowMap::MinimalShadowMap
MinimalShadowMap()
osgShadow::MinimalShadowMap::getMinLightMargin
float getMinLightMargin() const
Definition MinimalShadowMap:55
osgShadow::MinimalShadowMap::setShadowReceivingCoarseBoundAccuracy
void setShadowReceivingCoarseBoundAccuracy(ShadowReceivingCoarseBoundAccuracy accuracy)
Definition MinimalShadowMap:69
osgShadow::MinimalShadowMap::_modellingSpaceToWorld
osg::Matrix _modellingSpaceToWorld
Definition MinimalShadowMap:95
osgShadow::MinimalShadowMap::META_Object
META_Object(osgShadow, MinimalShadowMap)
osgShadow::MinimalShadowMap::setModellingSpaceToWorldTransform
void setModellingSpaceToWorldTransform(const osg::Matrix &modellingSpaceToWorld)
Definition MinimalShadowMap:43
osgShadow::MinimalShadowMap::ThisClass
MinimalShadowMap ThisClass
Definition MinimalShadowMap:28
osgShadow::MinimalShadowMap::getMaxFarPlane
float getMaxFarPlane() const
Definition MinimalShadowMap:49
osgShadow::StandardShadowMap::StandardShadowMap
StandardShadowMap()
osgUtil::CullVisitor
Definition CullVisitor:49
osg::Camera
Definition Camera:45
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Light
Definition Light:40
osg::Matrixd
Definition Matrixd:27
osg::Viewport
Definition Viewport:24
osgShadow
Definition ConvexPolyhedron:33
osg::Vec2
Vec2f Vec2
Definition Vec2:21
osg::Vec3
Vec3f Vec3
Definition Vec3:21
osg::BoundingBox
BoundingBoxd BoundingBox
Definition BoundingBox:257
osg::BoundingSphere
BoundingSphered BoundingSphere
Definition BoundingSphere:314
osg::Matrix
Matrixd Matrix
Definition Matrix:27
osg::Vec4
Vec4f Vec4
Definition Vec4:21
OSGSHADOW_EXPORT
#define OSGSHADOW_EXPORT
Definition osgShadow/Export:39
osgShadow::MinimalShadowMap::ViewData
Definition MinimalShadowMap:101
osgShadow::MinimalShadowMap::ViewData::_clampedProjection
osg::Matrixd _clampedProjection
Definition MinimalShadowMap:110
osgShadow::MinimalShadowMap::ViewData::_modellingSpaceToWorldPtr
osg::Matrix * _modellingSpaceToWorldPtr
Definition MinimalShadowMap:102
osgShadow::MinimalShadowMap::ViewData::aimShadowCastingCamera
virtual void aimShadowCastingCamera(const osg::BoundingSphere &bounds, const osg::Light *light, const osg::Vec4 &worldLightPos, const osg::Vec3 &worldLightDir, const osg::Vec3 &worldLightUp=osg::Vec3(0, 1, 0))
osgShadow::MinimalShadowMap::ViewData::_frameShadowCastingCameraPasses
int _frameShadowCastingCameraPasses
Definition MinimalShadowMap:105
osgShadow::MinimalShadowMap::ViewData::computeScenePolytopeBounds
osg::BoundingBox computeScenePolytopeBounds(const osg::Matrix &m)
osgShadow::MinimalShadowMap::ViewData::_sceneReceivingShadowPolytope
ConvexPolyhedron _sceneReceivingShadowPolytope
Definition MinimalShadowMap:107
osgShadow::MinimalShadowMap::ViewData::extendProjection
static void extendProjection(osg::Matrixd &projection, osg::Viewport *viewport, const osg::Vec2 &margin)
osgShadow::MinimalShadowMap::ViewData::cullShadowReceivingScene
virtual void cullShadowReceivingScene()
osgShadow::MinimalShadowMap::ViewData::init
virtual void init(ThisClass *st, osgUtil::CullVisitor *cv)
osgShadow::MinimalShadowMap::ViewData::_maxFarPlanePtr
float * _maxFarPlanePtr
Definition MinimalShadowMap:103
osgShadow::MinimalShadowMap::ViewData::computeScenePolytopeBounds
osg::BoundingBox computeScenePolytopeBounds()
osgShadow::MinimalShadowMap::ViewData::_sceneReceivingShadowPolytopePoints
std::vector< osg::Vec3d > _sceneReceivingShadowPolytopePoints
Definition MinimalShadowMap:108
osgShadow::MinimalShadowMap::ViewData::computeShadowReceivingCoarseBounds
virtual osg::BoundingBox computeShadowReceivingCoarseBounds()
osgShadow::MinimalShadowMap::ViewData::frameShadowCastingCamera
virtual void frameShadowCastingCamera(const osg::Camera *cameraMain, osg::Camera *cameraShadow, int pass=1)
osgShadow::MinimalShadowMap::ViewData::_minLightMarginPtr
float * _minLightMarginPtr
Definition MinimalShadowMap:104
osgShadow::MinimalShadowMap::ViewData::clampProjection
static void clampProjection(osg::Matrixd &projection, float n=0, float f=FLT_MAX)
osgShadow::MinimalShadowMap::ViewData::cutScenePolytope
void cutScenePolytope(const osg::Matrix &matrix, const osg::Matrix &inverse, const osg::BoundingBox &bb=osg::BoundingBox(-1,-1,-1, 1, 1, 1))
osgShadow::MinimalShadowMap::ViewData::aimShadowCastingCamera
virtual void aimShadowCastingCamera(const osg::Light *light, const osg::Vec4 &worldLightPos, const osg::Vec3 &worldLightDir, const osg::Vec3 &worldLightUp=osg::Vec3(0, 1, 0))
osgShadow::MinimalShadowMap::ViewData::trimProjection
static void trimProjection(osg::Matrixd &projection, osg::BoundingBox subrange, unsigned int trimMask=(1|2|4|8|16|32))
osgShadow::StandardShadowMap::ViewData
Definition StandardShadowMap:161