| 319 | | ShadowCallback() {} |
| | 319 | |
| | 320 | osg::Vec4 _lightpos; |
| | 321 | osg::ref_ptr<osg::StateSet> _ss1; |
| | 322 | |
| | 323 | ShadowCallback() |
| | 324 | { |
| | 325 | osg::Vec4 ambient(0.2,0.2,0.2,1.0); |
| | 326 | osg::Vec4 diffuse(0.8,0.8,0.8,1.0); |
| | 327 | osg::Vec4 zero_colour(0.0,0.0,0.0,1.0); |
| | 328 | |
| | 329 | // first group, render the depth buffer + ambient light contribution |
| | 330 | { |
| | 331 | _ss1 = new osg::StateSet; |
| | 332 | |
| | 333 | osg::LightModel* lm1 = new osg::LightModel; |
| | 334 | lm1->setAmbientIntensity(ambient); |
| | 335 | _ss1->setAttribute(lm1); |
| | 336 | |
| | 337 | osg::Light* light1 = new osg::Light; |
| | 338 | light1->setAmbient(ambient); |
| | 339 | light1->setDiffuse(zero_colour); |
| | 340 | light1->setPosition(_lightpos); |
| | 341 | _ss1->setAttributeAndModes(light1, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); |
| | 342 | _ss1->setMode(GL_LIGHTING, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); |
| | 343 | } |
| | 344 | } |
| 351 | | cv->setCurrentRenderBin(original_bin); |
| | 379 | |
| | 380 | osgUtil::RenderBin::RenderBinList::iterator itr = new_bin->getRenderBinList().find(1000); |
| | 381 | osg::ref_ptr<osgUtil::RenderBin> shadowVolumeBin; |
| | 382 | if (itr != new_bin->getRenderBinList().end()) |
| | 383 | { |
| | 384 | shadowVolumeBin = itr->second; |
| | 385 | |
| | 386 | if (shadowVolumeBin.valid()) |
| | 387 | { |
| | 388 | osg::notify(osg::NOTICE)<<"Found shadow volume bin, now removing it"<<std::endl; |
| | 389 | new_bin->getRenderBinList().erase(itr); |
| | 390 | } |
| | 391 | } |
| | 392 | |
| | 393 | for(osgUtil::RenderBin::RenderBinList::iterator itr = new_bin->getRenderBinList().begin(); |
| | 394 | itr != new_bin->getRenderBinList().end(); |
| | 395 | ++itr) |
| | 396 | { |
| | 397 | osg::notify(osg::NOTICE)<<"bin num = "<<itr->first<<std::endl; |
| | 398 | } |
| | 399 | |
| | 400 | osg::notify(osg::NOTICE)<<"after new_bin->getStateGraphList().size()= "<<new_bin->getStateGraphList().size()<<std::endl; |
| | 401 | osg::notify(osg::NOTICE)<<"after new_bin->getRenderBinList().size()= "<<new_bin->getRenderBinList().size()<<std::endl; |
| | 402 | osg::notify(osg::NOTICE)<<"after new_bin->getRenderLeafList().size()= "<<new_bin->getRenderLeafList().size()<<std::endl; |
| | 403 | |
| | 404 | |
| | 405 | original_bin->setStateSet(_ss1.get()); |
| | 406 | |
| | 407 | osgUtil::RenderStage* orig_rs = cv->getRenderStage(); |
| | 408 | osgUtil::RenderStage* new_rs = new osgUtil::RenderStage; |
| | 409 | orig_rs->addPostRenderStage(new_rs); |
| | 410 | |
| | 411 | new_rs->setViewport(orig_rs->getViewport()); |
| | 412 | new_rs->setClearColor(orig_rs->getClearColor()); |
| | 413 | new_rs->setClearMask(GL_STENCIL_BUFFER_BIT); |
| | 414 | |
| | 415 | if (shadowVolumeBin.valid()) |
| | 416 | { |
| | 417 | new_rs->getRenderBinList()[0] = shadowVolumeBin; |
| | 418 | new_rs->getRenderBinList()[1] = new_bin; |
| | 419 | } |
| | 420 | |