Changeset 8920 for OpenSceneGraph/trunk/examples/osgshadow/osgshadow.cpp
- Timestamp:
- 09/23/08 11:59:23 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgshadow/osgshadow.cpp
r8379 r8920 42 42 #include <osgShadow/SoftShadowMap> 43 43 #include <osgShadow/ParallelSplitShadowMap> 44 #include <osgShadow/LightSpacePerspectiveShadowMap> 44 45 45 46 #include <osgDB/ReadFile> … … 48 49 #include <iostream> 49 50 51 50 52 // for the grid data.. 51 #include "../osghangglide/terrain_coords.h" 52 53 const int ReceivesShadowTraversalMask = 0x1; 54 const int CastsShadowTraversalMask = 0x2; 53 #include "terrain_coords.h" 54 // for the model number four - island scene 55 #include "IslandScene.h" 56 57 58 static int ReceivesShadowTraversalMask = 0x1; 59 static int CastsShadowTraversalMask = 0x2; 55 60 56 61 namespace ModelOne … … 472 477 return ModelTwo::createModel(arguments); 473 478 } 479 else if (arguments.read("-4")) 480 { 481 return ModelFour::createModel(arguments); 482 } 474 483 else /*if (arguments.read("-3"))*/ 475 484 { … … 491 500 arguments.getApplicationUsage()->addCommandLineOption("--directionalLight", "Use a direction light."); 492 501 arguments.getApplicationUsage()->addCommandLineOption("--noUpdate", "Disable the updating the of light source."); 502 503 arguments.getApplicationUsage()->addCommandLineOption("--castsShadowMask", "Override default castsShadowMask (default - 0x2)"); 504 arguments.getApplicationUsage()->addCommandLineOption("--receivesShadowMask", "Override default receivesShadowMask (default - 0x1)"); 505 493 506 arguments.getApplicationUsage()->addCommandLineOption("--base", "Add a base geometry to test shadows."); 494 507 arguments.getApplicationUsage()->addCommandLineOption("--sv", "Select ShadowVolume implementation."); 495 508 arguments.getApplicationUsage()->addCommandLineOption("--ssm", "Select SoftShadowMap implementation."); 496 509 arguments.getApplicationUsage()->addCommandLineOption("--sm", "Select ShadowMap implementation."); 497 // arguments.getApplicationUsage()->addCommandLineOption("--pssm", "Select ParallelSplitShadowMap implementation."); 510 498 511 arguments.getApplicationUsage()->addCommandLineOption("--pssm", "Select ParallelSplitShadowMap implementation.");//ADEGLI 499 512 arguments.getApplicationUsage()->addCommandLineOption("--mapcount", "ParallelSplitShadowMap texture count.");//ADEGLI … … 506 519 arguments.getApplicationUsage()->addCommandLineOption("--PolyOffset-Unit", "ParallelSplitShadowMap set PolygonOffset unit.");//ADEGLI 507 520 521 arguments.getApplicationUsage()->addCommandLineOption("--lispsm", "Select LightSpacePerspectiveShadowMap implementation."); 522 arguments.getApplicationUsage()->addCommandLineOption("--ViewBounds", "LiSPSM optimize shadow for view frustum (weakest option)"); 523 arguments.getApplicationUsage()->addCommandLineOption("--CullBounds", "LiSPSM optimize shadow for bounds of culled objects in view frustum (better option)."); 524 arguments.getApplicationUsage()->addCommandLineOption("--DrawBounds", "LiSPSM optimize shadow for bounds of predrawn pixels in view frustum (best & default)."); 525 arguments.getApplicationUsage()->addCommandLineOption("--mapres", "LiSPSM texture resolution."); 526 arguments.getApplicationUsage()->addCommandLineOption("--maxFarDist", "LiSPSM max far distance to shadow."); 527 arguments.getApplicationUsage()->addCommandLineOption("--moveVCamFactor", "LiSPSM move the virtual frustum behind the real camera, (also back ground object can cast shadow)."); 528 arguments.getApplicationUsage()->addCommandLineOption("--minLightMargin", "LiSPSM the same as --moveVCamFactor."); 508 529 509 530 arguments.getApplicationUsage()->addCommandLineOption("-1", "Use test model one."); 510 531 arguments.getApplicationUsage()->addCommandLineOption("-2", "Use test model two."); 511 arguments.getApplicationUsage()->addCommandLineOption("-3", "Use test model three."); 532 arguments.getApplicationUsage()->addCommandLineOption("-3", "Use test model three (default)."); 533 arguments.getApplicationUsage()->addCommandLineOption("-4", "Use test model four - island scene."); 512 534 arguments.getApplicationUsage()->addCommandLineOption("--two-sided", "Use two-sided stencil extension for shadow volumes."); 513 535 arguments.getApplicationUsage()->addCommandLineOption("--two-pass", "Use two-pass stencil for shadow volumes."); … … 526 548 while (arguments.read("--positionalLight")) postionalLight = true; 527 549 while (arguments.read("--directionalLight")) postionalLight = false; 550 551 while (arguments.read("--castsShadowMask", CastsShadowTraversalMask )); 552 while (arguments.read("--receivesShadowMask", ReceivesShadowTraversalMask )); 528 553 529 554 bool updateLightPosition = true; … … 639 664 shadowedScene->setShadowTechnique(sm.get()); 640 665 } 666 else if ( arguments.read("--lispsm") ) 667 { 668 osg::ref_ptr<osgShadow::MinimalShadowMap> sm = NULL; 669 670 if( arguments.read( "--ViewBounds" ) ) 671 sm = new osgShadow::LightSpacePerspectiveShadowMapVB; 672 else if( arguments.read( "--CullBounds" ) ) 673 sm = new osgShadow::LightSpacePerspectiveShadowMapCB; 674 else // if( arguments.read( "--DrawBounds" ) ) // default 675 sm = new osgShadow::LightSpacePerspectiveShadowMapDB; 676 677 shadowedScene->setShadowTechnique( sm.get() ); 678 679 if( sm.valid() ) 680 { 681 while( arguments.read("--debugHUD") ) 682 sm->setDebugDraw( true ); 683 684 float minLightMargin = 10.f; 685 float maxFarPlane = 0; 686 unsigned int texSize = 1024; 687 unsigned int baseTexUnit = 0; 688 unsigned int shadowTexUnit = 1; 689 690 while ( arguments.read("--moveVCamFactor", minLightMargin ) ); 691 while ( arguments.read("--minLightMargin", minLightMargin ) ); 692 while ( arguments.read("--maxFarDist", maxFarPlane ) ); 693 while ( arguments.read("--mapres", texSize )); 694 while ( arguments.read("--baseTextureUnit", baseTexUnit) ); 695 while ( arguments.read("--shadowTextureUnit", shadowTexUnit) ); 696 697 sm->setMinLightMargin( minLightMargin ); 698 sm->setMaxFarPlane( maxFarPlane ); 699 sm->setTextureSize( osg::Vec2s( texSize, texSize ) ); 700 sm->setShadowTextureCoordIndex( shadowTexUnit ); 701 sm->setShadowTextureUnit( shadowTexUnit ); 702 sm->setBaseTextureCoordIndex( baseTexUnit ); 703 sm->setBaseTextureUnit( baseTexUnit ); 704 } 705 } 641 706 else /* if (arguments.read("--sm")) */ 642 707 { … … 647 712 while (arguments.read("--mapres", mapres)) 648 713 sm->setTextureSize(osg::Vec2s(mapres,mapres)); 649 }714 } 650 715 651 716 osg::ref_ptr<osg::Node> model = osgDB::readNodeFiles(arguments); … … 710 775 711 776 //set the LightSource, only for checking, there is only 1 light in the scene 712 dynamic_cast<osgShadow::ShadowMap*>(shadowedScene->getShadowTechnique())->setLight(ls.get()); 777 osgShadow::ShadowMap* shadowMap = dynamic_cast<osgShadow::ShadowMap*>(shadowedScene->getShadowTechnique()); 778 if( shadowMap ) shadowMap->setLight(ls.get()); 713 779 } 714 780 … … 741 807 742 808 osgShadow::ShadowMap* sm = dynamic_cast<osgShadow::ShadowMap*>(shadowedScene->getShadowTechnique()); 743 osg::ref_ptr<osg::Camera> hudCamera = sm->makeDebugHUD(); 744 745 // set up cameras to rendering on the first window available. 746 hudCamera->setGraphicsContext(windows[0]); 747 hudCamera->setViewport(0,0,windows[0]->getTraits()->width, windows[0]->getTraits()->height); 748 749 viewer.addSlave(hudCamera.get(), false); 809 if( sm ) { 810 osg::ref_ptr<osg::Camera> hudCamera = sm->makeDebugHUD(); 811 812 // set up cameras to rendering on the first window available. 813 hudCamera->setGraphicsContext(windows[0]); 814 hudCamera->setViewport(0,0,windows[0]->getTraits()->width, windows[0]->getTraits()->height); 815 816 viewer.addSlave(hudCamera.get(), false); 817 } 750 818 } 751 819 … … 755 823 while (!viewer.done()) 756 824 { 825 { 826 osgShadow::MinimalShadowMap * msm = dynamic_cast<osgShadow::MinimalShadowMap*>( shadowedScene->getShadowTechnique() ); 827 828 if( msm ) { 829 830 // If scene decorated by CoordinateSystemNode try to find localToWorld 831 // and set modellingSpaceToWorld matrix to optimize scene bounds computation 832 833 osg::NodePath np = viewer.getCoordinateSystemNodePath(); 834 if( !np.empty() ) { 835 osg::CoordinateSystemNode * csn = 836 dynamic_cast<osg::CoordinateSystemNode *>( np.back() ); 837 838 if( csn ) { 839 osg::Vec3d pos = 840 viewer.getCameraManipulator()->getMatrix().getTrans(); 841 842 msm->setModellingSpaceToWorldTransform 843 ( csn->computeLocalCoordinateFrame( pos ) ); 844 } 845 } 846 } 847 } 848 757 849 if (updateLightPosition) 758 850 { 759 851 float t = viewer.getFrameStamp()->getSimulationTime(); 852 760 853 if (postionalLight) 761 854 {
