DebugShadowMap
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_DEBUGSHADOWMAP
#define OSGSHADOW_DEBUGSHADOWMAP 1
#include <osgShadow/ViewDependentShadowTechnique>
#include <osgShadow/ConvexPolyhedron>
#include <osg/MatrixTransform>
#include <osg/Geode>
#include <osg/Geometry>
#include <string>
#include <map>
namespace osgShadow {
class OSGSHADOW_EXPORT DebugShadowMap : public ViewDependentShadowTechnique
{
public :
/*
All classes stemming from ViewDependentShadowTechnique follow the same pattern.
They are always based on some underlying level base Technique and they always
derive their ViewData from ViewData structure defined in underlying base Technique.
I use some typedefs to make these inheritance patterns easier to declare/define.
*/
typedef DebugShadowMap ThisClass;
typedef ViewDependentShadowTechnique BaseClass;
DebugShadowMap();
DebugShadowMap(const DebugShadowMap& dsm, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object( osgShadow, DebugShadowMap );
void setDebugDraw( bool draw ) { _doDebugDraw = draw; }
bool getDebugDraw( void ) const { return _doDebugDraw; }
std::string getDebugDump( void ) const { return _debugDump; }
void setDebugDump( const std::string & debugDumpFile ) { _debugDump = debugDumpFile; }
virtual void resizeGLObjectBuffers(unsigned int maxSize);
virtual void releaseGLObjects(osg::State* = 0) const;
protected:
virtual ~DebugShadowMap();
// forward declare, interface and implementation provided in DebugShadowMap.cpp
class DrawableDrawWithDepthShadowComparisonOffCallback;
osg::Vec2s _hudSize;
osg::Vec2s _hudOrigin;
osg::Vec2s _viewportSize;
osg::Vec2s _viewportOrigin;
osg::Vec2s _orthoSize;
osg::Vec2s _orthoOrigin;
bool _doDebugDraw;
std::string _debugDump;
osg::ref_ptr< osg::Shader > _depthColorFragmentShader;
struct OSGSHADOW_EXPORT ViewData: public BaseClass::ViewData
{
osg::ref_ptr< osg::Texture > _texture;
osg::ref_ptr< osg::Camera > _camera;
osg::Matrixd _viewProjection;
osg::observer_ptr<osg::Camera> _viewCamera;
// Debug hud variables
osg::ref_ptr< osg::Shader > _depthColorFragmentShader;
struct PolytopeGeometry {
ConvexPolyhedron _polytope;
osg::ref_ptr< osg::Geometry > _geometry[2];
osg::Vec4 _colorOutline;
osg::Vec4 _colorInside;
};
typedef std::map< std::string, PolytopeGeometry > PolytopeGeometryMap;
osg::Vec2s _hudSize;
osg::Vec2s _hudOrigin;
osg::Vec2s _viewportSize;
osg::Vec2s _viewportOrigin;
osg::Vec2s _orthoSize;
osg::Vec2s _orthoOrigin;
bool *_doDebugDrawPtr;
std::string *_debugDumpPtr;
PolytopeGeometryMap _polytopeGeometryMap;
osg::ref_ptr< osg::Geode > _geode[2];
osg::ref_ptr< osg::MatrixTransform > _transform[2];
std::map< std::string, osg::Matrix > _matrixMap;
std::map< std::string, osg::Polytope > _polytopeMap;
std::map< std::string, osg::BoundingBox > _boundingBoxMap;
osg::ref_ptr<osg::Camera> _cameraDebugHUD;
bool getDebugDraw() { return *_doDebugDrawPtr; }
std::string * getDebugDump() { return _debugDumpPtr; }
virtual void init( ThisClass * st, osgUtil::CullVisitor * cv );
virtual void cull( );
virtual void createDebugHUD( void );
virtual void cullDebugGeometry( );
virtual void updateDebugGeometry( const osg::Camera * screenCam,
const osg::Camera * shadowCam );
void setDebugPolytope( const char * name,
const ConvexPolyhedron & polytope = *(ConvexPolyhedron*)( NULL ),
osg::Vec4 colorOutline = osg::Vec4(0,0,0,0),
osg::Vec4 colorInside = osg::Vec4(0,0,0,0) );
bool DebugBoundingBox( const osg::BoundingBox & bb, const char * name = "" );
bool DebugPolytope( const osg::Polytope & p, const char * name = "" );
bool DebugMatrix( const osg::Matrix & m, const char * name = "" );
static osg::Vec3d computeShadowTexelToPixelError
( const osg::Matrix & mvpwView,
const osg::Matrix & mvpwShadow,
const osg::Vec3d & vWorld,
const osg::Vec3d & vDelta = osg::Vec3d( 0.01,0.01,0.01 ) );
static void displayShadowTexelToPixelErrors
( const osg::Camera * viewCam,
const osg::Camera * shadowCam,
const ConvexPolyhedron * hull );
void dump( const std::string & filename );
virtual void resizeGLObjectBuffers(unsigned int maxSize);
virtual void releaseGLObjects(osg::State* = 0) const;
};
META_ViewDependentShadowTechniqueData( ThisClass, ViewData )
};
} // namespace osgShadow
#endif
ConvexPolyhedron
Geode
Geometry
MatrixTransform
ViewDependentShadowTechnique
META_ViewDependentShadowTechniqueData
#define META_ViewDependentShadowTechniqueData(ShadowTechnique, TechniqueData)
Definition ViewDependentShadowTechnique:32
osgShadow::ConvexPolyhedron
Definition ConvexPolyhedron:36
osgShadow::DebugShadowMap::getDebugDraw
bool getDebugDraw(void) const
Definition DebugShadowMap:72
osgShadow::DebugShadowMap::_orthoOrigin
osg::Vec2s _orthoOrigin
Definition DebugShadowMap:101
osgShadow::DebugShadowMap::BaseClass
ViewDependentShadowTechnique BaseClass
Definition DebugShadowMap:57
osgShadow::DebugShadowMap::_orthoSize
osg::Vec2s _orthoSize
Definition DebugShadowMap:100
osgShadow::DebugShadowMap::getDebugDump
std::string getDebugDump(void) const
Definition DebugShadowMap:75
osgShadow::DebugShadowMap::META_Object
META_Object(osgShadow, DebugShadowMap)
osgShadow::DebugShadowMap::_doDebugDraw
bool _doDebugDraw
Definition DebugShadowMap:103
osgShadow::DebugShadowMap::_viewportSize
osg::Vec2s _viewportSize
Definition DebugShadowMap:98
osgShadow::DebugShadowMap::setDebugDump
void setDebugDump(const std::string &debugDumpFile)
Definition DebugShadowMap:78
osgShadow::DebugShadowMap::ThisClass
DebugShadowMap ThisClass
Definition DebugShadowMap:55
osgShadow::DebugShadowMap::setDebugDraw
void setDebugDraw(bool draw)
Definition DebugShadowMap:69
osgShadow::DebugShadowMap::_debugDump
std::string _debugDump
Definition DebugShadowMap:104
osgShadow::DebugShadowMap::resizeGLObjectBuffers
virtual void resizeGLObjectBuffers(unsigned int maxSize)
osgShadow::DebugShadowMap::releaseGLObjects
virtual void releaseGLObjects(osg::State *=0) const
osgShadow::DebugShadowMap::DebugShadowMap
DebugShadowMap()
osgShadow::DebugShadowMap::_viewportOrigin
osg::Vec2s _viewportOrigin
Definition DebugShadowMap:99
osgShadow::DebugShadowMap::DebugShadowMap
DebugShadowMap(const DebugShadowMap &dsm, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
osgShadow::DebugShadowMap::~DebugShadowMap
virtual ~DebugShadowMap()
osgShadow::DebugShadowMap::_hudOrigin
osg::Vec2s _hudOrigin
Definition DebugShadowMap:97
osgShadow::DebugShadowMap::_hudSize
osg::Vec2s _hudSize
Definition DebugShadowMap:96
osgShadow::DebugShadowMap::_depthColorFragmentShader
osg::ref_ptr< osg::Shader > _depthColorFragmentShader
Definition DebugShadowMap:106
osgShadow::ViewDependentShadowTechnique::ViewDependentShadowTechnique
ViewDependentShadowTechnique(void)
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::Matrixd
Definition Matrixd:27
osg::Polytope
Definition Polytope:26
osg::State
Definition State:80
osg::Vec2s
Definition Vec2s:20
osg::Vec3d
Definition Vec3d:30
osg::observer_ptr
Definition observer_ptr:39
osg::ref_ptr< osg::Shader >
osgShadow
Definition ConvexPolyhedron:33
osg::BoundingBox
BoundingBoxd BoundingBox
Definition BoundingBox:257
osg::Matrix
Matrixd Matrix
Definition Matrix:27
osg::Vec4
Vec4f Vec4
Definition Vec4:21
OSGSHADOW_EXPORT
#define OSGSHADOW_EXPORT
Definition osgShadow/Export:39
NULL
#define NULL
Definition osg/Export:55
osgShadow::DebugShadowMap::ViewData::PolytopeGeometry
Definition DebugShadowMap:129
osgShadow::DebugShadowMap::ViewData::PolytopeGeometry::_geometry
osg::ref_ptr< osg::Geometry > _geometry[2]
Definition DebugShadowMap:132
osgShadow::DebugShadowMap::ViewData::PolytopeGeometry::_polytope
ConvexPolyhedron _polytope
Definition DebugShadowMap:131
osgShadow::DebugShadowMap::ViewData::PolytopeGeometry::_colorOutline
osg::Vec4 _colorOutline
Definition DebugShadowMap:133
osgShadow::DebugShadowMap::ViewData::PolytopeGeometry::_colorInside
osg::Vec4 _colorInside
Definition DebugShadowMap:134
osgShadow::DebugShadowMap::ViewData
Definition DebugShadowMap:109
osgShadow::DebugShadowMap::ViewData::_cameraDebugHUD
osg::ref_ptr< osg::Camera > _cameraDebugHUD
Definition DebugShadowMap:157
osgShadow::DebugShadowMap::ViewData::getDebugDump
std::string * getDebugDump()
Definition DebugShadowMap:160
osgShadow::DebugShadowMap::ViewData::releaseGLObjects
virtual void releaseGLObjects(osg::State *=0) const
osgShadow::DebugShadowMap::ViewData::cullDebugGeometry
virtual void cullDebugGeometry()
osgShadow::DebugShadowMap::ViewData::_viewProjection
osg::Matrixd _viewProjection
Definition DebugShadowMap:121
osgShadow::DebugShadowMap::ViewData::dump
void dump(const std::string &filename)
osgShadow::DebugShadowMap::ViewData::getDebugDraw
bool getDebugDraw()
Definition DebugShadowMap:159
osgShadow::DebugShadowMap::ViewData::_hudOrigin
osg::Vec2s _hudOrigin
Definition DebugShadowMap:140
osgShadow::DebugShadowMap::ViewData::DebugMatrix
bool DebugMatrix(const osg::Matrix &m, const char *name="")
osgShadow::DebugShadowMap::ViewData::_geode
osg::ref_ptr< osg::Geode > _geode[2]
Definition DebugShadowMap:150
osgShadow::DebugShadowMap::ViewData::_boundingBoxMap
std::map< std::string, osg::BoundingBox > _boundingBoxMap
Definition DebugShadowMap:155
osgShadow::DebugShadowMap::ViewData::displayShadowTexelToPixelErrors
static void displayShadowTexelToPixelErrors(const osg::Camera *viewCam, const osg::Camera *shadowCam, const ConvexPolyhedron *hull)
osgShadow::DebugShadowMap::ViewData::_camera
osg::ref_ptr< osg::Camera > _camera
Definition DebugShadowMap:119
osgShadow::DebugShadowMap::ViewData::cull
virtual void cull()
osgShadow::DebugShadowMap::ViewData::_orthoOrigin
osg::Vec2s _orthoOrigin
Definition DebugShadowMap:144
osgShadow::DebugShadowMap::ViewData::_hudSize
osg::Vec2s _hudSize
Definition DebugShadowMap:139
osgShadow::DebugShadowMap::ViewData::_orthoSize
osg::Vec2s _orthoSize
Definition DebugShadowMap:143
osgShadow::DebugShadowMap::ViewData::_polytopeGeometryMap
PolytopeGeometryMap _polytopeGeometryMap
Definition DebugShadowMap:149
osgShadow::DebugShadowMap::ViewData::_viewCamera
osg::observer_ptr< osg::Camera > _viewCamera
Definition DebugShadowMap:122
osgShadow::DebugShadowMap::ViewData::_matrixMap
std::map< std::string, osg::Matrix > _matrixMap
Definition DebugShadowMap:153
osgShadow::DebugShadowMap::ViewData::PolytopeGeometryMap
std::map< std::string, PolytopeGeometry > PolytopeGeometryMap
Definition DebugShadowMap:137
osgShadow::DebugShadowMap::ViewData::DebugBoundingBox
bool DebugBoundingBox(const osg::BoundingBox &bb, const char *name="")
osgShadow::DebugShadowMap::ViewData::_polytopeMap
std::map< std::string, osg::Polytope > _polytopeMap
Definition DebugShadowMap:154
osgShadow::DebugShadowMap::ViewData::computeShadowTexelToPixelError
static osg::Vec3d computeShadowTexelToPixelError(const osg::Matrix &mvpwView, const osg::Matrix &mvpwShadow, const osg::Vec3d &vWorld, const osg::Vec3d &vDelta=osg::Vec3d(0.01, 0.01, 0.01))
osgShadow::DebugShadowMap::ViewData::resizeGLObjectBuffers
virtual void resizeGLObjectBuffers(unsigned int maxSize)
osgShadow::DebugShadowMap::ViewData::createDebugHUD
virtual void createDebugHUD(void)
osgShadow::DebugShadowMap::ViewData::_viewportOrigin
osg::Vec2s _viewportOrigin
Definition DebugShadowMap:142
osgShadow::DebugShadowMap::ViewData::init
virtual void init(ThisClass *st, osgUtil::CullVisitor *cv)
osgShadow::DebugShadowMap::ViewData::DebugPolytope
bool DebugPolytope(const osg::Polytope &p, const char *name="")
osgShadow::DebugShadowMap::ViewData::_depthColorFragmentShader
osg::ref_ptr< osg::Shader > _depthColorFragmentShader
Definition DebugShadowMap:127
osgShadow::DebugShadowMap::ViewData::_doDebugDrawPtr
bool * _doDebugDrawPtr
Definition DebugShadowMap:146
osgShadow::DebugShadowMap::ViewData::_debugDumpPtr
std::string * _debugDumpPtr
Definition DebugShadowMap:147
osgShadow::DebugShadowMap::ViewData::setDebugPolytope
void setDebugPolytope(const char *name, const ConvexPolyhedron &polytope= *(ConvexPolyhedron *)(NULL), osg::Vec4 colorOutline=osg::Vec4(0, 0, 0, 0), osg::Vec4 colorInside=osg::Vec4(0, 0, 0, 0))
osgShadow::DebugShadowMap::ViewData::_texture
osg::ref_ptr< osg::Texture > _texture
Definition DebugShadowMap:114
osgShadow::DebugShadowMap::ViewData::_viewportSize
osg::Vec2s _viewportSize
Definition DebugShadowMap:141
osgShadow::DebugShadowMap::ViewData::updateDebugGeometry
virtual void updateDebugGeometry(const osg::Camera *screenCam, const osg::Camera *shadowCam)
osgShadow::DebugShadowMap::ViewData::_transform
osg::ref_ptr< osg::MatrixTransform > _transform[2]
Definition DebugShadowMap:151
osgShadow::ViewDependentShadowTechnique::ViewData
Definition ViewDependentShadowTechnique:162
osgShadow::ViewDependentShadowTechnique::ViewData::ViewData
ViewData()
Definition ViewDependentShadowTechnique:186