From 236832f66992e6698176af6aa1d7e10d81f4e865 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 6 Oct 2008 08:53:54 +0000 Subject: [PATCH] Ran dos2unix on headers --- include/osgShadow/ConvexPolyhedron | 246 +++++----- include/osgShadow/DebugShadowMap | 356 +++++++------- .../osgShadow/LightSpacePerspectiveShadowMap | 244 +++++----- include/osgShadow/MinimalCullBoundsShadowMap | 164 +++---- include/osgShadow/MinimalDrawBoundsShadowMap | 252 +++++----- include/osgShadow/MinimalShadowMap | 312 ++++++------ include/osgShadow/ProjectionShadowMap | 164 +++---- include/osgShadow/StandardShadowMap | 390 +++++++-------- .../osgShadow/ViewDependentShadowTechnique | 458 +++++++++--------- 9 files changed, 1293 insertions(+), 1293 deletions(-) diff --git a/include/osgShadow/ConvexPolyhedron b/include/osgShadow/ConvexPolyhedron index bd6c7f7f3..5e0ebf129 100644 --- a/include/osgShadow/ConvexPolyhedron +++ b/include/osgShadow/ConvexPolyhedron @@ -1,123 +1,123 @@ -/* -*-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_CONVEXPOLYHEDRON -#define OSGSHADOW_CONVEXPOLYHEDRON 1 - -#include -#include -#include - -//////////////////////////////////////////////////////////////////////////////// -// Class based on CustomPolytope defined and used in osgSim::OverlayNode.cpp. -// Honors should go to Robert Osfield for writing such useful piece of code. -// First incarnations of my ConvexPolyhedron were derived from CustomPolytope. -// Later I made a number of modifications aimed at improving convex hull -// precision of intersection & extrusion operations and ended up with code -// so mixed that I decided to rewrite it as separate class. -//////////////////////////////////////////////////////////////////////////////// - -namespace osgShadow { - -class OSGSHADOW_EXPORT ConvexPolyhedron -{ - public: - typedef std::vector Vertices; - - static const osg::Matrix & defaultMatrix; - - struct Face - { - std::string name; - osg::Plane plane; - Vertices vertices; - }; - - typedef std::list Faces; - Faces _faces; - - ConvexPolyhedron( void ) { } - - ConvexPolyhedron( const osg::Matrix& matrix, const osg::Matrix& inverse, - const osg::BoundingBox& bb = osg::BoundingBox(-1,-1,-1,1,1,1)); - - Face& createFace() { _faces.push_back(Face()); return _faces.back(); } - void clear() { _faces.clear(); } - - - void setToUnitFrustum(bool withNear=true, bool withFar=true); - void setToBoundingBox(const osg::BoundingBox& bb); - void transform(const osg::Matrix& matrix, const osg::Matrix& inverse); - void transformClip(const osg::Matrix& matrix, const osg::Matrix& inverse); - - - bool mergeFaces - ( const Face & face0, const Face & face1, Face & face ); - - void mergeCoplanarFaces( const double & plane_normal_dot_tolerance = 0.0, - const double & plane_distance_tolerance = 0.0 ); - - void removeDuplicateVertices( void ); - - - static int pointsColinear - ( const osg::Vec3d & va, const osg::Vec3d & vb, const osg::Vec3d & vc, - const double & edge_normal_dot_tolerance = 0.0, - const double & null_edge_length_tolerance = 0.0 ); - - static int isFacePolygonConvex( Face & face, bool ignoreCollinearVertices = true ); - - bool checkCoherency - ( bool checkForNonConvexPolys = false, const char * errorPrefix = NULL ); - - - void cut(const osg::Polytope& polytope); - - void cut(const ConvexPolyhedron& polytope); - - void cut(const osg::Plane& plane, const std::string& name=std::string()); - - void extrude( const osg::Vec3d & offset ); - - void translate( const osg::Vec3d & offset ); - - - void getPolytope(osg::Polytope& polytope) const; - void getPoints(Vertices& vertices) const; - osg::BoundingBox computeBoundingBox( const osg::Matrix & m = osgShadow::ConvexPolyhedron::defaultMatrix ) const; - - osg::Geometry* buildGeometry( const osg::Vec4d& colorOutline, - const osg::Vec4d& colorInside, - osg::Geometry* useGeometry = NULL ) const; - - - bool dumpGeometry( const Face * face = NULL, - const osg::Plane * plane = NULL, - ConvexPolyhedron * basehull = NULL, - const char * filename = "convexpolyhedron.osg", - const osg::Vec4d& colorOutline = osg::Vec4( 0,1,0,0.5 ), - const osg::Vec4d& colorInside = osg::Vec4( 0,1,0,0.25 ), - const osg::Vec4d& faceColorOutline = osg::Vec4( 0,0,1,0.5 ), - const osg::Vec4d& faceColorInside = osg::Vec4( 0,0,1,0.25 ), - const osg::Vec4d& planeColorOutline = osg::Vec4( 1,0,0,0.5 ), - const osg::Vec4d& planeColorInside = osg::Vec4( 1,0,0,0.25 ), - const osg::Vec4d& baseColorOutline = osg::Vec4( 0,0,0,0.5 ), - const osg::Vec4d& baseColorInside = osg::Vec4( 0,0,0,0.25 ) ) const; -}; - -} // namespace osgShadow - -#endif +/* -*-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_CONVEXPOLYHEDRON +#define OSGSHADOW_CONVEXPOLYHEDRON 1 + +#include +#include +#include + +//////////////////////////////////////////////////////////////////////////////// +// Class based on CustomPolytope defined and used in osgSim::OverlayNode.cpp. +// Honors should go to Robert Osfield for writing such useful piece of code. +// First incarnations of my ConvexPolyhedron were derived from CustomPolytope. +// Later I made a number of modifications aimed at improving convex hull +// precision of intersection & extrusion operations and ended up with code +// so mixed that I decided to rewrite it as separate class. +//////////////////////////////////////////////////////////////////////////////// + +namespace osgShadow { + +class OSGSHADOW_EXPORT ConvexPolyhedron +{ + public: + typedef std::vector Vertices; + + static const osg::Matrix & defaultMatrix; + + struct Face + { + std::string name; + osg::Plane plane; + Vertices vertices; + }; + + typedef std::list Faces; + Faces _faces; + + ConvexPolyhedron( void ) { } + + ConvexPolyhedron( const osg::Matrix& matrix, const osg::Matrix& inverse, + const osg::BoundingBox& bb = osg::BoundingBox(-1,-1,-1,1,1,1)); + + Face& createFace() { _faces.push_back(Face()); return _faces.back(); } + void clear() { _faces.clear(); } + + + void setToUnitFrustum(bool withNear=true, bool withFar=true); + void setToBoundingBox(const osg::BoundingBox& bb); + void transform(const osg::Matrix& matrix, const osg::Matrix& inverse); + void transformClip(const osg::Matrix& matrix, const osg::Matrix& inverse); + + + bool mergeFaces + ( const Face & face0, const Face & face1, Face & face ); + + void mergeCoplanarFaces( const double & plane_normal_dot_tolerance = 0.0, + const double & plane_distance_tolerance = 0.0 ); + + void removeDuplicateVertices( void ); + + + static int pointsColinear + ( const osg::Vec3d & va, const osg::Vec3d & vb, const osg::Vec3d & vc, + const double & edge_normal_dot_tolerance = 0.0, + const double & null_edge_length_tolerance = 0.0 ); + + static int isFacePolygonConvex( Face & face, bool ignoreCollinearVertices = true ); + + bool checkCoherency + ( bool checkForNonConvexPolys = false, const char * errorPrefix = NULL ); + + + void cut(const osg::Polytope& polytope); + + void cut(const ConvexPolyhedron& polytope); + + void cut(const osg::Plane& plane, const std::string& name=std::string()); + + void extrude( const osg::Vec3d & offset ); + + void translate( const osg::Vec3d & offset ); + + + void getPolytope(osg::Polytope& polytope) const; + void getPoints(Vertices& vertices) const; + osg::BoundingBox computeBoundingBox( const osg::Matrix & m = osgShadow::ConvexPolyhedron::defaultMatrix ) const; + + osg::Geometry* buildGeometry( const osg::Vec4d& colorOutline, + const osg::Vec4d& colorInside, + osg::Geometry* useGeometry = NULL ) const; + + + bool dumpGeometry( const Face * face = NULL, + const osg::Plane * plane = NULL, + ConvexPolyhedron * basehull = NULL, + const char * filename = "convexpolyhedron.osg", + const osg::Vec4d& colorOutline = osg::Vec4( 0,1,0,0.5 ), + const osg::Vec4d& colorInside = osg::Vec4( 0,1,0,0.25 ), + const osg::Vec4d& faceColorOutline = osg::Vec4( 0,0,1,0.5 ), + const osg::Vec4d& faceColorInside = osg::Vec4( 0,0,1,0.25 ), + const osg::Vec4d& planeColorOutline = osg::Vec4( 1,0,0,0.5 ), + const osg::Vec4d& planeColorInside = osg::Vec4( 1,0,0,0.25 ), + const osg::Vec4d& baseColorOutline = osg::Vec4( 0,0,0,0.5 ), + const osg::Vec4d& baseColorInside = osg::Vec4( 0,0,0,0.25 ) ) const; +}; + +} // namespace osgShadow + +#endif diff --git a/include/osgShadow/DebugShadowMap b/include/osgShadow/DebugShadowMap index f76bf58e4..8b1881ec3 100644 --- a/include/osgShadow/DebugShadowMap +++ b/include/osgShadow/DebugShadowMap @@ -1,178 +1,178 @@ -/* -*-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 -#include -#include -#include -#include -#include -#include - -namespace osgShadow { - -/** -Class used as a layer for debuging resources used by derived xxxShadowMap classes. -As designed by its base ViewDepndentShadowTechnique, DebugShadowMap serves mainly as container of -DebugShadowMap::ViewData objects. Most of the debuging support work is done by these objects. -DebugShadowMap technique only initializes them in initViewDependentData method. - -Debuging outputs present: - Shadow maps (pseudo colored to improve readability) - Shadow and related volumes (represented as convex polyhedra) -*/ - -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. - */ - - /** Convenient typedef used in definition of ViewData struct and methods */ - typedef DebugShadowMap ThisClass; - /** Convenient typedef used in definition of ViewData struct and methods */ - typedef ViewDependentShadowTechnique BaseClass; - - /** Classic OSG constructor */ - DebugShadowMap(); - - /** Classic OSG cloning constructor */ - DebugShadowMap(const DebugShadowMap& dsm, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); - - /** Declaration of standard OSG object methods */ - META_Object( ViewDependentShadow, DebugShadowMap ); - - /** Turn on/off debuging hud & rendering of debug volumes in main view */ - void setDebugDraw( bool draw ) { _doDebugDraw = draw; } - - /** Tell if debuging hud & rendering of debug volumes is active */ - bool getDebugDraw( void ) { return _doDebugDraw; } - - protected: - /** Classic protected OSG destructor */ - virtual ~DebugShadowMap(); - - osg::Vec2s _hudSize; - osg::Vec2s _hudOrigin; - osg::Vec2s _viewportSize; - osg::Vec2s _viewportOrigin; - osg::Vec2s _orthoSize; - osg::Vec2s _orthoOrigin; - - bool _doDebugDraw; - - osg::ref_ptr< osg::Shader > _depthColorFragmentShader; - - struct ViewData: public BaseClass::ViewData - { - /** - Texture used as ShadowMap - initialized by derived classes. - But it has to be defined now since DebugShadowMap::ViewData methods use it - */ - osg::ref_ptr< osg::Texture2D > _texture; - /** - Camera used to render ShadowMap - initialized by derived classes. - But it has to be defined now since DebugShadowMap::ViewData methods use it - */ - osg::ref_ptr< osg::Camera > _camera; - - osg::Matrix _viewProjection; - osg::Camera * _viewCamera; - - // Debug hud variables - - /** Coloring Shader used to present shadow depth map contents */ - 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; - - 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 _cameraDebugHUD; - - bool getDebugDraw() { return *_doDebugDrawPtr; } - - 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 ); - }; - - META_ViewDependentShadowTechniqueData( ThisClass, ViewData ) -}; - -} // namespace osgShadow - -#endif +/* -*-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 +#include +#include +#include +#include +#include +#include + +namespace osgShadow { + +/** +Class used as a layer for debuging resources used by derived xxxShadowMap classes. +As designed by its base ViewDepndentShadowTechnique, DebugShadowMap serves mainly as container of +DebugShadowMap::ViewData objects. Most of the debuging support work is done by these objects. +DebugShadowMap technique only initializes them in initViewDependentData method. + +Debuging outputs present: + Shadow maps (pseudo colored to improve readability) + Shadow and related volumes (represented as convex polyhedra) +*/ + +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. + */ + + /** Convenient typedef used in definition of ViewData struct and methods */ + typedef DebugShadowMap ThisClass; + /** Convenient typedef used in definition of ViewData struct and methods */ + typedef ViewDependentShadowTechnique BaseClass; + + /** Classic OSG constructor */ + DebugShadowMap(); + + /** Classic OSG cloning constructor */ + DebugShadowMap(const DebugShadowMap& dsm, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); + + /** Declaration of standard OSG object methods */ + META_Object( ViewDependentShadow, DebugShadowMap ); + + /** Turn on/off debuging hud & rendering of debug volumes in main view */ + void setDebugDraw( bool draw ) { _doDebugDraw = draw; } + + /** Tell if debuging hud & rendering of debug volumes is active */ + bool getDebugDraw( void ) { return _doDebugDraw; } + + protected: + /** Classic protected OSG destructor */ + virtual ~DebugShadowMap(); + + osg::Vec2s _hudSize; + osg::Vec2s _hudOrigin; + osg::Vec2s _viewportSize; + osg::Vec2s _viewportOrigin; + osg::Vec2s _orthoSize; + osg::Vec2s _orthoOrigin; + + bool _doDebugDraw; + + osg::ref_ptr< osg::Shader > _depthColorFragmentShader; + + struct ViewData: public BaseClass::ViewData + { + /** + Texture used as ShadowMap - initialized by derived classes. + But it has to be defined now since DebugShadowMap::ViewData methods use it + */ + osg::ref_ptr< osg::Texture2D > _texture; + /** + Camera used to render ShadowMap - initialized by derived classes. + But it has to be defined now since DebugShadowMap::ViewData methods use it + */ + osg::ref_ptr< osg::Camera > _camera; + + osg::Matrix _viewProjection; + osg::Camera * _viewCamera; + + // Debug hud variables + + /** Coloring Shader used to present shadow depth map contents */ + 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; + + 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 _cameraDebugHUD; + + bool getDebugDraw() { return *_doDebugDrawPtr; } + + 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 ); + }; + + META_ViewDependentShadowTechniqueData( ThisClass, ViewData ) +}; + +} // namespace osgShadow + +#endif diff --git a/include/osgShadow/LightSpacePerspectiveShadowMap b/include/osgShadow/LightSpacePerspectiveShadowMap index 9514667be..4853bffbe 100644 --- a/include/osgShadow/LightSpacePerspectiveShadowMap +++ b/include/osgShadow/LightSpacePerspectiveShadowMap @@ -1,122 +1,122 @@ -/* -*-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_LIGHTSPACEPERSPECTIVESHADOWMAP -#define OSGSHADOW_LIGHTSPACEPERSPECTIVESHADOWMAP 1 - -#include -#include -#include - -namespace osgShadow { - -// Class implements -// "Light Space Perspective Shadow Maps" algorithm by -// Michael Wimmer, Daniel Scherzer, Werner Purgathofer -// http://www.cg.tuwien.ac.at/research/vr/lispsm/ - -class LispSM; - -class OSGSHADOW_EXPORT LightSpacePerspectiveShadowMapAlgorithm -{ - public: - LightSpacePerspectiveShadowMapAlgorithm(); - ~LightSpacePerspectiveShadowMapAlgorithm(); - - void operator() ( - const osgShadow::ConvexPolyhedron* hullShadowedView, - const osg::Camera* cameraMain, - osg::Camera* cameraShadow ) const; - - protected: - LispSM * lispsm; -}; - -// Optimized for draw traversal shadow bounds -class OSGSHADOW_EXPORT LightSpacePerspectiveShadowMapDB: public ProjectionShadowMap< MinimalDrawBoundsShadowMap, LightSpacePerspectiveShadowMapAlgorithm > -{ - public: - /** Convenient typedef used in definition of ViewData struct and methods */ - typedef ProjectionShadowMap< MinimalDrawBoundsShadowMap, LightSpacePerspectiveShadowMapAlgorithm > BaseClass; - - /** Classic OSG constructor */ - LightSpacePerspectiveShadowMapDB() - { - } - - /** Classic OSG cloning constructor */ - LightSpacePerspectiveShadowMapDB( - const LightSpacePerspectiveShadowMapDB& copy, - const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : BaseClass(copy,copyop) - { - } - - /** Declaration of standard OSG object methods */ - META_Object( ViewDependentShadow, LightSpacePerspectiveShadowMapDB ); -}; - -// Optimized for cull traversal shadow bounds -class OSGSHADOW_EXPORT LightSpacePerspectiveShadowMapCB: public ProjectionShadowMap< MinimalCullBoundsShadowMap, LightSpacePerspectiveShadowMapAlgorithm > -{ - public: - /** Convenient typedef used in definition of ViewData struct and methods */ - typedef ProjectionShadowMap< MinimalCullBoundsShadowMap, LightSpacePerspectiveShadowMapAlgorithm > BaseClass; - - /** Classic OSG constructor */ - LightSpacePerspectiveShadowMapCB() - { - } - - /** Classic OSG cloning constructor */ - LightSpacePerspectiveShadowMapCB( - const LightSpacePerspectiveShadowMapCB& copy, - const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : BaseClass(copy,copyop) - { - } - - /** Declaration of standard OSG object methods */ - META_Object( ViewDependentShadow, LightSpacePerspectiveShadowMapCB ); -}; - -// Optimized for view frustum bounds -class OSGSHADOW_EXPORT LightSpacePerspectiveShadowMapVB: public ProjectionShadowMap< MinimalShadowMap, LightSpacePerspectiveShadowMapAlgorithm > -{ - public: - /** Convenient typedef used in definition of ViewData struct and methods */ - typedef ProjectionShadowMap< MinimalShadowMap, LightSpacePerspectiveShadowMapAlgorithm > BaseClass; - - /** Classic OSG constructor */ - LightSpacePerspectiveShadowMapVB() - { - } - - /** Classic OSG cloning constructor */ - LightSpacePerspectiveShadowMapVB( - const LightSpacePerspectiveShadowMapVB& copy, - const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : BaseClass(copy,copyop) - { - } - - /** Declaration of standard OSG object methods */ - META_Object( ViewDependentShadow, LightSpacePerspectiveShadowMapVB ); -}; - -typedef LightSpacePerspectiveShadowMapDB LightSpacePerspectiveShadowMap; - -} // namespace osgShadow - -#endif +/* -*-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_LIGHTSPACEPERSPECTIVESHADOWMAP +#define OSGSHADOW_LIGHTSPACEPERSPECTIVESHADOWMAP 1 + +#include +#include +#include + +namespace osgShadow { + +// Class implements +// "Light Space Perspective Shadow Maps" algorithm by +// Michael Wimmer, Daniel Scherzer, Werner Purgathofer +// http://www.cg.tuwien.ac.at/research/vr/lispsm/ + +class LispSM; + +class OSGSHADOW_EXPORT LightSpacePerspectiveShadowMapAlgorithm +{ + public: + LightSpacePerspectiveShadowMapAlgorithm(); + ~LightSpacePerspectiveShadowMapAlgorithm(); + + void operator() ( + const osgShadow::ConvexPolyhedron* hullShadowedView, + const osg::Camera* cameraMain, + osg::Camera* cameraShadow ) const; + + protected: + LispSM * lispsm; +}; + +// Optimized for draw traversal shadow bounds +class OSGSHADOW_EXPORT LightSpacePerspectiveShadowMapDB: public ProjectionShadowMap< MinimalDrawBoundsShadowMap, LightSpacePerspectiveShadowMapAlgorithm > +{ + public: + /** Convenient typedef used in definition of ViewData struct and methods */ + typedef ProjectionShadowMap< MinimalDrawBoundsShadowMap, LightSpacePerspectiveShadowMapAlgorithm > BaseClass; + + /** Classic OSG constructor */ + LightSpacePerspectiveShadowMapDB() + { + } + + /** Classic OSG cloning constructor */ + LightSpacePerspectiveShadowMapDB( + const LightSpacePerspectiveShadowMapDB& copy, + const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : BaseClass(copy,copyop) + { + } + + /** Declaration of standard OSG object methods */ + META_Object( ViewDependentShadow, LightSpacePerspectiveShadowMapDB ); +}; + +// Optimized for cull traversal shadow bounds +class OSGSHADOW_EXPORT LightSpacePerspectiveShadowMapCB: public ProjectionShadowMap< MinimalCullBoundsShadowMap, LightSpacePerspectiveShadowMapAlgorithm > +{ + public: + /** Convenient typedef used in definition of ViewData struct and methods */ + typedef ProjectionShadowMap< MinimalCullBoundsShadowMap, LightSpacePerspectiveShadowMapAlgorithm > BaseClass; + + /** Classic OSG constructor */ + LightSpacePerspectiveShadowMapCB() + { + } + + /** Classic OSG cloning constructor */ + LightSpacePerspectiveShadowMapCB( + const LightSpacePerspectiveShadowMapCB& copy, + const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : BaseClass(copy,copyop) + { + } + + /** Declaration of standard OSG object methods */ + META_Object( ViewDependentShadow, LightSpacePerspectiveShadowMapCB ); +}; + +// Optimized for view frustum bounds +class OSGSHADOW_EXPORT LightSpacePerspectiveShadowMapVB: public ProjectionShadowMap< MinimalShadowMap, LightSpacePerspectiveShadowMapAlgorithm > +{ + public: + /** Convenient typedef used in definition of ViewData struct and methods */ + typedef ProjectionShadowMap< MinimalShadowMap, LightSpacePerspectiveShadowMapAlgorithm > BaseClass; + + /** Classic OSG constructor */ + LightSpacePerspectiveShadowMapVB() + { + } + + /** Classic OSG cloning constructor */ + LightSpacePerspectiveShadowMapVB( + const LightSpacePerspectiveShadowMapVB& copy, + const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : BaseClass(copy,copyop) + { + } + + /** Declaration of standard OSG object methods */ + META_Object( ViewDependentShadow, LightSpacePerspectiveShadowMapVB ); +}; + +typedef LightSpacePerspectiveShadowMapDB LightSpacePerspectiveShadowMap; + +} // namespace osgShadow + +#endif diff --git a/include/osgShadow/MinimalCullBoundsShadowMap b/include/osgShadow/MinimalCullBoundsShadowMap index cac7e71d0..56ec17aee 100644 --- a/include/osgShadow/MinimalCullBoundsShadowMap +++ b/include/osgShadow/MinimalCullBoundsShadowMap @@ -1,82 +1,82 @@ -/* -*-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_MINIMALCULLBOUNDSSHADOWMAP -#define OSGSHADOW_MINIMALCULLBOUNDSSHADOWMAP 1 - -#include - -namespace osgShadow { - -class OSGSHADOW_EXPORT MinimalCullBoundsShadowMap - : public MinimalShadowMap -{ - public : - /** Convenient typedef used in definition of ViewData struct and methods */ - typedef MinimalCullBoundsShadowMap ThisClass; - /** Convenient typedef used in definition of ViewData struct and methods */ - typedef MinimalShadowMap BaseClass; - - /** Classic OSG constructor */ - MinimalCullBoundsShadowMap(); - - /** Classic OSG cloning constructor */ - MinimalCullBoundsShadowMap( - const MinimalCullBoundsShadowMap& mcbsm, - const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); - - /** Declaration of standard OSG object methods */ - META_Object( ViewDependentShadow, MinimalCullBoundsShadowMap ); - - protected: - /** Classic protected OSG destructor */ - virtual ~MinimalCullBoundsShadowMap(void); - - struct ViewData: public MinimalShadowMap::ViewData - { - virtual void init( ThisClass * st, osgUtil::CullVisitor * cv ); - - virtual void cullShadowReceivingScene( ); - - virtual void aimShadowCastingCamera( const osg::Light *light, - const osg::Vec4 &worldLightPos, - const osg::Vec3 &worldLightDir, - const osg::Vec3 &worldLightUp - = osg::Vec3(0,1,0) ); - - typedef std::vector< osgUtil::RenderLeaf* > RenderLeafList; - - static unsigned RemoveOldRenderLeaves - ( RenderLeafList &rllNew, RenderLeafList &rllOld ); - - static unsigned RemoveIgnoredRenderLeaves( RenderLeafList &rll ); - - static osg::BoundingBox ComputeRenderLeavesBounds - ( RenderLeafList &rll, osg::Matrix & projectionToWorld ); - - static osg::BoundingBox ComputeRenderLeavesBounds - ( RenderLeafList &rll, osg::Matrix & projectionToWorld, osg::Polytope & polytope ); - - static void GetRenderLeaves - ( osgUtil::RenderBin *rb, RenderLeafList &rll ); - }; - - META_ViewDependentShadowTechniqueData( ThisClass, ThisClass::ViewData ) -}; - -} // namespace osgShadow - -#endif +/* -*-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_MINIMALCULLBOUNDSSHADOWMAP +#define OSGSHADOW_MINIMALCULLBOUNDSSHADOWMAP 1 + +#include + +namespace osgShadow { + +class OSGSHADOW_EXPORT MinimalCullBoundsShadowMap + : public MinimalShadowMap +{ + public : + /** Convenient typedef used in definition of ViewData struct and methods */ + typedef MinimalCullBoundsShadowMap ThisClass; + /** Convenient typedef used in definition of ViewData struct and methods */ + typedef MinimalShadowMap BaseClass; + + /** Classic OSG constructor */ + MinimalCullBoundsShadowMap(); + + /** Classic OSG cloning constructor */ + MinimalCullBoundsShadowMap( + const MinimalCullBoundsShadowMap& mcbsm, + const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); + + /** Declaration of standard OSG object methods */ + META_Object( ViewDependentShadow, MinimalCullBoundsShadowMap ); + + protected: + /** Classic protected OSG destructor */ + virtual ~MinimalCullBoundsShadowMap(void); + + struct ViewData: public MinimalShadowMap::ViewData + { + virtual void init( ThisClass * st, osgUtil::CullVisitor * cv ); + + virtual void cullShadowReceivingScene( ); + + virtual void aimShadowCastingCamera( const osg::Light *light, + const osg::Vec4 &worldLightPos, + const osg::Vec3 &worldLightDir, + const osg::Vec3 &worldLightUp + = osg::Vec3(0,1,0) ); + + typedef std::vector< osgUtil::RenderLeaf* > RenderLeafList; + + static unsigned RemoveOldRenderLeaves + ( RenderLeafList &rllNew, RenderLeafList &rllOld ); + + static unsigned RemoveIgnoredRenderLeaves( RenderLeafList &rll ); + + static osg::BoundingBox ComputeRenderLeavesBounds + ( RenderLeafList &rll, osg::Matrix & projectionToWorld ); + + static osg::BoundingBox ComputeRenderLeavesBounds + ( RenderLeafList &rll, osg::Matrix & projectionToWorld, osg::Polytope & polytope ); + + static void GetRenderLeaves + ( osgUtil::RenderBin *rb, RenderLeafList &rll ); + }; + + META_ViewDependentShadowTechniqueData( ThisClass, ThisClass::ViewData ) +}; + +} // namespace osgShadow + +#endif diff --git a/include/osgShadow/MinimalDrawBoundsShadowMap b/include/osgShadow/MinimalDrawBoundsShadowMap index 3ed1d59cc..2be16938d 100644 --- a/include/osgShadow/MinimalDrawBoundsShadowMap +++ b/include/osgShadow/MinimalDrawBoundsShadowMap @@ -1,126 +1,126 @@ -/* -*-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_MINIMALDRAWBOUNDSSHADOWMAP -#define OSGSHADOW_MINIMALDRAWBOUNDSSHADOWMAP 1 - -#include - -namespace osgShadow { - -class OSGSHADOW_EXPORT MinimalDrawBoundsShadowMap - : public MinimalShadowMap -{ - public : - /** Convenient typedef used in definition of ViewData struct and methods */ - typedef MinimalDrawBoundsShadowMap ThisClass; - /** Convenient typedef used in definition of ViewData struct and methods */ - typedef MinimalShadowMap BaseClass; - - /** Classic OSG constructor */ - MinimalDrawBoundsShadowMap(); - - /** Classic OSG cloning constructor */ - MinimalDrawBoundsShadowMap( - const MinimalDrawBoundsShadowMap& mdbsm, - const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); - - /** Declaration of standard OSG object methods */ - META_Object( ViewDependentShadow, MinimalDrawBoundsShadowMap ); - - protected: - /** Classic protected OSG destructor */ - virtual ~MinimalDrawBoundsShadowMap(void); - - struct ViewData: public BaseClass::ViewData - { - osg::ref_ptr< osg::RefMatrix > _projection; - osg::Vec2s _boundAnalysisSize; - osg::ref_ptr< osg::Image > _boundAnalysisImage; - osg::ref_ptr< osg::Texture2D > _boundAnalysisTexture; - osg::ref_ptr< osg::Camera > _boundAnalysisCamera; - osg::ref_ptr< osg::Camera > _mainCamera; - - void setShadowCameraProjectionMatrixPtr( osg::RefMatrix * projection ) - { _projection = projection; } - - osg::RefMatrix * getShadowCameraProjectionMatrixPtr( void ) - { return _projection.get(); } - - virtual void init( ThisClass * st, osgUtil::CullVisitor * cv ); - - virtual void cullShadowReceivingScene( ); - - virtual void createDebugHUD( ); - - virtual void recordShadowMapParams( ); - - virtual void cullBoundAnalysisScene( ); - - static osg::BoundingBox scanImage( const osg::Image * image, osg::Matrix m ); - - virtual void performBoundAnalysis( const osg::Camera& camera ); - - ViewData( void ): _boundAnalysisSize( 64, 64 ) {} - }; - - META_ViewDependentShadowTechniqueData( ThisClass, ThisClass::ViewData ) - - - struct CameraPostDrawCallback : public osg::Camera::DrawCallback { - - CameraPostDrawCallback( ViewData * vd ): _vd( vd ) - { - } - - virtual void operator ()( const osg::Camera& camera ) const - { - if( _vd.valid() ) - _vd->performBoundAnalysis( camera ); - } - - osg::observer_ptr< ViewData > _vd; - }; - - struct CameraCullCallback: public osg::NodeCallback { - - CameraCullCallback(ViewData * vd, osg::NodeCallback * nc): _vd(vd), _nc(nc) - { - } - - virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) - { - osgUtil::CullVisitor *cv = dynamic_cast< osgUtil::CullVisitor *>( nv ); - - if( _nc.valid() ) - _nc->operator()(node,nv); - else - traverse(node,nv); - - if( cv ) - _vd->recordShadowMapParams( ); - } - - protected: - osg::ref_ptr< osg::NodeCallback > _nc; - osg::observer_ptr< ViewData > _vd; - }; -}; - -} // namespace osgShadow - -#endif +/* -*-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_MINIMALDRAWBOUNDSSHADOWMAP +#define OSGSHADOW_MINIMALDRAWBOUNDSSHADOWMAP 1 + +#include + +namespace osgShadow { + +class OSGSHADOW_EXPORT MinimalDrawBoundsShadowMap + : public MinimalShadowMap +{ + public : + /** Convenient typedef used in definition of ViewData struct and methods */ + typedef MinimalDrawBoundsShadowMap ThisClass; + /** Convenient typedef used in definition of ViewData struct and methods */ + typedef MinimalShadowMap BaseClass; + + /** Classic OSG constructor */ + MinimalDrawBoundsShadowMap(); + + /** Classic OSG cloning constructor */ + MinimalDrawBoundsShadowMap( + const MinimalDrawBoundsShadowMap& mdbsm, + const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); + + /** Declaration of standard OSG object methods */ + META_Object( ViewDependentShadow, MinimalDrawBoundsShadowMap ); + + protected: + /** Classic protected OSG destructor */ + virtual ~MinimalDrawBoundsShadowMap(void); + + struct ViewData: public BaseClass::ViewData + { + osg::ref_ptr< osg::RefMatrix > _projection; + osg::Vec2s _boundAnalysisSize; + osg::ref_ptr< osg::Image > _boundAnalysisImage; + osg::ref_ptr< osg::Texture2D > _boundAnalysisTexture; + osg::ref_ptr< osg::Camera > _boundAnalysisCamera; + osg::ref_ptr< osg::Camera > _mainCamera; + + void setShadowCameraProjectionMatrixPtr( osg::RefMatrix * projection ) + { _projection = projection; } + + osg::RefMatrix * getShadowCameraProjectionMatrixPtr( void ) + { return _projection.get(); } + + virtual void init( ThisClass * st, osgUtil::CullVisitor * cv ); + + virtual void cullShadowReceivingScene( ); + + virtual void createDebugHUD( ); + + virtual void recordShadowMapParams( ); + + virtual void cullBoundAnalysisScene( ); + + static osg::BoundingBox scanImage( const osg::Image * image, osg::Matrix m ); + + virtual void performBoundAnalysis( const osg::Camera& camera ); + + ViewData( void ): _boundAnalysisSize( 64, 64 ) {} + }; + + META_ViewDependentShadowTechniqueData( ThisClass, ThisClass::ViewData ) + + + struct CameraPostDrawCallback : public osg::Camera::DrawCallback { + + CameraPostDrawCallback( ViewData * vd ): _vd( vd ) + { + } + + virtual void operator ()( const osg::Camera& camera ) const + { + if( _vd.valid() ) + _vd->performBoundAnalysis( camera ); + } + + osg::observer_ptr< ViewData > _vd; + }; + + struct CameraCullCallback: public osg::NodeCallback { + + CameraCullCallback(ViewData * vd, osg::NodeCallback * nc): _vd(vd), _nc(nc) + { + } + + virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) + { + osgUtil::CullVisitor *cv = dynamic_cast< osgUtil::CullVisitor *>( nv ); + + if( _nc.valid() ) + _nc->operator()(node,nv); + else + traverse(node,nv); + + if( cv ) + _vd->recordShadowMapParams( ); + } + + protected: + osg::ref_ptr< osg::NodeCallback > _nc; + osg::observer_ptr< ViewData > _vd; + }; +}; + +} // namespace osgShadow + +#endif diff --git a/include/osgShadow/MinimalShadowMap b/include/osgShadow/MinimalShadowMap index 3bccbce58..5ff53cf5e 100644 --- a/include/osgShadow/MinimalShadowMap +++ b/include/osgShadow/MinimalShadowMap @@ -1,156 +1,156 @@ -/* -*-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 - -namespace osgShadow { - -class OSGSHADOW_EXPORT MinimalShadowMap : public StandardShadowMap -{ - public : - /** Convenient typedef used in definition of ViewData struct and methods */ - typedef MinimalShadowMap ThisClass; - /** Convenient typedef used in definition of ViewData struct and methods */ - typedef StandardShadowMap BaseClass; - - /** Classic OSG constructor */ - MinimalShadowMap(); - - /** Classic OSG cloning constructor */ - MinimalShadowMap( - const MinimalShadowMap& msm, - const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); - - /** Declaration of standard OSG object methods */ - META_Object( ViewDependentShadow, MinimalShadowMap ); - - void setModellingSpaceToWorldTransform( const osg::Matrix & modellingSpaceToWorld ) - { _modellingSpaceToWorld = modellingSpaceToWorld; } - - const osg::Matrix & getModellingSpaceToWorldTransform( void ) - { return _modellingSpaceToWorld; } - - float getMaxFarPlane( ) - { return _maxFarPlane; } - - void setMaxFarPlane( float maxFarPlane ) - { _maxFarPlane = maxFarPlane; } - - float getMinLightMargin( ) - { 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() - { return _shadowReceivingCoarseBoundAccuracy; } - - protected: - /** Classic protected OSG destructor */ - 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 colums - - osg::Matrix _modellingSpaceToWorld; - float _maxFarPlane; - float _minLightMargin; - ShadowReceivingCoarseBoundAccuracy _shadowReceivingCoarseBoundAccuracy; - - struct ViewData: public BaseClass::ViewData - { - osg::Matrix *_modellingSpaceToWorldPtr; - float *_maxFarPlanePtr; - float *_minLightMarginPtr; - - ConvexPolyhedron _sceneReceivingShadowPolytope; - std::vector< osg::Vec3d > _sceneReceivingShadowPolytopePoints; - - osg::Matrix _clampedProjection; - - virtual void init( ThisClass * st, osgUtil::CullVisitor * cv ); - - virtual osg::BoundingBox computeShadowReceivingCoarseBounds( ); - - virtual void cullShadowReceivingScene( ); - - 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 - ( const osg::Matrix & m = *(osg::Matrix*)(NULL) ); - - // 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::Matrix & 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::Matrix & projection, float n = 0, float f = FLT_MAX ); - - static void extendProjection - ( osg::Matrix & projection, osg::Viewport * viewport, const osg::Vec2& margin ); - }; - - META_ViewDependentShadowTechniqueData( ThisClass, ThisClass::ViewData ) -}; - -} // namespace osgShadow - -#endif +/* -*-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 + +namespace osgShadow { + +class OSGSHADOW_EXPORT MinimalShadowMap : public StandardShadowMap +{ + public : + /** Convenient typedef used in definition of ViewData struct and methods */ + typedef MinimalShadowMap ThisClass; + /** Convenient typedef used in definition of ViewData struct and methods */ + typedef StandardShadowMap BaseClass; + + /** Classic OSG constructor */ + MinimalShadowMap(); + + /** Classic OSG cloning constructor */ + MinimalShadowMap( + const MinimalShadowMap& msm, + const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); + + /** Declaration of standard OSG object methods */ + META_Object( ViewDependentShadow, MinimalShadowMap ); + + void setModellingSpaceToWorldTransform( const osg::Matrix & modellingSpaceToWorld ) + { _modellingSpaceToWorld = modellingSpaceToWorld; } + + const osg::Matrix & getModellingSpaceToWorldTransform( void ) + { return _modellingSpaceToWorld; } + + float getMaxFarPlane( ) + { return _maxFarPlane; } + + void setMaxFarPlane( float maxFarPlane ) + { _maxFarPlane = maxFarPlane; } + + float getMinLightMargin( ) + { 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() + { return _shadowReceivingCoarseBoundAccuracy; } + + protected: + /** Classic protected OSG destructor */ + 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 colums + + osg::Matrix _modellingSpaceToWorld; + float _maxFarPlane; + float _minLightMargin; + ShadowReceivingCoarseBoundAccuracy _shadowReceivingCoarseBoundAccuracy; + + struct ViewData: public BaseClass::ViewData + { + osg::Matrix *_modellingSpaceToWorldPtr; + float *_maxFarPlanePtr; + float *_minLightMarginPtr; + + ConvexPolyhedron _sceneReceivingShadowPolytope; + std::vector< osg::Vec3d > _sceneReceivingShadowPolytopePoints; + + osg::Matrix _clampedProjection; + + virtual void init( ThisClass * st, osgUtil::CullVisitor * cv ); + + virtual osg::BoundingBox computeShadowReceivingCoarseBounds( ); + + virtual void cullShadowReceivingScene( ); + + 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 + ( const osg::Matrix & m = *(osg::Matrix*)(NULL) ); + + // 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::Matrix & 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::Matrix & projection, float n = 0, float f = FLT_MAX ); + + static void extendProjection + ( osg::Matrix & projection, osg::Viewport * viewport, const osg::Vec2& margin ); + }; + + META_ViewDependentShadowTechniqueData( ThisClass, ThisClass::ViewData ) +}; + +} // namespace osgShadow + +#endif diff --git a/include/osgShadow/ProjectionShadowMap b/include/osgShadow/ProjectionShadowMap index e9eece046..b19cdc190 100644 --- a/include/osgShadow/ProjectionShadowMap +++ b/include/osgShadow/ProjectionShadowMap @@ -1,82 +1,82 @@ -/* -*-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_PROJECTIONSHADOWMAP -#define OSGSHADOW_PROJECTIONSHADOWMAP 1 - -#include - -namespace osgShadow { - -template< typename MinimalBoundsBaseClass, typename ShadowProjectionAlgorithmClass > -class OSGSHADOW_EXPORT ProjectionShadowMap : public MinimalBoundsBaseClass -{ - public : - /** Convenient typedef used in definition of ViewData struct and methods */ - typedef MinimalBoundsBaseClass BaseClass; - /** Convenient typedef used in definition of ViewData struct and methods */ - typedef ProjectionShadowMap ThisClass; - - /** Classic OSG constructor */ - ProjectionShadowMap() : BaseClass() - { - } - - /** Classic OSG cloning constructor */ - ProjectionShadowMap( - const ProjectionShadowMap& copy, - const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : BaseClass(copy,copyop) - { - } - - /** Declaration of standard OSG object methods */ - META_Object( ViewDependentShadow, ProjectionShadowMap ); - - protected: - - /** Classic protected OSG destructor */ - virtual ~ProjectionShadowMap(void) - { - } - - struct ViewData: public BaseClass::ViewData, - public ShadowProjectionAlgorithmClass - { - #if 0 - virtual void init( ThisClass * st, osgUtil::CullVisitor * cv ); - { - BaseClass::ViewData::init( st, cv ); - } - #endif - - virtual void frameShadowCastingCamera - ( const osg::Camera* cameraMain, osg::Camera* cameraShadow, int pass = 1 ) - { - // Force dependent name lookup - ShadowProjectionAlgorithmClass::operator() - ( &this->_sceneReceivingShadowPolytope, cameraMain, cameraShadow ); - - // DebugBoundingBox( computeScenePolytopeBounds(), "ProjectionShadowMap" ); - BaseClass::ViewData::frameShadowCastingCamera( cameraMain, cameraShadow, pass ); - } - }; - - META_ViewDependentShadowTechniqueData( ThisClass, typename ThisClass::ViewData ) -}; - -} // namespace osgShadow - -#endif +/* -*-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_PROJECTIONSHADOWMAP +#define OSGSHADOW_PROJECTIONSHADOWMAP 1 + +#include + +namespace osgShadow { + +template< typename MinimalBoundsBaseClass, typename ShadowProjectionAlgorithmClass > +class OSGSHADOW_EXPORT ProjectionShadowMap : public MinimalBoundsBaseClass +{ + public : + /** Convenient typedef used in definition of ViewData struct and methods */ + typedef MinimalBoundsBaseClass BaseClass; + /** Convenient typedef used in definition of ViewData struct and methods */ + typedef ProjectionShadowMap ThisClass; + + /** Classic OSG constructor */ + ProjectionShadowMap() : BaseClass() + { + } + + /** Classic OSG cloning constructor */ + ProjectionShadowMap( + const ProjectionShadowMap& copy, + const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : BaseClass(copy,copyop) + { + } + + /** Declaration of standard OSG object methods */ + META_Object( ViewDependentShadow, ProjectionShadowMap ); + + protected: + + /** Classic protected OSG destructor */ + virtual ~ProjectionShadowMap(void) + { + } + + struct ViewData: public BaseClass::ViewData, + public ShadowProjectionAlgorithmClass + { + #if 0 + virtual void init( ThisClass * st, osgUtil::CullVisitor * cv ); + { + BaseClass::ViewData::init( st, cv ); + } + #endif + + virtual void frameShadowCastingCamera + ( const osg::Camera* cameraMain, osg::Camera* cameraShadow, int pass = 1 ) + { + // Force dependent name lookup + ShadowProjectionAlgorithmClass::operator() + ( &this->_sceneReceivingShadowPolytope, cameraMain, cameraShadow ); + + // DebugBoundingBox( computeScenePolytopeBounds(), "ProjectionShadowMap" ); + BaseClass::ViewData::frameShadowCastingCamera( cameraMain, cameraShadow, pass ); + } + }; + + META_ViewDependentShadowTechniqueData( ThisClass, typename ThisClass::ViewData ) +}; + +} // namespace osgShadow + +#endif diff --git a/include/osgShadow/StandardShadowMap b/include/osgShadow/StandardShadowMap index ef3f5cf5b..06d3e50f1 100644 --- a/include/osgShadow/StandardShadowMap +++ b/include/osgShadow/StandardShadowMap @@ -1,195 +1,195 @@ -/* -*-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_STANDARDSHADOWMAP -#define OSGSHADOW_STANDARDSHADOWMAP 1 - -#include - -namespace osgShadow { - -class OSGSHADOW_EXPORT StandardShadowMap : public DebugShadowMap -{ - public : - /** Convenient typedef used in definition of ViewData struct and methods */ - typedef StandardShadowMap ThisClass; - /** Convenient typedef used in definition of ViewData struct and methods */ - typedef DebugShadowMap BaseClass; - - /** Classic OSG constructor */ - StandardShadowMap(); - - /** Classic OSG cloning constructor */ - StandardShadowMap(const StandardShadowMap& ssm, - const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); - - /** Declaration of standard OSG object methods */ - META_Object( ViewDependentShadow, StandardShadowMap ); - - void setBaseTextureUnit( unsigned int unit ) - { _baseTextureUnit = unit; dirty(); } - - unsigned int getBaseTextureUnit( void ) - { return _baseTextureUnit; } - - void setShadowTextureUnit( unsigned int unit ) - { _shadowTextureUnit = unit; dirty(); } - - unsigned int getShadowTextureUnit( void ) - { return _shadowTextureUnit; } - - // Texture Indices are changed by search and replace on shader source - // Carefully order these calls when changing both base and shadow indices - // In worst case when intend to swap indices - // one will have to call these methods more than once - // with one extra pass to change index to unused value to avoid - // unwanted superfluous replace: - // - // Example: Imagine we want to swap base(0) and shadow(1) indices: - // We have to do an extra step to make sure both do not end up as 1 - // - // // initialy change base to something else than 1 - // setBaseTextureCoordIndex( 100 ); - // // now search and replace all gl_TexCord[1] to gl_TexCord[0] - // setShadowTextureCoordIndex( 0 ); - // // finally change base from 100 to 0 - // setBaseTextureCoordIndex( 1 ); - - void setBaseTextureCoordIndex( unsigned int index ) - { updateTextureCoordIndices( _baseTextureCoordIndex, index ); - _baseTextureCoordIndex = index; } - - unsigned int getBaseTextureCoordIndex( void ) - { return _baseTextureCoordIndex; } - - // Texture Indices are changed by search and replace on shader source - // Look at the comment above setBaseTextureCoordIndex - - void setShadowTextureCoordIndex( unsigned int index ) - { updateTextureCoordIndices( _shadowTextureCoordIndex, index ); - _shadowTextureCoordIndex = index; } - - unsigned int getShadowTextureCoordIndex( void ) - { return _shadowTextureCoordIndex; } - - void setTextureSize( const osg::Vec2s& textureSize ) - { _textureSize = textureSize; dirty(); } - - osg::Vec2s getTextureSize( ) - { return _textureSize; } - - void setLight( osg::Light* light ) - { _light = light; } - - osg::Light* getLight( void ) - { return _light.get(); } - - osg::Shader * getShadowVertexShader() - { return _shadowVertexShader.get(); } - - osg::Shader * getShadowFragmentShader() - { return _shadowFragmentShader.get(); } - - osg::Shader * getMainVertexShader( ) - { return _mainVertexShader.get(); } - - osg::Shader * getMainFragmentShader( ) - { return _mainFragmentShader.get(); } - - void setShadowVertexShader( osg::Shader * shader ) - { _shadowVertexShader = shader; } - - void setShadowFragmentShader( osg::Shader * shader ) - { _shadowFragmentShader = shader; } - - void setMainVertexShader( osg::Shader * shader ) - { _mainVertexShader = shader; } - - void setMainFragmentShader( osg::Shader * shader ) - { _mainFragmentShader = shader; } - - protected: - /** Classic protected OSG destructor */ - virtual ~StandardShadowMap(void); - - virtual void updateTextureCoordIndices - ( unsigned int baseTexCoordIndex, unsigned int shadowTexCoordIndex ); - - virtual void searchAndReplaceShaderSource - ( osg::Shader*, std::string fromString, std::string toString ); - - osg::ref_ptr< osg::Shader > _mainVertexShader; - osg::ref_ptr< osg::Shader > _mainFragmentShader; - osg::ref_ptr< osg::Shader > _shadowVertexShader; - osg::ref_ptr< osg::Shader > _shadowFragmentShader; - - osg::ref_ptr< osg::Light > _light; - float _polygonOffsetFactor; - float _polygonOffsetUnits; - osg::Vec2s _textureSize; - unsigned int _baseTextureUnit; - unsigned int _shadowTextureUnit; - unsigned int _baseTextureCoordIndex; - unsigned int _shadowTextureCoordIndex; - - struct ViewData: public BaseClass::ViewData - { - osg::ref_ptr< osg::Light > * _lightPtr; - unsigned int * _baseTextureUnitPtr; - unsigned int * _shadowTextureUnitPtr; - - // ShadowMap texture is defined by base DebugShadowMap - // osg::ref_ptr _texture; - - // ShadowMap camera is defined by base DebugShadowMap - // osg::ref_ptr _camera; - - osg::ref_ptr _texgen; - osg::ref_ptr _stateset; - - virtual void init( ThisClass * st, osgUtil::CullVisitor * cv ); - - virtual void cull( ); - - 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 cullShadowReceivingScene( ); - - virtual void cullShadowCastingScene( ); - - virtual void addShadowReceivingTexGen( ); - - virtual const osg::Light* selectLight( osg::Vec4 &viewLightPos, - osg::Vec3 &viewLightDir ); - - virtual void aimShadowCastingCamera( const osg::Light *light, - const osg::Vec4 &worldLightPos, - const osg::Vec3 &worldLightDir, - const osg::Vec3 &worldLightUp - = osg::Vec3(0,1,0) ); - }; - - META_ViewDependentShadowTechniqueData( ThisClass, ThisClass::ViewData ) -}; - -} // namespace osgShadow - -#endif +/* -*-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_STANDARDSHADOWMAP +#define OSGSHADOW_STANDARDSHADOWMAP 1 + +#include + +namespace osgShadow { + +class OSGSHADOW_EXPORT StandardShadowMap : public DebugShadowMap +{ + public : + /** Convenient typedef used in definition of ViewData struct and methods */ + typedef StandardShadowMap ThisClass; + /** Convenient typedef used in definition of ViewData struct and methods */ + typedef DebugShadowMap BaseClass; + + /** Classic OSG constructor */ + StandardShadowMap(); + + /** Classic OSG cloning constructor */ + StandardShadowMap(const StandardShadowMap& ssm, + const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); + + /** Declaration of standard OSG object methods */ + META_Object( ViewDependentShadow, StandardShadowMap ); + + void setBaseTextureUnit( unsigned int unit ) + { _baseTextureUnit = unit; dirty(); } + + unsigned int getBaseTextureUnit( void ) + { return _baseTextureUnit; } + + void setShadowTextureUnit( unsigned int unit ) + { _shadowTextureUnit = unit; dirty(); } + + unsigned int getShadowTextureUnit( void ) + { return _shadowTextureUnit; } + + // Texture Indices are changed by search and replace on shader source + // Carefully order these calls when changing both base and shadow indices + // In worst case when intend to swap indices + // one will have to call these methods more than once + // with one extra pass to change index to unused value to avoid + // unwanted superfluous replace: + // + // Example: Imagine we want to swap base(0) and shadow(1) indices: + // We have to do an extra step to make sure both do not end up as 1 + // + // // initialy change base to something else than 1 + // setBaseTextureCoordIndex( 100 ); + // // now search and replace all gl_TexCord[1] to gl_TexCord[0] + // setShadowTextureCoordIndex( 0 ); + // // finally change base from 100 to 0 + // setBaseTextureCoordIndex( 1 ); + + void setBaseTextureCoordIndex( unsigned int index ) + { updateTextureCoordIndices( _baseTextureCoordIndex, index ); + _baseTextureCoordIndex = index; } + + unsigned int getBaseTextureCoordIndex( void ) + { return _baseTextureCoordIndex; } + + // Texture Indices are changed by search and replace on shader source + // Look at the comment above setBaseTextureCoordIndex + + void setShadowTextureCoordIndex( unsigned int index ) + { updateTextureCoordIndices( _shadowTextureCoordIndex, index ); + _shadowTextureCoordIndex = index; } + + unsigned int getShadowTextureCoordIndex( void ) + { return _shadowTextureCoordIndex; } + + void setTextureSize( const osg::Vec2s& textureSize ) + { _textureSize = textureSize; dirty(); } + + osg::Vec2s getTextureSize( ) + { return _textureSize; } + + void setLight( osg::Light* light ) + { _light = light; } + + osg::Light* getLight( void ) + { return _light.get(); } + + osg::Shader * getShadowVertexShader() + { return _shadowVertexShader.get(); } + + osg::Shader * getShadowFragmentShader() + { return _shadowFragmentShader.get(); } + + osg::Shader * getMainVertexShader( ) + { return _mainVertexShader.get(); } + + osg::Shader * getMainFragmentShader( ) + { return _mainFragmentShader.get(); } + + void setShadowVertexShader( osg::Shader * shader ) + { _shadowVertexShader = shader; } + + void setShadowFragmentShader( osg::Shader * shader ) + { _shadowFragmentShader = shader; } + + void setMainVertexShader( osg::Shader * shader ) + { _mainVertexShader = shader; } + + void setMainFragmentShader( osg::Shader * shader ) + { _mainFragmentShader = shader; } + + protected: + /** Classic protected OSG destructor */ + virtual ~StandardShadowMap(void); + + virtual void updateTextureCoordIndices + ( unsigned int baseTexCoordIndex, unsigned int shadowTexCoordIndex ); + + virtual void searchAndReplaceShaderSource + ( osg::Shader*, std::string fromString, std::string toString ); + + osg::ref_ptr< osg::Shader > _mainVertexShader; + osg::ref_ptr< osg::Shader > _mainFragmentShader; + osg::ref_ptr< osg::Shader > _shadowVertexShader; + osg::ref_ptr< osg::Shader > _shadowFragmentShader; + + osg::ref_ptr< osg::Light > _light; + float _polygonOffsetFactor; + float _polygonOffsetUnits; + osg::Vec2s _textureSize; + unsigned int _baseTextureUnit; + unsigned int _shadowTextureUnit; + unsigned int _baseTextureCoordIndex; + unsigned int _shadowTextureCoordIndex; + + struct ViewData: public BaseClass::ViewData + { + osg::ref_ptr< osg::Light > * _lightPtr; + unsigned int * _baseTextureUnitPtr; + unsigned int * _shadowTextureUnitPtr; + + // ShadowMap texture is defined by base DebugShadowMap + // osg::ref_ptr _texture; + + // ShadowMap camera is defined by base DebugShadowMap + // osg::ref_ptr _camera; + + osg::ref_ptr _texgen; + osg::ref_ptr _stateset; + + virtual void init( ThisClass * st, osgUtil::CullVisitor * cv ); + + virtual void cull( ); + + 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 cullShadowReceivingScene( ); + + virtual void cullShadowCastingScene( ); + + virtual void addShadowReceivingTexGen( ); + + virtual const osg::Light* selectLight( osg::Vec4 &viewLightPos, + osg::Vec3 &viewLightDir ); + + virtual void aimShadowCastingCamera( const osg::Light *light, + const osg::Vec4 &worldLightPos, + const osg::Vec3 &worldLightDir, + const osg::Vec3 &worldLightUp + = osg::Vec3(0,1,0) ); + }; + + META_ViewDependentShadowTechniqueData( ThisClass, ThisClass::ViewData ) +}; + +} // namespace osgShadow + +#endif diff --git a/include/osgShadow/ViewDependentShadowTechnique b/include/osgShadow/ViewDependentShadowTechnique index 211f7bb2f..cba472cea 100644 --- a/include/osgShadow/ViewDependentShadowTechnique +++ b/include/osgShadow/ViewDependentShadowTechnique @@ -1,229 +1,229 @@ -/* -*-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_VIEWDEPENDENTSHADOWTECHINIQUE -#define OSGSHADOW_VIEWDEPENDENTSHADOWTECHINIQUE 1 - -#include -#include -#include - -namespace osgShadow { -/** - META_ViewDependentShadowTechniqueData macro defines initViewDependentData - method used by derived shadow techniques to initialize their specific - ViewData objects. initViewDependentData will be called from - ViewDependentShadowTechnique base class to init derived class -*/ -#define META_ViewDependentShadowTechniqueData( ShadowTechnique, TechniqueData )\ -virtual ViewDependentShadowTechnique::ViewData * initViewDependentData \ -( osgUtil::CullVisitor *cv, ViewDependentShadowTechnique::ViewData * vd ) \ -{ \ - TechniqueData* td = dynamic_cast( vd ); \ - if ( !td ) td = new TechniqueData; \ - td->init( this, cv ); \ - return td; \ -} - -/** - ViewDependentShadowTechnique is a base class for all - View Dependent Shadow techniques. It defines fundamental object structure - and methods to manage separate shadow resources for each view of the scene. - By view we understand osg::View or SceneView instance and their associated - Camera. Typical osg application has one or more such views. View Dependent - Shadow techniques manage shadow generation for them. - - View Dependent Shadow techniques are used to optimize shadow algorithms for - part of the scene seen on the view. If rest of the scene is behind view - frustum, there is no sense in computing shadows for it. Since in practice we - often use 3d databases extending far beyond current camera frustum View - Dependent Shadow approach may produce much better shadows. - - The other goal is to provide framework for thread safe rendering of - the shadows. It allows to use shadows with different OSG threading models. - - Conceptually ViewDependentShadowTechnique is similar to osgSim::OverlayNode. - Its a container class for number of ViewData (or ViewData derived) objects - doing actual shadow work for each of the scene views. - - But ViewDependentShadowTechnique is intended as foundation layer for all - derived classes so in some way it extends osgSim::OverlayNode approach a bit. - - HOW IT WORKS: - - ViewDependendentShadowTechnique is derived from osgShadow::ShadowTechnique - and as such overrides virtual methods of osgShadow::ShadowTechnique. - But most of the shadow dirty work is done by ViewData objects, - ViewDependendentShadowTechnique::cull is the only osgShadow::ShadowTechnique - method where ViewDependendentShadowTechnique does something significant: - - What ViewDependentShadowTechnique::cull( CullVisitor & cv ) does ? - It identifies View. CullVisitor ptr is used as View identificator. - In practice we do not check and interpret what are actual Views and SceneViews - set up by application. We focus on Camera and CullVisitors as a identificators - of views. We can safely do this because each such view will have associated - unique CullVisitor used to cull the scene in every frame. - - Based on CullVisitor ptr passed to cull method, associated Technique::ViewData - object is created (if neccessary) and then seleced. Then control is passed to - this ViewData object. So, each view has its associated unique ViewData - (or derived) object performing dirty work of shadow resources management and - shadow generation for the view. - - To support creation of classes derived from ViewDependentShadowTechnique it - was neccessary to provide mechanism to override ViewData and allow for - initialization of new derived ViewData objects. Creation and initialization - is performed when ViewDependendentShadowTechnique::cull gets called with - CullVistor ptr which does not yet have associated ViewData object. When it - happens, virtual initViewDependentData method is called to give - derived techniques a chance to allocate and iniitalize its specific - resources as new ViewData derived instance. In practice initViewDependentData - in derived techniques should look the same as in base class so as a convenience - it was defined as META_ViewDependentShadowTechnique macro. Derived techniques - use this macro to override initViewDependentData method for their usage. - - After ViewData derived object is construted and selected, control is passed - to this object by call to virtual ViewData::cull method. The rest of work - is the done by this object. ViewDependentShadowTechnique::ViewData is intended - as a base class so it does nothing. In practice the rest of dirty work will - do new ViewData classes implemented in derived techniques. -*/ -class OSGSHADOW_EXPORT ViewDependentShadowTechnique - : public osgShadow::ShadowTechnique -{ - public: - /** - osgShadow::ShadowTechnique equivalent methods for view dependent techniques - */ - - /** Classic OSG constructor */ - ViewDependentShadowTechnique( void ); - - /** Classic OSG cloning constructor */ - ViewDependentShadowTechnique( - const ViewDependentShadowTechnique& vdst, - const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY ); - - - /** Declaration of standard OSG object methods */ - META_Object( ViewDependentShadow, ViewDependentShadowTechnique ); - - /** Dirty view data bits and force update of view data resources */ - virtual void dirty(); - - /** Initialize the ShadowedScene and some data structures.*/ - virtual void init(); - - /** Run the update traversal of the ShadowedScene and update any local cached data structures.*/ - virtual void update(osg::NodeVisitor& nv); - - /** Run the cull traversal of the ShadowedScene and set up the rendering for this ShadowTechnique.*/ - virtual void cull(osgUtil::CullVisitor& cv); - - /** Clean scene graph from any shadow technique specific nodes, state and drawables.*/ - virtual void cleanSceneGraph(); - - /** Traverse shadow scene graph.*/ - virtual void traverse(osg::NodeVisitor& nv); - - protected: - /** Classic protected OSG destructor */ - ~ViewDependentShadowTechnique( void ); - - /** - Base container class for view dependent shadow resources. - Techniques based on ViewDependentShadowTechnique will usually define - similar struct and derive it from ViewData to contain their specufic resources. - */ - struct ViewData: public osg::Referenced - { - /** - Method called upon ViewData instance to initialize internal variables - */ - virtual void init - ( ViewDependentShadowTechnique *st, osgUtil::CullVisitor *cv ); - - /** - Method called by ViewDependentShadowTechnique to allow ViewData - do the hard work computing shadows for its associated view - */ - virtual void cull(); - - /** - Dirty is called by parent ViewDependentShadowTechnique to force - update of resources after some of them were modified in parent technique - */ - virtual void dirty( bool flag ); - - /** - Simple constructor zeroing all variables. - */ - ViewData(): _dirty( true ), _cv( NULL ), _st( NULL ) { }; - - /** - Mutex used to guard _dirty flag from override in case when parent technique calls - dirty() simultaneously with ViewData while it is updating resources inside init method. - */ - OpenThreads::Mutex _mutex; - - /** - View's CullVisitor associated with this ViewData instance - */ - osg::observer_ptr< osgUtil::CullVisitor > _cv; - - /** - Parent ViewDependentShadowTechnique - */ - osg::observer_ptr< ViewDependentShadowTechnique > _st; - - /** - Dirty flag tells this instance to update its resources - */ - bool _dirty; - }; - - /** - Map of view dependent data per view cull visitor (CVs are used as indices) - ViewDependentShadowTechnique uses this map to find VieData for each cull vitior - */ - - typedef std::map< osg::ref_ptr< osgUtil::CullVisitor >, - osg::ref_ptr< ViewData > > ViewDataMap; - - ViewDataMap _viewDataMap; - - - /** - Mutex used to serialize accesses to ViewDataMap - */ - OpenThreads::Mutex _viewDataMapMutex; - - /** Return view dependent data for the cull visitor */ - virtual ViewDependentShadowTechnique::ViewData * getViewDependentData( osgUtil::CullVisitor * cv ); - - /** Define view dependent data for the cull visitor */ - virtual void setViewDependentData( osgUtil::CullVisitor * cv, ViewDependentShadowTechnique::ViewData * data ); - - /** - Declare standard initViewDependentData method. - */ - META_ViewDependentShadowTechniqueData( ViewDependentShadowTechnique, ViewData ) -}; - - -} // namespace osgShadow - -#endif +/* -*-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_VIEWDEPENDENTSHADOWTECHINIQUE +#define OSGSHADOW_VIEWDEPENDENTSHADOWTECHINIQUE 1 + +#include +#include +#include + +namespace osgShadow { +/** + META_ViewDependentShadowTechniqueData macro defines initViewDependentData + method used by derived shadow techniques to initialize their specific + ViewData objects. initViewDependentData will be called from + ViewDependentShadowTechnique base class to init derived class +*/ +#define META_ViewDependentShadowTechniqueData( ShadowTechnique, TechniqueData )\ +virtual ViewDependentShadowTechnique::ViewData * initViewDependentData \ +( osgUtil::CullVisitor *cv, ViewDependentShadowTechnique::ViewData * vd ) \ +{ \ + TechniqueData* td = dynamic_cast( vd ); \ + if ( !td ) td = new TechniqueData; \ + td->init( this, cv ); \ + return td; \ +} + +/** + ViewDependentShadowTechnique is a base class for all + View Dependent Shadow techniques. It defines fundamental object structure + and methods to manage separate shadow resources for each view of the scene. + By view we understand osg::View or SceneView instance and their associated + Camera. Typical osg application has one or more such views. View Dependent + Shadow techniques manage shadow generation for them. + + View Dependent Shadow techniques are used to optimize shadow algorithms for + part of the scene seen on the view. If rest of the scene is behind view + frustum, there is no sense in computing shadows for it. Since in practice we + often use 3d databases extending far beyond current camera frustum View + Dependent Shadow approach may produce much better shadows. + + The other goal is to provide framework for thread safe rendering of + the shadows. It allows to use shadows with different OSG threading models. + + Conceptually ViewDependentShadowTechnique is similar to osgSim::OverlayNode. + Its a container class for number of ViewData (or ViewData derived) objects + doing actual shadow work for each of the scene views. + + But ViewDependentShadowTechnique is intended as foundation layer for all + derived classes so in some way it extends osgSim::OverlayNode approach a bit. + + HOW IT WORKS: + + ViewDependendentShadowTechnique is derived from osgShadow::ShadowTechnique + and as such overrides virtual methods of osgShadow::ShadowTechnique. + But most of the shadow dirty work is done by ViewData objects, + ViewDependendentShadowTechnique::cull is the only osgShadow::ShadowTechnique + method where ViewDependendentShadowTechnique does something significant: + + What ViewDependentShadowTechnique::cull( CullVisitor & cv ) does ? + It identifies View. CullVisitor ptr is used as View identificator. + In practice we do not check and interpret what are actual Views and SceneViews + set up by application. We focus on Camera and CullVisitors as a identificators + of views. We can safely do this because each such view will have associated + unique CullVisitor used to cull the scene in every frame. + + Based on CullVisitor ptr passed to cull method, associated Technique::ViewData + object is created (if neccessary) and then seleced. Then control is passed to + this ViewData object. So, each view has its associated unique ViewData + (or derived) object performing dirty work of shadow resources management and + shadow generation for the view. + + To support creation of classes derived from ViewDependentShadowTechnique it + was neccessary to provide mechanism to override ViewData and allow for + initialization of new derived ViewData objects. Creation and initialization + is performed when ViewDependendentShadowTechnique::cull gets called with + CullVistor ptr which does not yet have associated ViewData object. When it + happens, virtual initViewDependentData method is called to give + derived techniques a chance to allocate and iniitalize its specific + resources as new ViewData derived instance. In practice initViewDependentData + in derived techniques should look the same as in base class so as a convenience + it was defined as META_ViewDependentShadowTechnique macro. Derived techniques + use this macro to override initViewDependentData method for their usage. + + After ViewData derived object is construted and selected, control is passed + to this object by call to virtual ViewData::cull method. The rest of work + is the done by this object. ViewDependentShadowTechnique::ViewData is intended + as a base class so it does nothing. In practice the rest of dirty work will + do new ViewData classes implemented in derived techniques. +*/ +class OSGSHADOW_EXPORT ViewDependentShadowTechnique + : public osgShadow::ShadowTechnique +{ + public: + /** + osgShadow::ShadowTechnique equivalent methods for view dependent techniques + */ + + /** Classic OSG constructor */ + ViewDependentShadowTechnique( void ); + + /** Classic OSG cloning constructor */ + ViewDependentShadowTechnique( + const ViewDependentShadowTechnique& vdst, + const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY ); + + + /** Declaration of standard OSG object methods */ + META_Object( ViewDependentShadow, ViewDependentShadowTechnique ); + + /** Dirty view data bits and force update of view data resources */ + virtual void dirty(); + + /** Initialize the ShadowedScene and some data structures.*/ + virtual void init(); + + /** Run the update traversal of the ShadowedScene and update any local cached data structures.*/ + virtual void update(osg::NodeVisitor& nv); + + /** Run the cull traversal of the ShadowedScene and set up the rendering for this ShadowTechnique.*/ + virtual void cull(osgUtil::CullVisitor& cv); + + /** Clean scene graph from any shadow technique specific nodes, state and drawables.*/ + virtual void cleanSceneGraph(); + + /** Traverse shadow scene graph.*/ + virtual void traverse(osg::NodeVisitor& nv); + + protected: + /** Classic protected OSG destructor */ + ~ViewDependentShadowTechnique( void ); + + /** + Base container class for view dependent shadow resources. + Techniques based on ViewDependentShadowTechnique will usually define + similar struct and derive it from ViewData to contain their specufic resources. + */ + struct ViewData: public osg::Referenced + { + /** + Method called upon ViewData instance to initialize internal variables + */ + virtual void init + ( ViewDependentShadowTechnique *st, osgUtil::CullVisitor *cv ); + + /** + Method called by ViewDependentShadowTechnique to allow ViewData + do the hard work computing shadows for its associated view + */ + virtual void cull(); + + /** + Dirty is called by parent ViewDependentShadowTechnique to force + update of resources after some of them were modified in parent technique + */ + virtual void dirty( bool flag ); + + /** + Simple constructor zeroing all variables. + */ + ViewData(): _dirty( true ), _cv( NULL ), _st( NULL ) { }; + + /** + Mutex used to guard _dirty flag from override in case when parent technique calls + dirty() simultaneously with ViewData while it is updating resources inside init method. + */ + OpenThreads::Mutex _mutex; + + /** + View's CullVisitor associated with this ViewData instance + */ + osg::observer_ptr< osgUtil::CullVisitor > _cv; + + /** + Parent ViewDependentShadowTechnique + */ + osg::observer_ptr< ViewDependentShadowTechnique > _st; + + /** + Dirty flag tells this instance to update its resources + */ + bool _dirty; + }; + + /** + Map of view dependent data per view cull visitor (CVs are used as indices) + ViewDependentShadowTechnique uses this map to find VieData for each cull vitior + */ + + typedef std::map< osg::ref_ptr< osgUtil::CullVisitor >, + osg::ref_ptr< ViewData > > ViewDataMap; + + ViewDataMap _viewDataMap; + + + /** + Mutex used to serialize accesses to ViewDataMap + */ + OpenThreads::Mutex _viewDataMapMutex; + + /** Return view dependent data for the cull visitor */ + virtual ViewDependentShadowTechnique::ViewData * getViewDependentData( osgUtil::CullVisitor * cv ); + + /** Define view dependent data for the cull visitor */ + virtual void setViewDependentData( osgUtil::CullVisitor * cv, ViewDependentShadowTechnique::ViewData * data ); + + /** + Declare standard initViewDependentData method. + */ + META_ViewDependentShadowTechniqueData( ViewDependentShadowTechnique, ViewData ) +}; + + +} // namespace osgShadow + +#endif