Hi all,

I'm currently working on an example that uses
osgShadow::ViewDependentShadowMap for generating dynamic shadows on a large
area of buildings. It can work correctly on a huge city which is created by
CityEngine and then converted to OSG styled scene graph. It also generates
aliasing issues as expected, but I'm still looking for some good solutions
to reduce such problem and want to discuss them in this thread if possible.
My test program and a simple shader file can be found in attachement.

I've already read a similar topic at:
http://lists.openscenegraph.org/htdig.cgi/osg-users-openscenegraph.org/2011-August/053731.html
And I believe it is necessary to apply some filters on the shadow map (the
test shader file simply uses PCF here) and increase the texture resolution
as well. But for huge scene, a 4096-sized RTT texture will be a heavy
burden. So I wonder if there are some more methods to choose, for example,
is it possible to change the internal format of the texture to
GL_DEPTH_COMPONENT32 to improve the shadow comparision process?

Meanwhile, is it necessary to perform a screen space blurring to reduce the
aliasing effect? It is a serious problem for my scene now as I can't use a
very high resolution. Could anyone suggest some other possible methods on
the post-processing level? To be honest, the ViewDependentShadowMap is the
best shadow solution for me at present as it is easy to be integrated with
custom shaders and embedded into a deferred shading framework.

The test city models are about 180MB. If any of you think it important for
digging into the problem. I'd like to share them freely, too, as I believe
these automatically generated models should not have any copyrights with
them. :-)

Cheers,

Wang Rui
#include <osg/AnimationPath>
#include <osg/PolygonMode>
#include <osg/Texture2D>
#include <osg/Geometry>
#include <osg/Geode>
#include <osg/MatrixTransform>
#include <osgDB/ReadFile>
#include <osgShadow/ShadowedScene>
#include <osgShadow/SoftShadowMap>
#include <osgShadow/LightSpacePerspectiveShadowMap>
#include <osgShadow/ParallelSplitShadowMap>
#include <osgShadow/ViewDependentShadowMap>
#include <osgGA/TrackballManipulator>
#include <osgViewer/ViewerEventHandlers>
#include <osgViewer/Viewer>

int main( int argc, char** argv )
{
	unsigned int rcvShadowMask = 0x1;
	unsigned int castShadowMask = 0x2;

	osg::ref_ptr<osg::Program> program = new osg::Program;
	program->addShader( osgDB::readShaderFile("shadowRenderer.frag") );

	osg::ref_ptr<osg::MatrixTransform> city = new osg::MatrixTransform;
	city->addChild( osgDB::readNodeFile("city_root.osgb") );
	city->setNodeMask( rcvShadowMask|castShadowMask );
	city->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
	city->getOrCreateStateSet()->setAttribute( program.get() );

	osg::ref_ptr<osg::LightSource> light = new osg::LightSource;
	light->getLight()->setPosition( osg::Vec4(1.0, 1.0, 1.0, 0.0) );

	osg::ref_ptr<osgShadow::ViewDependentShadowMap> sm = new osgShadow::ViewDependentShadowMap;

	osg::ref_ptr<osgShadow::ShadowSettings> settings = new osgShadow::ShadowSettings;
	settings->setShaderHint( osgShadow::ShadowSettings::NO_SHADERS );
	settings->setTextureSize( osg::Vec2s(2048, 2048) );
	settings->setMinimumShadowMapNearFarRatio( 0.05 );

	osg::ref_ptr<osgShadow::ShadowedScene> shadowRoot = new osgShadow::ShadowedScene;
	shadowRoot->setShadowTechnique( sm.get() );
	shadowRoot->setShadowSettings( settings.get() );
	shadowRoot->setReceivesShadowTraversalMask( rcvShadowMask );
	shadowRoot->setCastsShadowTraversalMask( castShadowMask );
	shadowRoot->addChild( city.get() );
	shadowRoot->addChild( light.get() );

	osg::ref_ptr<osgDB::Options> options = new osgDB::Options("dds_flip");
	options->setObjectCacheHint( osgDB::Options::CACHE_IMAGES );
	osgDB::Registry::instance()->setOptions( options.get() );
	osgDB::Registry::instance()->getOrCreateSharedStateManager();
	
	osgViewer::Viewer viewer;
	viewer.setSceneData( shadowRoot.get() );
	viewer.addEventHandler( new osgViewer::StatsHandler );
	return viewer.run();
}

Attachment: shadowRenderer.frag
Description: Binary data

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to