root/OpenSceneGraph/trunk/include/osgShadow/DebugShadowMap @ 13041

Revision 13041, 7.6 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12 *
13 * ViewDependentShadow codes Copyright (C) 2008 Wojciech Lewandowski
14 * Thanks to to my company http://www.ai.com.pl for allowing me free this work.
15*/
16
17#ifndef OSGSHADOW_DEBUGSHADOWMAP
18#define OSGSHADOW_DEBUGSHADOWMAP 1
19
20#include <osgShadow/ViewDependentShadowTechnique>
21#include <osgShadow/ConvexPolyhedron>
22#include <osg/MatrixTransform>
23#include <osg/Geode>
24#include <osg/Geometry>
25#include <string>
26#include <map>
27
28namespace osgShadow {
29
30/**
31Class used as a layer for debuging resources used by derived xxxShadowMap classes.
32As designed by its base ViewDepndentShadowTechnique, DebugShadowMap serves mainly as container of
33DebugShadowMap::ViewData objects. Most of the debuging support work is done by these objects.
34DebugShadowMap technique only initializes them in initViewDependentData method.
35
36Debuging outputs present:
37    Shadow maps (pseudo colored to improve readability)
38    Shadow and related volumes (represented as convex polyhedra)
39*/
40
41class OSGSHADOW_EXPORT DebugShadowMap : public ViewDependentShadowTechnique
42{
43    public :
44
45        /*
46        All classes stemming from ViewDependentShadowTechnique follow the same pattern.
47
48        They are always based on some underlying level base Technique and they always
49        derive their ViewData from ViewData structure defined in underlying base Technique.
50
51        I use some typedefs to make these inheritance patterns easier to declare/define.
52        */
53
54        /** Convenient typedef used in definition of ViewData struct and methods */
55        typedef DebugShadowMap               ThisClass;
56        /** Convenient typedef used in definition of ViewData struct and methods */
57        typedef ViewDependentShadowTechnique BaseClass;
58
59        /** Classic OSG constructor */
60        DebugShadowMap();
61
62        /** Classic OSG cloning constructor */
63        DebugShadowMap(const DebugShadowMap& dsm, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
64
65        /** Declaration of standard OSG object methods */
66        META_Object( osgShadow, DebugShadowMap );
67
68        /** Turn on/off debuging hud & rendering of debug volumes in main view */
69        void setDebugDraw( bool draw ) { _doDebugDraw = draw; }
70
71        /** Tell if debuging hud & rendering of debug volumes is active */
72        bool getDebugDraw( void ) const { return _doDebugDraw; }
73
74        /** Get the file name of debuging dump */
75        std::string getDebugDump( void ) const { return _debugDump; }
76
77        /** Set the file name of debuging dump */
78        void setDebugDump( const std::string & debugDumpFile ) { _debugDump = debugDumpFile; }
79
80    protected:
81        /** Classic protected OSG destructor */
82        virtual ~DebugShadowMap();
83
84        // forward declare, interface and implementation provided in DebugShadowMap.cpp
85        class DrawableDrawWithDepthShadowComparisonOffCallback;
86
87        osg::Vec2s  _hudSize;
88        osg::Vec2s  _hudOrigin;
89        osg::Vec2s  _viewportSize;
90        osg::Vec2s  _viewportOrigin;
91        osg::Vec2s  _orthoSize;
92        osg::Vec2s  _orthoOrigin;
93
94        bool        _doDebugDraw;
95        std::string _debugDump;
96
97        osg::ref_ptr< osg::Shader > _depthColorFragmentShader;
98
99        struct OSGSHADOW_EXPORT ViewData: public BaseClass::ViewData
100        {
101            /**
102            Texture used as ShadowMap - initialized by derived classes.
103            But it has to be defined now since DebugShadowMap::ViewData methods use it
104            */
105            osg::ref_ptr< osg::Texture >   _texture;
106            /**
107            Camera used to render ShadowMap - initialized by derived classes.
108            But it has to be defined now since DebugShadowMap::ViewData methods use it
109            */
110            osg::ref_ptr< osg::Camera >    _camera;
111
112            osg::Matrixd                   _viewProjection;
113            osg::observer_ptr<osg::Camera> _viewCamera;
114
115            // Debug hud variables
116
117            /** Coloring Shader used to present shadow depth map contents */
118            osg::ref_ptr< osg::Shader >    _depthColorFragmentShader;
119
120            struct PolytopeGeometry {
121
122                ConvexPolyhedron                 _polytope;
123                osg::ref_ptr< osg::Geometry >    _geometry[2];
124                osg::Vec4                        _colorOutline;
125                osg::Vec4                        _colorInside;
126            };
127
128            typedef std::map< std::string, PolytopeGeometry > PolytopeGeometryMap;
129
130            osg::Vec2s                                _hudSize;
131            osg::Vec2s                                _hudOrigin;
132            osg::Vec2s                                _viewportSize;
133            osg::Vec2s                                _viewportOrigin;
134            osg::Vec2s                                _orthoSize;
135            osg::Vec2s                                _orthoOrigin;
136
137            bool                                     *_doDebugDrawPtr;
138            std::string                              *_debugDumpPtr;
139
140            PolytopeGeometryMap                       _polytopeGeometryMap;
141            osg::ref_ptr< osg::Geode >                _geode[2];
142            osg::ref_ptr< osg::MatrixTransform >      _transform[2];
143
144            std::map< std::string, osg::Matrix >      _matrixMap;
145            std::map< std::string, osg::Polytope >    _polytopeMap;
146            std::map< std::string, osg::BoundingBox > _boundingBoxMap;
147
148            osg::ref_ptr<osg::Camera>                 _cameraDebugHUD;
149
150            bool          getDebugDraw()    { return *_doDebugDrawPtr; }
151            std::string * getDebugDump()    { return _debugDumpPtr; }
152
153            virtual void init( ThisClass * st, osgUtil::CullVisitor * cv );
154
155            virtual void cull( );
156
157            virtual void createDebugHUD( void );
158
159            virtual void cullDebugGeometry( );
160
161            virtual void updateDebugGeometry( const osg::Camera * screenCam,
162                const osg::Camera * shadowCam );
163
164            void setDebugPolytope( const char * name,
165                const ConvexPolyhedron & polytope = *(ConvexPolyhedron*)( NULL ),
166                osg::Vec4 colorOutline = osg::Vec4(0,0,0,0),
167                osg::Vec4 colorInside = osg::Vec4(0,0,0,0) );
168
169            bool DebugBoundingBox( const osg::BoundingBox & bb, const char * name = "" );
170            bool DebugPolytope( const osg::Polytope & p, const char * name = "" );
171            bool DebugMatrix( const osg::Matrix & m, const char * name = "" );
172
173            static osg::Vec3d computeShadowTexelToPixelError
174                ( const osg::Matrix & mvpwView,
175                  const osg::Matrix & mvpwShadow,
176                  const osg::Vec3d & vWorld,
177                  const osg::Vec3d & vDelta = osg::Vec3d( 0.01,0.01,0.01 ) );
178
179            static void displayShadowTexelToPixelErrors
180                ( const osg::Camera * viewCam,
181                  const osg::Camera * shadowCam,
182                  const ConvexPolyhedron * hull );
183
184            void dump( const std::string & filename );
185        };
186
187        META_ViewDependentShadowTechniqueData( ThisClass, ViewData )
188};
189
190} // namespace osgShadow
191
192#endif
Note: See TracBrowser for help on using the browser.