[osg-users] osgShadowMap Problems

tuandoviet at gmail.com tuandoviet at gmail.com
Tue Mar 17 13:38:36 PDT 2009


 

I'm trying to use osgShadow, I read examples on osg website and try to run
this code

But the shadow appears strangely like this picture:

http://i475.photobucket.com/albums/rr113/tek3D/shadow.jpg

Here is the code I tested:

int main()

{

           osgViewer::Viewer viewer;

 

           osg::ref_ptr<osg::Group> root = new osg::Group;

           // create light source.

           osg::LightSource* lightsource = new osg::LightSource;

           osg::Light* light = new osg::Light;

           lightsource->setLight(light);

           light->setDirection(osg::Vec3(0,10,0));

           light->setPosition(osg::Vec4(0,0,90,1.0f));

           light->setAmbient(osg::Vec4(0.00f,0.00f,0.08f,1.0f));

           light->setDiffuse(osg::Vec4(1.0f,1.0f,1.0f,1.0f));

           root->addChild(lightsource);

 

           //shadow

           const int ReceivesShadowTraversalMask = 0x1;

 

           const int CastsShadowTraversalMask = 0x2;

 

    osg::ref_ptr<osgShadow::ShadowedScene> shadowedScene = new
osgShadow::ShadowedScene;

 

 
shadowedScene->setReceivesShadowTraversalMask(ReceivesShadowTraversalMask);

    shadowedScene->setCastsShadowTraversalMask(CastsShadowTraversalMask);

 

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

    shadowedScene->setShadowTechnique(sm.get());

 

    int mapres = 1024;

    sm->setTextureSize(osg::Vec2s(mapres,mapres));

           sm->setLight(light);

 

    osg::Node* cessna1 = osgDB::readNodeFile("car68/car68.3DS");

    cessna1->setNodeMask(CastsShadowTraversalMask);

 

    osg::Node* cessna2 = osgDB::readNodeFile("lai.flt");

    cessna2->setNodeMask(ReceivesShadowTraversalMask);

 

    osg::MatrixTransform* positioned = new osg::MatrixTransform;

           osg::Matrix mat = osg::Matrix::rotate(2.7, osg::Vec3(0,0,1));

 
positioned->setMatrix(mat*positioned->getMatrix()*osg::Matrix::translate(10,
40,2));

    positioned->addChild(cessna1);

           

           shadowedScene->addChild(positioned);

           shadowedScene->addChild(cessna2);    

 

           root->addChild(shadowedScene);

 

           viewer.setSceneData(root);

           return viewer.run();

}

 

Could anyone help me with this problem? Thanks in advance!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20090318/1f8b29ff/attachment-0002.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/jpeg
Size: 2950 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20090318/1f8b29ff/attachment-0002.jpeg>


More information about the osg-users mailing list