Changeset 7957 for OpenSceneGraph/trunk/examples/osgshadow/osgshadow.cpp
- Timestamp:
- 03/14/08 17:51:39 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgshadow/osgshadow.cpp
r7545 r7957 53 53 const int ReceivesShadowTraversalMask = 0x1; 54 54 const int CastsShadowTraversalMask = 0x2; 55 55 56 56 namespace ModelOne 57 57 { … … 64 64 RIGHT_FACE = 8, 65 65 TOP_FACE = 16, 66 BOTTOM_FACE = 32 66 BOTTOM_FACE = 32 67 67 }; 68 68 … … 101 101 if (mask & FRONT_FACE) 102 102 { 103 // front face 103 // front face 104 104 vertices->push_back(origin); 105 105 vertices->push_back(origin+dx); … … 114 114 if (mask & BACK_FACE) 115 115 { 116 // back face 116 // back face 117 117 vertices->push_back(origin+dy); 118 118 vertices->push_back(origin+dy+dz); … … 127 127 if (mask & LEFT_FACE) 128 128 { 129 // left face 129 // left face 130 130 vertices->push_back(origin+dy); 131 131 vertices->push_back(origin); … … 140 140 if (mask & RIGHT_FACE) 141 141 { 142 // right face 142 // right face 143 143 vertices->push_back(origin+dx+dy); 144 144 vertices->push_back(origin+dx+dy+dz); … … 153 153 if (mask & TOP_FACE) 154 154 { 155 // top face 155 // top face 156 156 vertices->push_back(origin+dz); 157 157 vertices->push_back(origin+dz+dx); … … 166 166 if (mask & BOTTOM_FACE) 167 167 { 168 // bottom face 168 // bottom face 169 169 vertices->push_back(origin); 170 170 vertices->push_back(origin+dy); … … 207 207 sw->setSingleChildOn(_childNum); 208 208 return true; 209 } 209 } 210 210 break; 211 211 } … … 235 235 sw->addChild(ModelOne::createCube(ModelOne::FRONT_FACE | ModelOne::BACK_FACE | ModelOne::LEFT_FACE | ModelOne::RIGHT_FACE | ModelOne::TOP_FACE), false); 236 236 sw->addChild(ModelOne::createCube(ModelOne::FRONT_FACE | ModelOne::BACK_FACE | ModelOne::LEFT_FACE | ModelOne::RIGHT_FACE | ModelOne::TOP_FACE | ModelOne::BOTTOM_FACE), false); 237 238 return sw; 237 238 return sw; 239 239 } 240 240 } … … 244 244 osg::AnimationPath* createAnimationPath(const osg::Vec3& center,float radius,double looptime) 245 245 { 246 // set up the animation path 246 // set up the animation path 247 247 osg::AnimationPath* animationPath = new osg::AnimationPath; 248 248 animationPath->setLoopMode(osg::AnimationPath::LOOP); … … 266 266 267 267 } 268 return animationPath; 268 return animationPath; 269 269 } 270 270 … … 374 374 osg::Node* shadowed = createBase(center-osg::Vec3(0.0f,0.0f,radius*0.25),radius); 375 375 shadowed->setNodeMask(ReceivesShadowTraversalMask); 376 376 377 377 osg::Group* group = new osg::Group; 378 378 379 379 group->addChild(shadowed); 380 380 group->addChild(shadower); 381 381 382 382 return group; 383 383 } … … 458 458 return scene; 459 459 } 460 460 461 461 } 462 462 … … 476 476 return ModelThree::createModel(arguments); 477 477 } 478 478 479 479 } 480 480 … … 503 503 arguments.getApplicationUsage()->addCommandLineOption("--maxFarDist", "ParallelSplitShadowMap max far distance to shadow.");//ADEGLI 504 504 arguments.getApplicationUsage()->addCommandLineOption("--moveVCamFactor", "ParallelSplitShadowMap move the virtual frustum behind the real camera, (also back ground object can cast shadow).");//ADEGLI 505 arguments.getApplicationUsage()->addCommandLineOption("--NVid ea", "ParallelSplitShadowMap set default PolygonOffset for NVidea.");//ADEGLI505 arguments.getApplicationUsage()->addCommandLineOption("--NVidia", "ParallelSplitShadowMap set default PolygonOffset for NVidia.");//ADEGLI 506 506 arguments.getApplicationUsage()->addCommandLineOption("--PolyOffset-Factor", "ParallelSplitShadowMap set PolygonOffset factor.");//ADEGLI 507 507 arguments.getApplicationUsage()->addCommandLineOption("--PolyOffset-Unit", "ParallelSplitShadowMap set PolygonOffset unit.");//ADEGLI 508 508 arguments.getApplicationUsage()->addCommandLineOption("--CullFaceFront", "ParallelSplitShadowMap add a cull face: front.");//ADEGLI 509 509 510 510 511 511 arguments.getApplicationUsage()->addCommandLineOption("-1", "Use test model one."); 512 512 arguments.getApplicationUsage()->addCommandLineOption("-2", "Use test model two."); … … 528 528 // default to single threaded during dev work. 529 529 viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); 530 530 531 531 while (arguments.read("--SingleThreaded")) viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); 532 532 while (arguments.read("--CullDrawThreadPerContext")) viewer.setThreadingModel(osgViewer::Viewer::CullDrawThreadPerContext); … … 560 560 { 561 561 osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); 562 if (apm || !apm->valid()) 562 if (apm || !apm->valid()) 563 563 { 564 564 unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); … … 583 583 584 584 osg::ref_ptr<osgShadow::ShadowedScene> shadowedScene = new osgShadow::ShadowedScene; 585 585 586 586 shadowedScene->setReceivesShadowTraversalMask(ReceivesShadowTraversalMask); 587 587 shadowedScene->setCastsShadowTraversalMask(CastsShadowTraversalMask); 588 589 588 589 590 590 if (arguments.read("--sv")) 591 591 { … … 612 612 613 613 int mapres = 1024; 614 while (arguments.read("--mapres", mapres)) 614 while (arguments.read("--mapres", mapres)) 615 615 pssm->setTextureResolution(mapres); 616 616 617 617 while (arguments.read("--debug-color")) { pssm->setDebugColorOn(); } 618 618 619 619 620 620 int minNearSplit=0; … … 638 638 std::cout << "ParallelSplitShadowMap : setMoveVCamBehindRCamFactor(" << moveVCamFactor<<")" << std::endl; 639 639 } 640 640 641 641 642 642 double polyoffsetfactor = -0.02; … … 646 646 pssm->setPolygonOffset(osg::Vec2(polyoffsetfactor,polyoffsetunit)); //ATI Radeon 647 647 648 if (arguments.read("--NVid ea")){648 if (arguments.read("--NVidia")){ 649 649 //pssm->setPolygonOffset(osg::Vec2(-0.02,1.0)); //ATI Radeon 650 pssm->setPolygonOffset(osg::Vec2(10.0f,20.0f)); //NVid ea650 pssm->setPolygonOffset(osg::Vec2(10.0f,20.0f)); //NVidia 651 651 } 652 652 … … 668 668 669 669 int mapres = 1024; 670 while (arguments.read("--mapres", mapres)) 670 while (arguments.read("--mapres", mapres)) 671 671 sm->setTextureSize(osg::Vec2s(mapres,mapres)); 672 672 } 673 673 674 674 osg::ref_ptr<osg::Node> model = osgDB::readNodeFiles(arguments); 675 675 if (model.valid()) … … 682 682 } 683 683 684 // get the bounds of the model. 684 // get the bounds of the model. 685 685 osg::ComputeBoundsVisitor cbbv; 686 686 model->accept(cbbv); … … 688 688 689 689 osg::Vec4 lightpos; 690 690 691 691 if (postionalLight) 692 692 { … … 703 703 704 704 osg::Geode* geode = new osg::Geode; 705 705 706 706 osg::Vec3 widthVec(bb.radius(), 0.0f, 0.0f); 707 707 osg::Vec3 depthVec(0.0f, bb.radius(), 0.0f); 708 708 osg::Vec3 centerBase( (bb.xMin()+bb.xMax())*0.5f, (bb.yMin()+bb.yMax())*0.5f, bb.zMin()-bb.radius()*0.1f ); 709 710 geode->addDrawable( osg::createTexturedQuadGeometry( centerBase-widthVec*1.5f-depthVec*1.5f, 709 710 geode->addDrawable( osg::createTexturedQuadGeometry( centerBase-widthVec*1.5f-depthVec*1.5f, 711 711 widthVec*3.0f, depthVec*3.0f) ); 712 712 713 713 geode->setNodeMask(shadowedScene->getReceivesShadowTraversalMask()); 714 714 715 715 geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, new osg::Texture2D(osgDB::readImageFile("Images/lz.rgb"))); 716 716 … … 720 720 osg::ref_ptr<osg::LightSource> ls = new osg::LightSource; 721 721 ls->getLight()->setPosition(lightpos); 722 722 723 723 bool spotlight = false; 724 724 if (arguments.read("--spotLight")) … … 749 749 shadowedScene->addChild(model.get()); 750 750 shadowedScene->addChild(ls.get()); 751 751 752 752 viewer.setSceneData(shadowedScene.get()); 753 753 … … 760 760 osgViewer::Viewer::Windows windows; 761 761 viewer.getWindows(windows); 762 762 763 763 if (windows.empty()) return 1; 764 764 765 765 osgShadow::ShadowMap* sm = dynamic_cast<osgShadow::ShadowMap*>(shadowedScene->getShadowTechnique()); 766 766 osg::ref_ptr<osg::Camera> hudCamera = sm->makeDebugHUD(); 767 767 768 768 // set up cameras to rendering on the first window available. 769 769 hudCamera->setGraphicsContext(windows[0]); … … 790 790 } 791 791 ls->getLight()->setPosition(lightpos); 792 792 793 793 osg::Vec3f lightDir(-lightpos.x(),-lightpos.y(),-lightpos.z()); 794 794 if(spotlight) 795 lightDir = osg::Vec3(bb.center().x()+sinf(t)*bb.radius()/2.0, bb.center().y() + cosf(t)*bb.radius()/2.0, bb.center().z()) 795 lightDir = osg::Vec3(bb.center().x()+sinf(t)*bb.radius()/2.0, bb.center().y() + cosf(t)*bb.radius()/2.0, bb.center().z()) 796 796 - osg::Vec3(lightpos.x(), lightpos.y(), lightpos.z()) ; 797 797 lightDir.normalize(); … … 801 801 viewer.frame(); 802 802 } 803 803 804 804 return 0; 805 805 }
