 Timestamp:
 03/21/12 18:36:20 (5 years ago)
 Files:

 1 modified
Legend:
 Unmodified
 Added
 Removed

OpenSceneGraph/trunk/src/osgShadow/MinimalCullBoundsShadowMap.cpp
r12577 r13041 1 /* *c++* OpenSceneGraph  Copyright (C) 19982006 Robert Osfield 1 /* *c++* OpenSceneGraph  Copyright (C) 19982006 Robert Osfield 2 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 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 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 * … … 34 34 } 35 35 36 MinimalCullBoundsShadowMap::~MinimalCullBoundsShadowMap() 36 MinimalCullBoundsShadowMap::~MinimalCullBoundsShadowMap() 37 37 { 38 38 } … … 48 48 ( const osg::Light *light, 49 49 const osg::Vec4 &lightPos, 50 const osg::Vec3 &lightDir, 50 const osg::Vec3 &lightDir, 51 51 const osg::Vec3 &lightUp ) 52 52 { … … 61 61 { 62 62 RenderLeafList rllOld, rllNew; 63 63 64 64 GetRenderLeaves( _cv>getRenderStage(), rllOld ); 65 65 … … 71 71 RemoveIgnoredRenderLeaves( rllNew ); 72 72 73 osg::Matrix projectionToModelSpace = 74 osg::Matrix::inverse( *_modellingSpaceToWorldPtr * 73 osg::Matrix projectionToModelSpace = 74 osg::Matrix::inverse( *_modellingSpaceToWorldPtr * 75 75 *_cv>getModelViewMatrix() * *_cv>getProjectionMatrix() ); 76 76 … … 79 79 80 80 osg::Polytope polytope; 81 #if 1 81 #if 1 82 82 polytope.setToUnitFrustum(); 83 83 #else … … 86 86 polytope.transformProvidingInverse( *_modellingSpaceToWorldPtr * 87 87 *_cv>getModelViewMatrix() * _clampedProjection ); 88 88 89 89 bb = ComputeRenderLeavesBounds( rllNew, projectionToModelSpace, polytope ); 90 90 } else { 91 91 bb = ComputeRenderLeavesBounds( rllNew, projectionToModelSpace ); 92 92 } 93 94 cutScenePolytope( *_modellingSpaceToWorldPtr, 93 94 cutScenePolytope( *_modellingSpaceToWorldPtr, 95 95 osg::Matrix::inverse( *_modellingSpaceToWorldPtr ), bb ); 96 96 } … … 102 102 osgUtil::RenderBin::RenderBinList::const_iterator rbitr; 103 103 104 // scan pre render bins 104 // scan pre render bins 105 105 for(rbitr = bins.begin(); rbitr!=bins.end() && rbitr>first<0; ++rbitr ) 106 106 GetRenderLeaves( rbitr>second.get(), rll ); … … 111 111 for( rlitr= renderLeafList.begin(); rlitr!= renderLeafList.end(); ++rlitr ) 112 112 { 113 rll.push_back( *rlitr ); 113 rll.push_back( *rlitr ); 114 114 } 115 115 116 116 // scan coarse grained ordering. 117 117 osgUtil::RenderBin::StateGraphList& stateGraphList = rb>getStateGraphList(); 118 osgUtil::RenderBin::StateGraphList::const_iterator oitr; 118 osgUtil::RenderBin::StateGraphList::const_iterator oitr; 119 119 for( oitr= stateGraphList.begin(); oitr!= stateGraphList.end(); ++oitr ) 120 120 { 121 for( osgUtil::StateGraph::LeafList::const_iterator dw_itr = 121 for( osgUtil::StateGraph::LeafList::const_iterator dw_itr = 122 122 (*oitr)>_leaves.begin(); dw_itr != (*oitr)>_leaves.end(); ++dw_itr) 123 123 { … … 127 127 128 128 // scan post render bins 129 for(; rbitr!=bins.end(); ++rbitr ) 129 for(; rbitr!=bins.end(); ++rbitr ) 130 130 GetRenderLeaves( rbitr>second.get(), rll ); 131 131 } … … 137 137 if ( !a ) return false; // NULL render leaf goes last 138 138 return !b  139 a>_projection < b>_projection  139 a>_projection < b>_projection  140 140 (a>_projection == b>_projection && a>_modelview < b>_modelview); 141 141 } … … 171 171 for( int i = 0; i < 3; i ++ ) 172 172 for( int j = 0; j < 3; j ++ ) 173 if( s[i][j] < 0 ) bb._min[j] += s[i][j]; else bb._max[j] += s[i][j]; 173 if( s[i][j] < 0 ) bb._min[j] += s[i][j]; else bb._max[j] += s[i][j]; 174 174 #else 175 175 b.expandBy( o + s[0] ); … … 216 216 unsigned count = 0; 217 217 218 for( RenderLeafList::iterator it = rll.begin(); it != rll.end(); ++it ) 218 for( RenderLeafList::iterator it = rll.begin(); it != rll.end(); ++it ) 219 219 { 220 220 if( !*it ) continue; … … 226 226 227 227 if( !strcmp( name, "LightPointDrawable" )  228 !strcmp( name, "LightPointSpriteDrawable" ) ) 228 !strcmp( name, "LightPointSpriteDrawable" ) ) 229 229 { 230 230 *it = NULL; //ignored = invalidate this in new render leaves list 231 count++; 231 count++; 232 232 } 233 233 } … … 238 238 osg::BoundingBox MinimalCullBoundsShadowMap::ViewData::ComputeRenderLeavesBounds 239 239 ( RenderLeafList &rll, osg::Matrix & projectionToWorld ) 240 { 240 { 241 241 osg::BoundingBox bbResult; 242 242 … … 259 259 // Don't trust already computed bounds for cull generated drawables 260 260 // LightPointDrawable & LightPointSpriteDrawable are such examples 261 // they store wrong recorded bounds from very first pass 262 if( rl && rl>_modelview == NULL ) 261 // they store wrong recorded bounds from very first pass 262 if( rl && rl>_modelview == NULL ) 263 263 rl>_drawable>dirtyBound(); 264 264 … … 268 268 } else { 269 269 if( bb.valid() ) { 270 // Conditions to avoid matrix multiplications 271 if( projection.valid() ) 270 // Conditions to avoid matrix multiplications 271 if( projection.valid() ) 272 272 { 273 if( projection.get() != ptrProjection ) 273 if( projection.get() != ptrProjection ) 274 274 { 275 275 ptrProjection = projection.get(); … … 281 281 } 282 282 283 if( modelview.valid() ) 283 if( modelview.valid() ) 284 284 { 285 285 modelToWorld = *modelview.get() * *ptrViewToWorld; … … 292 292 bbResult.expandBy( bb.corner( i ) * *ptrModelToWorld ); 293 293 } 294 if( !rl ) break; 294 if( !rl ) break; 295 295 bb = rl>_drawable>getBound(); 296 296 modelview = rl>_modelview; … … 306 306 osg::BoundingBox MinimalCullBoundsShadowMap::ViewData::ComputeRenderLeavesBounds 307 307 ( RenderLeafList &rll, osg::Matrix & projectionToWorld, osg::Polytope & p ) 308 { 308 { 309 309 osg::BoundingBox bbResult, bb; 310 310 … … 317 317 osg::Matrix viewToWorld, modelToWorld, 318 318 *ptrProjection = NULL, 319 *ptrViewToWorld = &projectionToWorld, 319 *ptrViewToWorld = &projectionToWorld, 320 320 *ptrModelToWorld = NULL; 321 321 … … 328 328 // Don't trust already computed bounds for cull generated drawables 329 329 // LightPointDrawable & LightPointSpriteDrawable are such examples 330 // they store wrong recorded bounds from very first pass 330 // they store wrong recorded bounds from very first pass 331 331 if(rl>_modelview == NULL ) 332 332 rl>_drawable>dirtyBound(); … … 334 334 bb = rl>_drawable>getBound(); 335 335 if( !bb.valid() ) continue; 336 336 337 337 // Stay as long as possible in model space to minimize matrix ops 338 338 if( rl>_modelview != modelview  rl>_projection != projection ) { 339 339 340 340 projection = rl>_projection; 341 if( projection.valid() ) 341 if( projection.valid() ) 342 342 { 343 if( projection.get() != ptrProjection ) 343 if( projection.get() != ptrProjection ) 344 344 { 345 345 ptrProjection = projection.get(); … … 352 352 353 353 modelview = rl>_modelview; 354 if( modelview.valid() ) 354 if( modelview.valid() ) 355 355 { 356 356 modelToWorld = *modelview.get() * *ptrViewToWorld;