Hi Robert, hi all,
I'm writing an example for the latest ViewDependentShadowMap feature
and I've already found it good comparing with the standard shadow map
technique, especially when handling with massive shadow casters. But
in my example attached, the cessna who acts as a caster seems to be
affected by the shadow, too. You may find every cessna node are
blinking while they flying around the terrain and this may bring bad
experience to developers. Is it a known issue to be fixed or I'm doing
something wrong in the example code?
This example will be used in the book OpenSceneGraph Cookbook, which
will be published by Packt Publishing at the beginning of next year.
:-)
Thanks,
Wang Rui
/* -*-c++-*- OpenSceneGraph Cookbook
* Chapter 6 Recipe 2
* Author: Wang Rui <wangray84 at gmail dot com>
*/
#include <osg/MatrixTransform>
#include <osgDB/ReadFile>
#include <osgShadow/ShadowedScene>
#include <osgShadow/ViewDependentShadowMap>
#include <osgGA/TrackballManipulator>
#include <osgViewer/ViewerEventHandlers>
#include <osgViewer/Viewer>
#include "CommonFunctions"
int main( int argc, char** argv )
{
unsigned int rcvShadowMask = 0x1;
unsigned int castShadowMask = 0x2;
// Set the ground (only receives shadow)
osg::ref_ptr<osg::MatrixTransform> groundNode = new osg::MatrixTransform;
groundNode->addChild( osgDB::readNodeFile("lz.osg") );
groundNode->setMatrix( osg::Matrix::translate(200.0f, 200.0f,-200.0f) );
groundNode->setNodeMask( rcvShadowMask );
// Set the cessna (only casts shadow)
osg::ref_ptr<osg::MatrixTransform> cessnaNode = new osg::MatrixTransform;
cessnaNode->addChild( osgDB::readNodeFile("cessna.osg.0,0,90.rot") );
cessnaNode->addUpdateCallback( osgCookBook::createAnimationPathCallback(50.0f, 6.0f) );
cessnaNode->setNodeMask( castShadowMask );
// Set shadow node
osg::ref_ptr<osgShadow::ViewDependentShadowMap> vdsm = new osgShadow::ViewDependentShadowMap;
vdsm->setShadowMapProjectionHint( osgShadow::ViewDependentShadowMap::ORTHOGRAPHIC_SHADOW_MAP );
vdsm->setBaseShadowTextureUnit( 1 );
osg::ref_ptr<osgShadow::ShadowedScene> shadowRoot = new osgShadow::ShadowedScene;
shadowRoot->setShadowTechnique( vdsm.get() );
shadowRoot->setReceivesShadowTraversalMask( rcvShadowMask );
shadowRoot->setCastsShadowTraversalMask( castShadowMask );
shadowRoot->addChild( groundNode.get() );
for ( unsigned int i=0; i<10; ++i )
{
for ( unsigned int j=0; j<10; ++j )
{
osg::ref_ptr<osg::MatrixTransform> cessnaInstance = new osg::MatrixTransform;
cessnaInstance->setMatrix( osg::Matrix::translate((float)i*50.0f, (float)j*50.0f, 0.0f) );
cessnaInstance->addChild( cessnaNode.get() );
shadowRoot->addChild( cessnaInstance.get() );
}
}
const osg::BoundingSphere& bs = groundNode->getBound();
osg::ref_ptr<osgGA::TrackballManipulator> trackball = new osgGA::TrackballManipulator;
trackball->setHomePosition( bs.center()+osg::Vec3(0.0f, 0.0f, bs.radius()*0.4f), bs.center(), osg::Y_AXIS );
osgViewer::Viewer viewer;
viewer.setCameraManipulator( trackball.get() );
viewer.setSceneData( shadowRoot.get() );
viewer.addEventHandler( new osgViewer::StatsHandler );
return viewer.run();
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org