- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgShadow/MinimalDrawBoundsShadowMap.cpp
r12292 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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 * … … 48 48 49 49 void MinimalDrawBoundsShadowMap::ViewData::cullShadowReceivingScene( ) 50 { 50 { 51 51 BaseClass::ViewData::cullShadowReceivingScene( ); 52 52 ThisClass::ViewData::cullBoundAnalysisScene( ); … … 60 60 61 61 osg::Matrixd::value_type l,r,b,t,n,f; 62 _boundAnalysisCamera->getProjectionMatrixAsFrustum( l,r,b,t,n,f ); 62 _boundAnalysisCamera->getProjectionMatrixAsFrustum( l,r,b,t,n,f ); 63 63 64 64 _mainCamera = _cv->getRenderStage()->getCamera(); 65 65 66 66 extendProjection( _boundAnalysisCamera->getProjectionMatrix(), 67 _boundAnalysisCamera->getViewport(), osg::Vec2( 2,2 ) ); 67 _boundAnalysisCamera->getViewport(), osg::Vec2( 2,2 ) ); 68 68 69 69 // record the traversal mask on entry so we can reapply it later. 70 70 unsigned int traversalMask = _cv->getTraversalMask(); 71 71 72 _cv->setTraversalMask( traversalMask & 72 _cv->setTraversalMask( traversalMask & 73 73 _st->getShadowedScene()->getReceivesShadowTraversalMask() ); 74 74 … … 96 96 osg::Geometry* geometry = osg::createTexturedQuadGeometry 97 97 ( osg::Vec3(_hudOrigin[0]+_hudSize[0],_hudOrigin[1],0), 98 osg::Vec3(_hudSize[0],0,0), 98 osg::Vec3(_hudSize[0],0,0), 99 99 osg::Vec3(0,_hudSize[1],0) ); 100 100 … … 120 120 osg::BoundingBox bb, bbProj; 121 121 122 int components = osg::Image::computeNumComponents( image->getPixelFormat() ); 122 int components = osg::Image::computeNumComponents( image->getPixelFormat() ); 123 123 124 124 if( image->getDataType() == GL_FLOAT ) { 125 float scale = 255.f / 254.f; 125 float scale = 255.f / 254.f; 126 126 float * pf = (float *)image->data(); 127 127 for( int y = 0; y < image->t(); y++ ) { … … 134 134 bbProj.expandBy( osg::Vec3( fX, fY, fMinZ ) ); 135 135 bb.expandBy( osg::Vec3( fX, fY, fMinZ ) * m ); 136 136 137 137 if( components > 1 ) { 138 138 float fMaxZ = scale * ( 1.f - pf[1] ); … … 165 165 float fMaxZ = scale * (255 - pb[1] + 0.5f); 166 166 fMaxZ = osg::clampTo( fMaxZ, 0.f, 1.f ); 167 167 168 168 bbProj.expandBy( osg::Vec3( fX, fY, fMaxZ ) ); 169 169 bb.expandBy( osg::Vec3( fX, fY, fMaxZ ) * m ); … … 184 184 return; 185 185 186 osg::Camera::BufferAttachmentMap & bam 186 osg::Camera::BufferAttachmentMap & bam 187 187 = const_cast<osg::Camera&>( camera ).getBufferAttachmentMap(); 188 188 #if ANALYSIS_DEPTH … … 193 193 194 194 const osg::ref_ptr< osg::Image > image = attachment._image.get(); 195 if( !image.valid() ) 195 if( !image.valid() ) 196 196 return; 197 197 198 198 osg::Matrix m; 199 m.invert( *_modellingSpaceToWorldPtr * 200 camera.getViewMatrix() * 199 m.invert( *_modellingSpaceToWorldPtr * 200 camera.getViewMatrix() * 201 201 camera.getProjectionMatrix() ); 202 202 … … 206 206 osg::BoundingBox bb = scanImage( image.get(), m ); 207 207 208 if( getDebugDraw() ) { 208 if( getDebugDraw() ) { 209 209 ConvexPolyhedron p; 210 210 p.setToBoundingBox( bb ); 211 p.transform( *_modellingSpaceToWorldPtr, 211 p.transform( *_modellingSpaceToWorldPtr, 212 212 osg::Matrix::inverse( *_modellingSpaceToWorldPtr ) ); 213 213 … … 216 216 } 217 217 218 cutScenePolytope( *_modellingSpaceToWorldPtr, 218 cutScenePolytope( *_modellingSpaceToWorldPtr, 219 219 osg::Matrix::inverse( *_modellingSpaceToWorldPtr ), bb ); 220 220 … … 234 234 { 235 235 const osgUtil::RenderStage * rs = _cv->getCurrentRenderBin()->getStage(); 236 236 237 237 setShadowCameraProjectionMatrixPtr( _cv->getProjectionMatrix() ); 238 238 239 if( !rs->getRenderBinList().empty() || rs->getBinNum() != 0 ) 239 if( !rs->getRenderBinList().empty() || rs->getBinNum() != 0 ) 240 240 { 241 241 242 242 } 243 243 #if 0 … … 249 249 250 250 std::set< osg::ref_ptr< osg::RefMatrix > > projections; 251 251 252 252 MinimalShadowMap::GetRenderLeaves( , rll ); 253 for( unsigned i =0; i < rll.size(); i++ ) { 253 for( unsigned i =0; i < rll.size(); i++ ) { 254 254 if( rll[i]->_projection.get() != _projection.get() ) { 255 255 osg::RefMatrix * projection = rll[i]->_projection.get(); 256 projections.insert( rll[i]->_projection ); 256 projections.insert( rll[i]->_projection ); 257 257 c++; 258 258 } 259 259 } 260 260 261 if( projections.size() > 0 ) 261 if( projections.size() > 0 ) 262 262 _projection = (*projections.begin()).get(); 263 263 … … 271 271 { 272 272 BaseClass::ViewData::init( st, cv ); 273 273 274 274 _frameShadowCastingCameraPasses = 2; 275 275 _camera->setCullCallback 276 276 ( new CameraCullCallback( this, _camera->getCullCallback() ) ); 277 277 278 278 _boundAnalysisTexture = new osg::Texture2D; 279 279 _boundAnalysisTexture->setTextureSize … … 288 288 GL_DEPTH_COMPONENT, GL_FLOAT ); 289 289 290 _boundAnalysisTexture->setInternalFormat(GL_DEPTH_COMPONENT); 290 _boundAnalysisTexture->setInternalFormat(GL_DEPTH_COMPONENT); 291 291 // _boundAnalysisTexture->setShadowComparison(true); 292 292 _boundAnalysisTexture->setShadowTextureMode(osg::Texture2D::LUMINANCE); … … 299 299 #if USE_FLOAT_IMAGE 300 300 _boundAnalysisImage->allocateImage( _boundAnalysisSize[0], 301 _boundAnalysisSize[1], 1, 301 _boundAnalysisSize[1], 1, 302 302 GL_RGBA, GL_FLOAT ); 303 303 … … 306 306 #else 307 307 _boundAnalysisImage->allocateImage( _boundAnalysisSize[0], 308 _boundAnalysisSize[1], 1, 308 _boundAnalysisSize[1], 1, 309 309 GL_RGBA, GL_UNSIGNED_BYTE ); 310 310 … … 326 326 _boundAnalysisTexture->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::REPEAT); 327 327 328 // set up the render to texture camera. 328 // set up the render to texture camera. 329 329 // create the camera 330 330 _boundAnalysisCamera = new osg::Camera;
