| 294 | | geode->addDrawable(shadowVolume.get()); |
| 295 | | |
| 296 | | // switch off the writing to the color bit planes. |
| 297 | | osg::ColorMask* colourMask = new osg::ColorMask; |
| 298 | | colourMask->setMask(false,false,false,false); |
| 299 | | |
| 300 | | osg::Stencil* stencil = new osg::Stencil; |
| 301 | | stencil->setFunction(osg::Stencil::ALWAYS,0,~0u); |
| 302 | | stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::INCR); |
| 303 | | |
| 304 | | osg::StateSet* ss_sv1 = geode->getOrCreateStateSet(); |
| 305 | | ss_sv1->setRenderBinDetails(0, "RenderBin"); |
| 306 | | ss_sv1->setAttributeAndModes(stencil,osg::StateAttribute::ON); |
| 307 | | ss_sv1->setAttribute(colourMask); |
| | 318 | shadowVolume->setDrawMode(drawMode); |
| 309 | | ss_sv1->setAttributeAndModes(new osg::CullFace(osg::CullFace::BACK), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); |
| 310 | | |
| 311 | | camera->addChild(geode.get()); |
| | 320 | |
| | 321 | if (drawMode == osgShadow::ShadowVolumeGeometry::STENCIL_TWO_SIDED) |
| | 322 | { |
| | 323 | osg::notify(osg::NOTICE)<<"STENCIL_TWO_SIDED seleteced"<<std::endl; |
| | 324 | |
| | 325 | osg::StencilTwoSided* stencil = new osg::StencilTwoSided; |
| | 326 | stencil->setFunction(osg::StencilTwoSided::BACK, osg::StencilTwoSided::ALWAYS,0,~0u); |
| | 327 | stencil->setOperation(osg::StencilTwoSided::BACK, osg::StencilTwoSided::KEEP, osg::StencilTwoSided::KEEP, osg::StencilTwoSided::DECR_WRAP); |
| | 328 | stencil->setFunction(osg::StencilTwoSided::FRONT, osg::StencilTwoSided::ALWAYS,0,~0u); |
| | 329 | stencil->setOperation(osg::StencilTwoSided::FRONT, osg::StencilTwoSided::KEEP, osg::StencilTwoSided::KEEP, osg::StencilTwoSided::INCR_WRAP); |
| | 330 | |
| | 331 | |
| | 332 | osg::ColorMask* colourMask = new osg::ColorMask(false, false, false, false); |
| | 333 | |
| | 334 | osg::StateSet* ss_sv1 = geode->getOrCreateStateSet(); |
| | 335 | ss_sv1->setRenderBinDetails(0, "RenderBin"); |
| | 336 | ss_sv1->setAttributeAndModes(stencil,osg::StateAttribute::ON); |
| | 337 | ss_sv1->setAttribute(colourMask); |
| | 338 | ss_sv1->setMode(GL_CULL_FACE,osg::StateAttribute::OFF); |
| | 339 | |
| | 340 | geode->addDrawable(shadowVolume.get()); |
| | 341 | |
| | 342 | camera->addChild(geode.get()); |
| | 343 | |
| | 344 | } |
| | 345 | else |
| | 346 | { |
| | 347 | osg::notify(osg::NOTICE)<<"STENCIL_TWO_PASSES seleteced"<<std::endl; |
| | 348 | |
| | 349 | osg::Stencil* stencil = new osg::Stencil; |
| | 350 | stencil->setFunction(osg::Stencil::ALWAYS,0,~0u); |
| | 351 | stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::KEEP); |
| | 352 | |
| | 353 | osg::ColorMask* colourMask = new osg::ColorMask(false, false, false, false); |
| | 354 | |
| | 355 | osg::StateSet* ss_sv1 = geode->getOrCreateStateSet(); |
| | 356 | ss_sv1->setRenderBinDetails(0, "RenderBin"); |
| | 357 | ss_sv1->setAttributeAndModes(stencil,osg::StateAttribute::ON); |
| | 358 | ss_sv1->setAttribute(colourMask); |
| | 359 | ss_sv1->setMode(GL_CULL_FACE,osg::StateAttribute::ON); |
| | 360 | |
| | 361 | geode->addDrawable(shadowVolume.get()); |
| | 362 | |
| | 363 | camera->addChild(geode.get()); |
| | 364 | } |
| | 365 | |
| 313 | | |
| 314 | | if (true) |
| 315 | | { |
| 316 | | osg::ref_ptr<osg::Geode> geode = new osg::Geode; |
| 317 | | occluder->computeShadowVolumeGeometry(lightpos, *shadowVolume); |
| 318 | | geode->addDrawable(shadowVolume.get()); |
| 319 | | |
| 320 | | // switch off the writing to the color bit planes. |
| 321 | | osg::ColorMask* colourMask = new osg::ColorMask; |
| 322 | | colourMask->setMask(false,false,false,false); |
| 323 | | |
| 324 | | osg::Stencil* stencil = new osg::Stencil; |
| 325 | | stencil->setFunction(osg::Stencil::ALWAYS,0,~0u); |
| 326 | | stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::DECR); |
| 327 | | |
| 328 | | osg::StateSet* ss_sv1 = geode->getOrCreateStateSet(); |
| 329 | | ss_sv1->setRenderBinDetails(1, "RenderBin"); |
| 330 | | ss_sv1->setAttributeAndModes(stencil,osg::StateAttribute::ON); |
| 331 | | ss_sv1->setAttribute(colourMask); |
| 332 | | |
| 333 | | ss_sv1->setAttributeAndModes(new osg::CullFace(osg::CullFace::FRONT), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); |
| 334 | | |
| 335 | | camera->addChild(geode.get()); |
| 336 | | } |
| 337 | | |
| | 367 | |
| | 368 | |
| | 369 | // render scene graph adding contribution of light |