ViewDependentShadowMap
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2011 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.
*/
#ifndef OSGSHADOW_VIEWDEPENDENTSHADOWMAP
#define OSGSHADOW_VIEWDEPENDENTSHADOWMAP 1
#include <osg/Camera>
#include <osg/Material>
#include <osg/MatrixTransform>
#include <osg/LightSource>
#include <osg/PolygonOffset>
#include <osgShadow/ShadowTechnique>
namespace osgShadow {
class OSGSHADOW_EXPORT ViewDependentShadowMap : public ShadowTechnique
{
public :
ViewDependentShadowMap();
ViewDependentShadowMap(const ViewDependentShadowMap& vdsm, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgShadow, ViewDependentShadowMap);
virtual void init();
virtual void update(osg::NodeVisitor& nv);
virtual void cull(osgUtil::CullVisitor& cv);
virtual void resizeGLObjectBuffers(unsigned int maxSize);
virtual void releaseGLObjects(osg::State* = 0) const;
virtual void cleanSceneGraph();
struct OSGSHADOW_EXPORT Frustum
{
Frustum(osgUtil::CullVisitor* cv, double minZNear, double maxZFar);
osg::Matrixd projectionMatrix;
osg::Matrixd modelViewMatrix;
typedef std::vector<osg::Vec3d> Vertices;
Vertices corners;
typedef std::vector<unsigned int> Indices;
typedef std::vector<Indices> Faces;
Faces faces;
typedef std::vector<Indices> Edges;
Edges edges;
osg::Vec3d eye;
osg::Vec3d centerNearPlane;
osg::Vec3d centerFarPlane;
osg::Vec3d center;
osg::Vec3d frustumCenterLine;
};
// forward declare
class ViewDependentData;
struct OSGSHADOW_EXPORT LightData : public osg::Referenced
{
LightData(ViewDependentData* vdd);
virtual void setLightData(osg::RefMatrix* lm, const osg::Light* l, const osg::Matrixd& modelViewMatrix);
ViewDependentData* _viewDependentData;
osg::ref_ptr<osg::RefMatrix> lightMatrix;
osg::ref_ptr<const osg::Light> light;
osg::Vec4d lightPos;
osg::Vec3d lightPos3;
osg::Vec3d lightDir;
bool directionalLight;
typedef std::vector<unsigned int> ActiveTextureUnits;
ActiveTextureUnits textureUnits;
};
typedef std::list< osg::ref_ptr<LightData> > LightDataList;
struct OSGSHADOW_EXPORT ShadowData : public osg::Referenced
{
ShadowData(ViewDependentData* vdd);
virtual void releaseGLObjects(osg::State* = 0) const;
ViewDependentData* _viewDependentData;
unsigned int _textureUnit;
osg::ref_ptr<osg::Texture2D> _texture;
osg::ref_ptr<osg::TexGen> _texgen;
osg::ref_ptr<osg::Camera> _camera;
};
typedef std::list< osg::ref_ptr<ShadowData> > ShadowDataList;
class OSGSHADOW_EXPORT ViewDependentData : public osg::Referenced
{
public:
ViewDependentData(ViewDependentShadowMap* vdsm);
const ViewDependentShadowMap* getViewDependentShadowMap() const { return _viewDependentShadowMap; }
LightDataList& getLightDataList() { return _lightDataList; }
ShadowDataList& getShadowDataList() { return _shadowDataList; }
osg::StateSet* getStateSet() { return _stateset.get(); }
virtual void releaseGLObjects(osg::State* = 0) const;
protected:
virtual ~ViewDependentData() {}
ViewDependentShadowMap* _viewDependentShadowMap;
osg::ref_ptr<osg::StateSet> _stateset;
LightDataList _lightDataList;
ShadowDataList _shadowDataList;
};
virtual ViewDependentData* createViewDependentData(osgUtil::CullVisitor* cv);
ViewDependentData* getViewDependentData(osgUtil::CullVisitor* cv);
virtual void createShaders();
virtual bool selectActiveLights(osgUtil::CullVisitor* cv, ViewDependentData* vdd) const;
virtual osg::Polytope computeLightViewFrustumPolytope(Frustum& frustum, LightData& positionedLight);
virtual bool computeShadowCameraSettings(Frustum& frustum, LightData& positionedLight, osg::Matrixd& projectionMatrix, osg::Matrixd& viewMatrix);
virtual bool adjustPerspectiveShadowMapCameraSettings(osgUtil::RenderStage* renderStage, Frustum& frustum, LightData& positionedLight, osg::Camera* camera);
virtual bool assignTexGenSettings(osgUtil::CullVisitor* cv, osg::Camera* camera, unsigned int textureUnit, osg::TexGen* texgen);
virtual void cullShadowReceivingScene(osgUtil::CullVisitor* cv) const;
virtual void cullShadowCastingScene(osgUtil::CullVisitor* cv, osg::Camera* camera) const;
virtual osg::StateSet* selectStateSetForRenderingShadow(ViewDependentData& vdd) const;
protected:
virtual ~ViewDependentShadowMap();
typedef std::map< osgUtil::CullVisitor*, osg::ref_ptr<ViewDependentData> > ViewDependentDataMap;
mutable OpenThreads::Mutex _viewDependentDataMapMutex;
ViewDependentDataMap _viewDependentDataMap;
osg::ref_ptr<osg::StateSet> _shadowRecievingPlaceholderStateSet;
osg::ref_ptr<osg::StateSet> _shadowCastingStateSet;
osg::ref_ptr<osg::PolygonOffset> _polygonOffset;
osg::ref_ptr<osg::Texture2D> _fallbackBaseTexture;
osg::ref_ptr<osg::Texture2D> _fallbackShadowMapTexture;
typedef std::vector< osg::ref_ptr<osg::Uniform> > Uniforms;
mutable OpenThreads::Mutex _accessUniformsAndProgramMutex;
Uniforms _uniforms;
osg::ref_ptr<osg::Program> _program;
};
}
#endif
Camera
LightSource
Material
MatrixTransform
PolygonOffset
ShadowTechnique
OpenThreads::Mutex
This class provides an object-oriented thread mutex interface.
Definition Mutex:31
osgShadow::ShadowTechnique::ShadowTechnique
ShadowTechnique()
osgShadow::ViewDependentShadowMap::ViewDependentData
Definition ViewDependentShadowMap:125
osgShadow::ViewDependentShadowMap::ViewDependentData::getShadowDataList
ShadowDataList & getShadowDataList()
Definition ViewDependentShadowMap:133
osgShadow::ViewDependentShadowMap::ViewDependentData::_lightDataList
LightDataList _lightDataList
Definition ViewDependentShadowMap:146
osgShadow::ViewDependentShadowMap::ViewDependentData::_shadowDataList
ShadowDataList _shadowDataList
Definition ViewDependentShadowMap:147
osgShadow::ViewDependentShadowMap::ViewDependentData::getViewDependentShadowMap
const ViewDependentShadowMap * getViewDependentShadowMap() const
Definition ViewDependentShadowMap:129
osgShadow::ViewDependentShadowMap::ViewDependentData::~ViewDependentData
virtual ~ViewDependentData()
Definition ViewDependentShadowMap:140
osgShadow::ViewDependentShadowMap::ViewDependentData::_viewDependentShadowMap
ViewDependentShadowMap * _viewDependentShadowMap
Definition ViewDependentShadowMap:142
osgShadow::ViewDependentShadowMap::ViewDependentData::_stateset
osg::ref_ptr< osg::StateSet > _stateset
Definition ViewDependentShadowMap:144
osgShadow::ViewDependentShadowMap::ViewDependentData::ViewDependentData
ViewDependentData(ViewDependentShadowMap *vdsm)
osgShadow::ViewDependentShadowMap::ViewDependentData::releaseGLObjects
virtual void releaseGLObjects(osg::State *=0) const
osgShadow::ViewDependentShadowMap::ViewDependentData::getStateSet
osg::StateSet * getStateSet()
Definition ViewDependentShadowMap:135
osgShadow::ViewDependentShadowMap::ViewDependentData::getLightDataList
LightDataList & getLightDataList()
Definition ViewDependentShadowMap:131
osgShadow::ViewDependentShadowMap::LightDataList
std::list< osg::ref_ptr< LightData > > LightDataList
Definition ViewDependentShadowMap:105
osgShadow::ViewDependentShadowMap::cleanSceneGraph
virtual void cleanSceneGraph()
osgShadow::ViewDependentShadowMap::computeShadowCameraSettings
virtual bool computeShadowCameraSettings(Frustum &frustum, LightData &positionedLight, osg::Matrixd &projectionMatrix, osg::Matrixd &viewMatrix)
osgShadow::ViewDependentShadowMap::adjustPerspectiveShadowMapCameraSettings
virtual bool adjustPerspectiveShadowMapCameraSettings(osgUtil::RenderStage *renderStage, Frustum &frustum, LightData &positionedLight, osg::Camera *camera)
osgShadow::ViewDependentShadowMap::META_Object
META_Object(osgShadow, ViewDependentShadowMap)
osgShadow::ViewDependentShadowMap::ViewDependentShadowMap
ViewDependentShadowMap(const ViewDependentShadowMap &vdsm, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
osgShadow::ViewDependentShadowMap::ShadowDataList
std::list< osg::ref_ptr< ShadowData > > ShadowDataList
Definition ViewDependentShadowMap:121
osgShadow::ViewDependentShadowMap::_viewDependentDataMap
ViewDependentDataMap _viewDependentDataMap
Definition ViewDependentShadowMap:179
osgShadow::ViewDependentShadowMap::getViewDependentData
ViewDependentData * getViewDependentData(osgUtil::CullVisitor *cv)
osgShadow::ViewDependentShadowMap::selectStateSetForRenderingShadow
virtual osg::StateSet * selectStateSetForRenderingShadow(ViewDependentData &vdd) const
osgShadow::ViewDependentShadowMap::_shadowRecievingPlaceholderStateSet
osg::ref_ptr< osg::StateSet > _shadowRecievingPlaceholderStateSet
Definition ViewDependentShadowMap:181
osgShadow::ViewDependentShadowMap::computeLightViewFrustumPolytope
virtual osg::Polytope computeLightViewFrustumPolytope(Frustum &frustum, LightData &positionedLight)
osgShadow::ViewDependentShadowMap::resizeGLObjectBuffers
virtual void resizeGLObjectBuffers(unsigned int maxSize)
osgShadow::ViewDependentShadowMap::createShaders
virtual void createShaders()
osgShadow::ViewDependentShadowMap::_uniforms
Uniforms _uniforms
Definition ViewDependentShadowMap:190
osgShadow::ViewDependentShadowMap::_fallbackShadowMapTexture
osg::ref_ptr< osg::Texture2D > _fallbackShadowMapTexture
Definition ViewDependentShadowMap:186
osgShadow::ViewDependentShadowMap::assignTexGenSettings
virtual bool assignTexGenSettings(osgUtil::CullVisitor *cv, osg::Camera *camera, unsigned int textureUnit, osg::TexGen *texgen)
osgShadow::ViewDependentShadowMap::ViewDependentShadowMap
ViewDependentShadowMap()
osgShadow::ViewDependentShadowMap::_viewDependentDataMapMutex
OpenThreads::Mutex _viewDependentDataMapMutex
Definition ViewDependentShadowMap:178
osgShadow::ViewDependentShadowMap::~ViewDependentShadowMap
virtual ~ViewDependentShadowMap()
osgShadow::ViewDependentShadowMap::update
virtual void update(osg::NodeVisitor &nv)
osgShadow::ViewDependentShadowMap::init
virtual void init()
osgShadow::ViewDependentShadowMap::_polygonOffset
osg::ref_ptr< osg::PolygonOffset > _polygonOffset
Definition ViewDependentShadowMap:184
osgShadow::ViewDependentShadowMap::_accessUniformsAndProgramMutex
OpenThreads::Mutex _accessUniformsAndProgramMutex
Definition ViewDependentShadowMap:189
osgShadow::ViewDependentShadowMap::cullShadowReceivingScene
virtual void cullShadowReceivingScene(osgUtil::CullVisitor *cv) const
osgShadow::ViewDependentShadowMap::_program
osg::ref_ptr< osg::Program > _program
Definition ViewDependentShadowMap:191
osgShadow::ViewDependentShadowMap::releaseGLObjects
virtual void releaseGLObjects(osg::State *=0) const
osgShadow::ViewDependentShadowMap::_shadowCastingStateSet
osg::ref_ptr< osg::StateSet > _shadowCastingStateSet
Definition ViewDependentShadowMap:183
osgShadow::ViewDependentShadowMap::createViewDependentData
virtual ViewDependentData * createViewDependentData(osgUtil::CullVisitor *cv)
osgShadow::ViewDependentShadowMap::ViewDependentDataMap
std::map< osgUtil::CullVisitor *, osg::ref_ptr< ViewDependentData > > ViewDependentDataMap
Definition ViewDependentShadowMap:177
osgShadow::ViewDependentShadowMap::cullShadowCastingScene
virtual void cullShadowCastingScene(osgUtil::CullVisitor *cv, osg::Camera *camera) const
osgShadow::ViewDependentShadowMap::Uniforms
std::vector< osg::ref_ptr< osg::Uniform > > Uniforms
Definition ViewDependentShadowMap:188
osgShadow::ViewDependentShadowMap::_fallbackBaseTexture
osg::ref_ptr< osg::Texture2D > _fallbackBaseTexture
Definition ViewDependentShadowMap:185
osgShadow::ViewDependentShadowMap::selectActiveLights
virtual bool selectActiveLights(osgUtil::CullVisitor *cv, ViewDependentData *vdd) const
osgShadow::ViewDependentShadowMap::cull
virtual void cull(osgUtil::CullVisitor &cv)
osgUtil::CullVisitor
Definition CullVisitor:49
osgUtil::RenderStage
Definition RenderStage:38
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::NodeVisitor
Definition NodeVisitor:82
osg::Polytope
Definition Polytope:26
osg::Referenced
Definition Referenced:44
osg::StateSet
Definition StateSet:46
osg::State
Definition State:80
osg::TexGen
Definition TexGen:43
osg::Vec3d
Definition Vec3d:30
osg::Vec4d
Definition Vec4d:29
osg::ref_ptr
Definition ref_ptr:32
osgShadow
Definition ConvexPolyhedron:33
osg::RefMatrix
RefMatrixd RefMatrix
Definition Matrix:28
OSGSHADOW_EXPORT
#define OSGSHADOW_EXPORT
Definition osgShadow/Export:39
osgShadow::ViewDependentShadowMap::Frustum
Definition ViewDependentShadowMap:59
osgShadow::ViewDependentShadowMap::Frustum::Edges
std::vector< Indices > Edges
Definition ViewDependentShadowMap:72
osgShadow::ViewDependentShadowMap::Frustum::edges
Edges edges
Definition ViewDependentShadowMap:73
osgShadow::ViewDependentShadowMap::Frustum::centerFarPlane
osg::Vec3d centerFarPlane
Definition ViewDependentShadowMap:77
osgShadow::ViewDependentShadowMap::Frustum::corners
Vertices corners
Definition ViewDependentShadowMap:66
osgShadow::ViewDependentShadowMap::Frustum::faces
Faces faces
Definition ViewDependentShadowMap:70
osgShadow::ViewDependentShadowMap::Frustum::centerNearPlane
osg::Vec3d centerNearPlane
Definition ViewDependentShadowMap:76
osgShadow::ViewDependentShadowMap::Frustum::Faces
std::vector< Indices > Faces
Definition ViewDependentShadowMap:69
osgShadow::ViewDependentShadowMap::Frustum::projectionMatrix
osg::Matrixd projectionMatrix
Definition ViewDependentShadowMap:62
osgShadow::ViewDependentShadowMap::Frustum::Vertices
std::vector< osg::Vec3d > Vertices
Definition ViewDependentShadowMap:65
osgShadow::ViewDependentShadowMap::Frustum::Frustum
Frustum(osgUtil::CullVisitor *cv, double minZNear, double maxZFar)
osgShadow::ViewDependentShadowMap::Frustum::modelViewMatrix
osg::Matrixd modelViewMatrix
Definition ViewDependentShadowMap:63
osgShadow::ViewDependentShadowMap::Frustum::frustumCenterLine
osg::Vec3d frustumCenterLine
Definition ViewDependentShadowMap:79
osgShadow::ViewDependentShadowMap::Frustum::Indices
std::vector< unsigned int > Indices
Definition ViewDependentShadowMap:68
osgShadow::ViewDependentShadowMap::Frustum::center
osg::Vec3d center
Definition ViewDependentShadowMap:78
osgShadow::ViewDependentShadowMap::Frustum::eye
osg::Vec3d eye
Definition ViewDependentShadowMap:75
osgShadow::ViewDependentShadowMap::LightData
Definition ViewDependentShadowMap:86
osgShadow::ViewDependentShadowMap::LightData::ActiveTextureUnits
std::vector< unsigned int > ActiveTextureUnits
Definition ViewDependentShadowMap:101
osgShadow::ViewDependentShadowMap::LightData::lightPos3
osg::Vec3d lightPos3
Definition ViewDependentShadowMap:97
osgShadow::ViewDependentShadowMap::LightData::light
osg::ref_ptr< const osg::Light > light
Definition ViewDependentShadowMap:94
osgShadow::ViewDependentShadowMap::LightData::directionalLight
bool directionalLight
Definition ViewDependentShadowMap:99
osgShadow::ViewDependentShadowMap::LightData::lightPos
osg::Vec4d lightPos
Definition ViewDependentShadowMap:96
osgShadow::ViewDependentShadowMap::LightData::textureUnits
ActiveTextureUnits textureUnits
Definition ViewDependentShadowMap:102
osgShadow::ViewDependentShadowMap::LightData::LightData
LightData(ViewDependentData *vdd)
osgShadow::ViewDependentShadowMap::LightData::_viewDependentData
ViewDependentData * _viewDependentData
Definition ViewDependentShadowMap:91
osgShadow::ViewDependentShadowMap::LightData::lightDir
osg::Vec3d lightDir
Definition ViewDependentShadowMap:98
osgShadow::ViewDependentShadowMap::LightData::setLightData
virtual void setLightData(osg::RefMatrix *lm, const osg::Light *l, const osg::Matrixd &modelViewMatrix)
osgShadow::ViewDependentShadowMap::LightData::lightMatrix
osg::ref_ptr< osg::RefMatrix > lightMatrix
Definition ViewDependentShadowMap:93
osgShadow::ViewDependentShadowMap::ShadowData::_camera
osg::ref_ptr< osg::Camera > _camera
Definition ViewDependentShadowMap:118
osgShadow::ViewDependentShadowMap::ShadowData::_texgen
osg::ref_ptr< osg::TexGen > _texgen
Definition ViewDependentShadowMap:117
osgShadow::ViewDependentShadowMap::ShadowData::_textureUnit
unsigned int _textureUnit
Definition ViewDependentShadowMap:115
osgShadow::ViewDependentShadowMap::ShadowData::releaseGLObjects
virtual void releaseGLObjects(osg::State *=0) const
osgShadow::ViewDependentShadowMap::ShadowData::_viewDependentData
ViewDependentData * _viewDependentData
Definition ViewDependentShadowMap:113
osgShadow::ViewDependentShadowMap::ShadowData::ShadowData
ShadowData(ViewDependentData *vdd)
osgShadow::ViewDependentShadowMap::ShadowData::_texture
osg::ref_ptr< osg::Texture2D > _texture
Definition ViewDependentShadowMap:116