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). "
This commit is contained in:
Robert Osfield
2010-03-01 11:52:44 +00:00
parent 60dd9ad7d0
commit 42a050e87c
5 changed files with 225 additions and 184 deletions

View File

@@ -13,10 +13,11 @@
* ViewDependentShadow codes Copyright (C) 2008 Wojciech Lewandowski
* Thanks to to my company http://www.ai.com.pl for allowing me free this work.
*/
#include <osgShadow/ShadowedScene>
#include <osgShadow/DebugShadowMap>
#include <osgShadow/ConvexPolyhedron>
#include <osgUtil/RenderLeaf>
#include <osgDB/WriteFile>
#include <osg/Geometry>
#include <osg/PrimitiveSet>
#include <osg/MatrixTransform>
@@ -415,7 +416,7 @@ class DebugShadowMap::DrawableDrawWithDepthShadowComparisonOffCallback:
public osg::Drawable::DrawCallback
{
public:
DrawableDrawWithDepthShadowComparisonOffCallback( osg::Texture2D *pTex )
DrawableDrawWithDepthShadowComparisonOffCallback( osg::Texture *pTex )
: _pTexture( pTex )
{
}
@@ -426,18 +427,64 @@ public:
ri.getState()->applyTextureAttribute( 0, _pTexture.get() );
// Turn off depth comparison mode
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE );
glTexParameteri( _pTexture->getTextureTarget(), GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE );
drawable->drawImplementation(ri);
// Turn it back on
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB,
glTexParameteri( _pTexture->getTextureTarget(), GL_TEXTURE_COMPARE_MODE_ARB,
GL_COMPARE_R_TO_TEXTURE_ARB );
}
osg::ref_ptr< osg::Texture2D > _pTexture;
osg::ref_ptr< osg::Texture > _pTexture;
};
void DebugShadowMap::ViewData::dump( const char * filename )
{
osg::ref_ptr< osg::Group > root = new osg::Group;
osgUtil::CullVisitor * cv = _cv.get();
#if 1
osg::Group * cam = cv->getRenderStage()->getCamera();
for( unsigned int i = 0; i < cam->getNumChildren(); i++ )
{
root->addChild( cam->getChild( i ) );
}
#endif
root->addChild( _st->getShadowedScene() );
osg::ref_ptr< osg::MatrixTransform > transform = new osg::MatrixTransform;
root->addChild( transform.get() );
// updateDebugGeometry( _viewCamera.get(), _camera.get() );
for( PolytopeGeometryMap::iterator itr = _polytopeGeometryMap.begin();
itr != _polytopeGeometryMap.end();
++itr )
{
PolytopeGeometry & pg = itr->second;
int i = 0;
{
ConvexPolyhedron cp( pg._polytope );
pg._geometry[i] = cp.buildGeometry
( pg._colorOutline, pg._colorInside, pg._geometry[i].get() );
}
}
for( unsigned int i = 0; i < _transform[0]->getNumChildren(); i++ )
{
root->addChild( _transform[0]->getChild( i ) );
}
osgDB::writeNodeFile( *root, std::string( filename ) );
root->removeChildren( 0, root->getNumChildren() );
}
void DebugShadowMap::ViewData::createDebugHUD( )
{
_cameraDebugHUD = new osg::Camera;
@@ -482,7 +529,7 @@ void DebugShadowMap::ViewData::createDebugHUD( )
osg::Vec3(0,_hudSize[1],0) );
osg::StateSet* stateset = _cameraDebugHUD->getOrCreateStateSet();
stateset->setTextureAttributeAndModes(0,_texture.get(),osg::StateAttribute::ON );
stateset->setTextureAttribute(0,_texture.get(),osg::StateAttribute::ON );
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
// stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
stateset->setAttributeAndModes