Show
Ignore:
Timestamp:
03/01/10 12:52:44 (4 years ago)
Author:
robert
Message:

From Wojciech Lewandowski, "Here comes a list of small fixes in StandardShadowMap? and derived classes affecting LispSM techniques. Changes made against SVN trunk.

Fixes in StandardShadowMap?.cpp & MinimalShadowMap?.cpp were made for spotlight issues. There were cases when further located spotlights were not shadowing properly.

Small tweak in DebugShadowMap? & StandardShadowMap?.cpp to not limit shadow maps to texture2D (which should also allow texture2D arrays and cube maps). I simply replaced ptr to osg::Texture2D with pointer to osg::Texture. Interpretation of this member could be now changed with change of shaders in derived classes. This may be useful for guys who override LispSM or MinimalBoundsShadowMaps? techniques. Could be useful for implementation of PerspectiveCascadedShadowMaps? technique for example.

ConvexPolyhedron?.cpp & DebugShadowMap?.cpp contain debug HUD tweaks.

Change in ConvexPolyhedron?.cpp overcomes the regression problem with color per primitive binding which caused that shadow volume outlines stopped to draw. I simply changed PER_PRIMITIVE to PER_PRIMITIVE_SET and it works again.

Other adition is dump method I added to DebugShadowMap? which can be used in shadow debugging mode to dump current frame shadow volumes & scene to osg file. It could be then loaded into viewer and freely examined from different angles (which is difficult inside the application if shadow adopts to view and projection). "

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgShadow/DebugShadowMap.cpp

    r9555 r11136  
    1414 * Thanks to to my company http://www.ai.com.pl for allowing me free this work. 
    1515*/ 
    16  
     16#include <osgShadow/ShadowedScene> 
    1717#include <osgShadow/DebugShadowMap> 
    1818#include <osgShadow/ConvexPolyhedron> 
    1919#include <osgUtil/RenderLeaf> 
     20#include <osgDB/WriteFile> 
    2021#include <osg/Geometry> 
    2122#include <osg/PrimitiveSet> 
     
    416417{ 
    417418public: 
    418     DrawableDrawWithDepthShadowComparisonOffCallback( osg::Texture2D *pTex )  
     419    DrawableDrawWithDepthShadowComparisonOffCallback( osg::Texture *pTex )  
    419420        : _pTexture( pTex ) 
    420421    { 
     
    427428 
    428429        // Turn off depth comparison mode 
    429         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE ); 
     430        glTexParameteri( _pTexture->getTextureTarget(), GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE ); 
    430431 
    431432        drawable->drawImplementation(ri); 
    432433 
    433434        // Turn it back on 
    434         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB,  
     435        glTexParameteri( _pTexture->getTextureTarget(), GL_TEXTURE_COMPARE_MODE_ARB,  
    435436            GL_COMPARE_R_TO_TEXTURE_ARB );             
    436437    } 
    437438 
    438     osg::ref_ptr< osg::Texture2D > _pTexture; 
     439    osg::ref_ptr< osg::Texture > _pTexture; 
    439440}; 
     441 
     442void DebugShadowMap::ViewData::dump( const char * filename ) 
     443{ 
     444    osg::ref_ptr< osg::Group > root = new osg::Group;     
     445    osgUtil::CullVisitor * cv = _cv.get(); 
     446 
     447#if 1 
     448    osg::Group * cam = cv->getRenderStage()->getCamera(); 
     449 
     450    for( unsigned int i = 0; i < cam->getNumChildren(); i++ ) 
     451    { 
     452        root->addChild( cam->getChild( i ) ); 
     453    } 
     454#endif 
     455 
     456    root->addChild( _st->getShadowedScene() ); 
     457 
     458    osg::ref_ptr< osg::MatrixTransform > transform = new osg::MatrixTransform; 
     459    root->addChild( transform.get() ); 
     460 
     461//    updateDebugGeometry( _viewCamera.get(), _camera.get() ); 
     462 
     463    for( PolytopeGeometryMap::iterator itr = _polytopeGeometryMap.begin(); 
     464         itr != _polytopeGeometryMap.end(); 
     465         ++itr ) 
     466    { 
     467        PolytopeGeometry & pg = itr->second; 
     468        int i = 0; 
     469        { 
     470 
     471            ConvexPolyhedron cp( pg._polytope );         
     472 
     473            pg._geometry[i] = cp.buildGeometry 
     474                ( pg._colorOutline, pg._colorInside, pg._geometry[i].get() ); 
     475        } 
     476    } 
     477 
     478    for( unsigned int i = 0; i < _transform[0]->getNumChildren(); i++ ) 
     479    { 
     480        root->addChild( _transform[0]->getChild( i ) ); 
     481    } 
     482 
     483    osgDB::writeNodeFile( *root, std::string( filename ) ); 
     484 
     485    root->removeChildren( 0, root->getNumChildren() ); 
     486} 
    440487 
    441488void DebugShadowMap::ViewData::createDebugHUD( ) 
     
    483530     
    484531        osg::StateSet* stateset = _cameraDebugHUD->getOrCreateStateSet(); 
    485         stateset->setTextureAttributeAndModes(0,_texture.get(),osg::StateAttribute::ON ); 
     532        stateset->setTextureAttribute(0,_texture.get(),osg::StateAttribute::ON ); 
    486533        stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); 
    487534//        stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);