Changeset 13041 for OpenSceneGraph/trunk/src/osgShadow/ShadowMap.cpp
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osgShadow/ShadowMap.cpp (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgShadow/ShadowMap.cpp
r11137 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 */ … … 35 35 // fragment shader 36 36 // 37 static const char fragmentShaderSource_noBaseTexture[] = 37 static const char fragmentShaderSource_noBaseTexture[] = 38 38 "uniform sampler2DShadow osgShadow_shadowTexture; \n" 39 39 "uniform vec2 osgShadow_ambientBias; \n" … … 47 47 // fragment shader 48 48 // 49 static const char fragmentShaderSource_withBaseTexture[] = 49 static const char fragmentShaderSource_withBaseTexture[] = 50 50 "uniform sampler2D osgShadow_baseTexture; \n" 51 51 "uniform sampler2DShadow osgShadow_shadowTexture; \n" … … 217 217 #if 1 218 218 // cull front faces so that only backfaces contribute to depth map 219 219 220 220 221 221 osg::ref_ptr<osg::CullFace> cull_face = new osg::CullFace; … … 252 252 253 253 { 254 _stateset = new osg::StateSet; 254 _stateset = new osg::StateSet; 255 255 _stateset->setTextureAttributeAndModes(_shadowTextureUnit,_texture.get(),osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); 256 256 _stateset->setTextureMode(_shadowTextureUnit,GL_TEXTURE_GEN_S,osg::StateAttribute::ON); … … 375 375 376 376 osg::RefMatrix* matrix = itr->second.get(); 377 if (matrix) 377 if (matrix) 378 378 { 379 379 lightpos = light->getPosition() * (*matrix); 380 380 lightDir = osg::Matrix::transform3x3( light->getDirection(), *matrix ); 381 381 } 382 else 382 else 383 383 { 384 384 lightpos = light->getPosition(); … … 392 392 eyeToWorld.invert(*cv.getModelViewMatrix()); 393 393 394 lightpos = lightpos * eyeToWorld; 394 lightpos = lightpos * eyeToWorld; 395 395 lightDir = osg::Matrix::transform3x3( lightDir, eyeToWorld ); 396 396 lightDir.normalize(); … … 413 413 else 414 414 { 415 // get the bounds of the model. 415 // get the bounds of the model. 416 416 osg::ComputeBoundsVisitor cbbv(osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN); 417 417 cbbv.setTraversalMask(getShadowedScene()->getCastsShadowTraversalMask()); … … 464 464 } 465 465 466 cv.setTraversalMask( traversalMask & 466 cv.setTraversalMask( traversalMask & 467 467 getShadowedScene()->getCastsShadowTraversalMask() ); 468 468 … … 486 486 cv.getRenderStage()->getPositionalStateContainer()-> 487 487 addPositionedTextureAttribute( _shadowTextureUnit, refMatrix, _texgen.get() ); 488 #else 488 #else 489 489 // compute the matrix which takes a vertex from local coords into tex coords 490 490 // will use this later to specify osg::TexGen.. 491 osg::Matrix MVPT = _camera->getViewMatrix() * 491 osg::Matrix MVPT = _camera->getViewMatrix() * 492 492 _camera->getProjectionMatrix() * 493 493 osg::Matrix::translate(1.0,1.0,1.0) * … … 513 513 //////////////////////////////////////////////////////////////////////////////// 514 514 // Callback used by debugging hud to display Shadow Map in color buffer 515 // OSG does not allow to use the same GL Texture Id with different glTexParams. 516 // Callback simply turns shadow compare mode off via GL while rendering hud and 517 // restores it afterwards. 515 // OSG does not allow to use the same GL Texture Id with different glTexParams. 516 // Callback simply turns shadow compare mode off via GL while rendering hud and 517 // restores it afterwards. 518 518 //////////////////////////////////////////////////////////////////////////////// 519 class ShadowMap::DrawableDrawWithDepthShadowComparisonOffCallback: 519 class ShadowMap::DrawableDrawWithDepthShadowComparisonOffCallback: 520 520 public osg::Drawable::DrawCallback 521 521 { 522 522 public: 523 // 523 // 524 524 DrawableDrawWithDepthShadowComparisonOffCallback 525 525 ( osg::Texture2D * texture, unsigned stage = 0 ) … … 536 536 537 537 // Turn off depth comparison mode 538 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, 538 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, 539 539 GL_NONE ); 540 540 } … … 544 544 if( _texture.valid() ) { 545 545 // Turn it back on 546 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, 546 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, 547 547 GL_COMPARE_R_TO_TEXTURE_ARB ); 548 548 } … … 565 565 camera->setProjectionMatrix(osg::Matrix::ortho2D(0,size.x(),0,size.y())); 566 566 567 // set the view matrix 567 // set the view matrix 568 568 camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); 569 569 camera->setViewMatrix(osg::Matrix::identity()); … … 583 583 584 584 osg::Vec3 position(10.0f,size.y()-100.0f,0.0f); 585 osg::Vec3 delta(0.0f,-120.0f,0.0f); 585 osg::Vec3 delta(0.0f,-120.0f,0.0f); 586 586 float length = 300.0f; 587 587
