| [8985] | 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 | |
|---|
| 18 | #ifndef OSGSHADOW_MINIMALDRAWBOUNDSSHADOWMAP |
|---|
| 19 | #define OSGSHADOW_MINIMALDRAWBOUNDSSHADOWMAP 1 |
|---|
| 20 | |
|---|
| 21 | #include <osgShadow/MinimalShadowMap> |
|---|
| 22 | |
|---|
| 23 | namespace osgShadow { |
|---|
| 24 | |
|---|
| 25 | class OSGSHADOW_EXPORT MinimalDrawBoundsShadowMap |
|---|
| 26 | : public MinimalShadowMap |
|---|
| 27 | { |
|---|
| 28 | public : |
|---|
| 29 | /** Convenient typedef used in definition of ViewData struct and methods */ |
|---|
| 30 | typedef MinimalDrawBoundsShadowMap ThisClass; |
|---|
| 31 | /** Convenient typedef used in definition of ViewData struct and methods */ |
|---|
| 32 | typedef MinimalShadowMap BaseClass; |
|---|
| 33 | |
|---|
| 34 | /** Classic OSG constructor */ |
|---|
| 35 | MinimalDrawBoundsShadowMap(); |
|---|
| 36 | |
|---|
| 37 | /** Classic OSG cloning constructor */ |
|---|
| 38 | MinimalDrawBoundsShadowMap( |
|---|
| 39 | const MinimalDrawBoundsShadowMap& mdbsm, |
|---|
| 40 | const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); |
|---|
| 41 | |
|---|
| 42 | /** Declaration of standard OSG object methods */ |
|---|
| 43 | META_Object( ViewDependentShadow, MinimalDrawBoundsShadowMap ); |
|---|
| 44 | |
|---|
| 45 | protected: |
|---|
| 46 | /** Classic protected OSG destructor */ |
|---|
| 47 | virtual ~MinimalDrawBoundsShadowMap(void); |
|---|
| 48 | |
|---|
| [9113] | 49 | struct OSGSHADOW_EXPORT ViewData: public BaseClass::ViewData |
|---|
| [8985] | 50 | { |
|---|
| 51 | osg::ref_ptr< osg::RefMatrix > _projection; |
|---|
| 52 | osg::Vec2s _boundAnalysisSize; |
|---|
| 53 | osg::ref_ptr< osg::Image > _boundAnalysisImage; |
|---|
| 54 | osg::ref_ptr< osg::Texture2D > _boundAnalysisTexture; |
|---|
| 55 | osg::ref_ptr< osg::Camera > _boundAnalysisCamera; |
|---|
| [9555] | 56 | osg::observer_ptr< osg::Camera > _mainCamera; |
|---|
| [8985] | 57 | |
|---|
| 58 | void setShadowCameraProjectionMatrixPtr( osg::RefMatrix * projection ) |
|---|
| 59 | { _projection = projection; } |
|---|
| 60 | |
|---|
| 61 | osg::RefMatrix * getShadowCameraProjectionMatrixPtr( void ) |
|---|
| 62 | { return _projection.get(); } |
|---|
| 63 | |
|---|
| 64 | virtual void init( ThisClass * st, osgUtil::CullVisitor * cv ); |
|---|
| 65 | |
|---|
| 66 | virtual void cullShadowReceivingScene( ); |
|---|
| 67 | |
|---|
| 68 | virtual void createDebugHUD( ); |
|---|
| 69 | |
|---|
| 70 | virtual void recordShadowMapParams( ); |
|---|
| 71 | |
|---|
| 72 | virtual void cullBoundAnalysisScene( ); |
|---|
| 73 | |
|---|
| 74 | static osg::BoundingBox scanImage( const osg::Image * image, osg::Matrix m ); |
|---|
| 75 | |
|---|
| 76 | virtual void performBoundAnalysis( const osg::Camera& camera ); |
|---|
| 77 | |
|---|
| 78 | ViewData( void ): _boundAnalysisSize( 64, 64 ) {} |
|---|
| 79 | }; |
|---|
| 80 | |
|---|
| [9011] | 81 | friend struct ViewData; |
|---|
| 82 | |
|---|
| [8985] | 83 | META_ViewDependentShadowTechniqueData( ThisClass, ThisClass::ViewData ) |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | struct CameraPostDrawCallback : public osg::Camera::DrawCallback { |
|---|
| 87 | |
|---|
| 88 | CameraPostDrawCallback( ViewData * vd ): _vd( vd ) |
|---|
| 89 | { |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | virtual void operator ()( const osg::Camera& camera ) const |
|---|
| 93 | { |
|---|
| 94 | if( _vd.valid() ) |
|---|
| 95 | _vd->performBoundAnalysis( camera ); |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | osg::observer_ptr< ViewData > _vd; |
|---|
| 99 | }; |
|---|
| 100 | |
|---|
| 101 | struct CameraCullCallback: public osg::NodeCallback { |
|---|
| 102 | |
|---|
| 103 | CameraCullCallback(ViewData * vd, osg::NodeCallback * nc): _vd(vd), _nc(nc) |
|---|
| 104 | { |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) |
|---|
| 108 | { |
|---|
| 109 | osgUtil::CullVisitor *cv = dynamic_cast< osgUtil::CullVisitor *>( nv ); |
|---|
| 110 | |
|---|
| 111 | if( _nc.valid() ) |
|---|
| 112 | _nc->operator()(node,nv); |
|---|
| 113 | else |
|---|
| 114 | traverse(node,nv); |
|---|
| 115 | |
|---|
| 116 | if( cv ) |
|---|
| 117 | _vd->recordShadowMapParams( ); |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | protected: |
|---|
| [9376] | 121 | osg::observer_ptr< ViewData > _vd; |
|---|
| [8985] | 122 | osg::ref_ptr< osg::NodeCallback > _nc; |
|---|
| 123 | }; |
|---|
| 124 | }; |
|---|
| 125 | |
|---|
| 126 | } // namespace osgShadow |
|---|
| 127 | |
|---|
| 128 | #endif |
|---|