| | 109 | |
| | 110 | class DumpShadowVolumesHandler : public osgGA::GUIEventHandler |
| | 111 | { |
| | 112 | public: |
| | 113 | DumpShadowVolumesHandler( ) |
| | 114 | { |
| | 115 | set( false ); |
| | 116 | } |
| | 117 | |
| | 118 | bool get() { return _value; } |
| | 119 | void set( bool value ) { _value = value; } |
| | 120 | |
| | 121 | /** Deprecated, Handle events, return true if handled, false otherwise. */ |
| | 122 | virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) |
| | 123 | { |
| | 124 | if (ea.getEventType() == osgGA::GUIEventAdapter::KEYUP) |
| | 125 | { |
| | 126 | if (ea.getKey() == 'D' ) |
| | 127 | { |
| | 128 | set( true ); |
| | 129 | return true; |
| | 130 | } |
| | 131 | } |
| | 132 | |
| | 133 | return false; |
| | 134 | } |
| | 135 | |
| | 136 | bool _value; |
| | 137 | }; |
| 574 | | arguments.getApplicationUsage()->addCommandLineOption("--ViewBounds", "LiSPSM optimize shadow for view frustum (weakest option)"); |
| 575 | | arguments.getApplicationUsage()->addCommandLineOption("--CullBounds", "LiSPSM optimize shadow for bounds of culled objects in view frustum (better option)."); |
| 576 | | arguments.getApplicationUsage()->addCommandLineOption("--DrawBounds", "LiSPSM optimize shadow for bounds of predrawn pixels in view frustum (best & default)."); |
| 577 | | arguments.getApplicationUsage()->addCommandLineOption("--mapres", "LiSPSM texture resolution."); |
| 578 | | arguments.getApplicationUsage()->addCommandLineOption("--maxFarDist", "LiSPSM max far distance to shadow."); |
| 579 | | arguments.getApplicationUsage()->addCommandLineOption("--moveVCamFactor", "LiSPSM move the virtual frustum behind the real camera, (also back ground object can cast shadow)."); |
| 580 | | arguments.getApplicationUsage()->addCommandLineOption("--minLightMargin", "LiSPSM the same as --moveVCamFactor."); |
| | 604 | arguments.getApplicationUsage()->addCommandLineOption("--tsm", "Select TrapezoidalShadowMap implementation."); |
| | 605 | arguments.getApplicationUsage()->addCommandLineOption("--msm", "Select MinimalShadowMap implementation."); |
| | 606 | arguments.getApplicationUsage()->addCommandLineOption("--ViewBounds", "MSM, LiSPSM & TSM optimize shadow for view frustum (weakest option)"); |
| | 607 | arguments.getApplicationUsage()->addCommandLineOption("--CullBounds", "MSM, LiSPSM & TSM optimize shadow for bounds of culled objects in view frustum (better option)."); |
| | 608 | arguments.getApplicationUsage()->addCommandLineOption("--DrawBounds", "MSM, LiSPSM & TSM optimize shadow for bounds of predrawn pixels in view frustum (best & default)."); |
| | 609 | arguments.getApplicationUsage()->addCommandLineOption("--mapres", "MSM, LiSPSM & TSM texture resolution."); |
| | 610 | arguments.getApplicationUsage()->addCommandLineOption("--maxFarDist", "MSM, LiSPSM & TSM max far distance to shadow."); |
| | 611 | arguments.getApplicationUsage()->addCommandLineOption("--moveVCamFactor", "MSM, LiSPSM & TSM move the virtual frustum behind the real camera, (also back ground object can cast shadow)."); |
| | 612 | arguments.getApplicationUsage()->addCommandLineOption("--minLightMargin", "MSM, LiSPSM t& TSM the same as --moveVCamFactor."); |
| 743 | | sm = new osgShadow::LightSpacePerspectiveShadowMapDB; |
| 744 | | |
| 745 | | shadowedScene->setShadowTechnique( sm.get() ); |
| 746 | | |
| 747 | | if( sm.valid() ) |
| 748 | | { |
| 749 | | while( arguments.read("--debugHUD") ) |
| 750 | | sm->setDebugDraw( true ); |
| 751 | | |
| 752 | | float minLightMargin = 10.f; |
| 753 | | float maxFarPlane = 0; |
| 754 | | unsigned int texSize = 1024; |
| 755 | | unsigned int baseTexUnit = 0; |
| 756 | | unsigned int shadowTexUnit = 1; |
| 757 | | |
| 758 | | while ( arguments.read("--moveVCamFactor", minLightMargin ) ); |
| 759 | | while ( arguments.read("--minLightMargin", minLightMargin ) ); |
| 760 | | while ( arguments.read("--maxFarDist", maxFarPlane ) ); |
| 761 | | while ( arguments.read("--mapres", texSize )); |
| 762 | | while ( arguments.read("--baseTextureUnit", baseTexUnit) ); |
| 763 | | while ( arguments.read("--shadowTextureUnit", shadowTexUnit) ); |
| 764 | | |
| 765 | | sm->setMinLightMargin( minLightMargin ); |
| 766 | | sm->setMaxFarPlane( maxFarPlane ); |
| 767 | | sm->setTextureSize( osg::Vec2s( texSize, texSize ) ); |
| 768 | | sm->setShadowTextureCoordIndex( shadowTexUnit ); |
| 769 | | sm->setShadowTextureUnit( shadowTexUnit ); |
| 770 | | sm->setBaseTextureCoordIndex( baseTexUnit ); |
| 771 | | sm->setBaseTextureUnit( baseTexUnit ); |
| 772 | | } |
| | 774 | msm = new osgShadow::LightSpacePerspectiveShadowMapDB; |
| | 775 | } |
| | 776 | else if( arguments.read("--tsm") ) |
| | 777 | { |
| | 778 | if( arguments.read( "--ViewBounds" ) ) |
| | 779 | msm = new osgShadow::TrapezoidalShadowMapVB; |
| | 780 | else if( arguments.read( "--CullBounds" ) ) |
| | 781 | msm = new osgShadow::TrapezoidalShadowMapCB; |
| | 782 | else // if( arguments.read( "--DrawBounds" ) ) |
| | 783 | msm = new osgShadow::TrapezoidalShadowMapDB; |
| | 784 | } |
| | 785 | else if( arguments.read("--msm") ) |
| | 786 | { |
| | 787 | if( arguments.read( "--ViewBounds" ) ) |
| | 788 | msm = new osgShadow::MinimalShadowMap; |
| | 789 | else if( arguments.read( "--CullBounds" ) ) |
| | 790 | msm = new osgShadow::MinimalCullBoundsShadowMap; |
| | 791 | else // if( arguments.read( "--DrawBounds" ) ) // default |
| | 792 | msm = new osgShadow::MinimalDrawBoundsShadowMap; |
| | 802 | } |
| | 803 | |
| | 804 | if( msm )// Set common MSM & TSM & LISPSM arguments |
| | 805 | { |
| | 806 | shadowedScene->setShadowTechnique( msm.get() ); |
| | 807 | while( arguments.read("--debugHUD") ) |
| | 808 | msm->setDebugDraw( true ); |
| | 809 | |
| | 810 | float minLightMargin = 10.f; |
| | 811 | float maxFarPlane = 0; |
| | 812 | unsigned int texSize = 1024; |
| | 813 | unsigned int baseTexUnit = 0; |
| | 814 | unsigned int shadowTexUnit = 1; |
| | 815 | |
| | 816 | while ( arguments.read("--moveVCamFactor", minLightMargin ) ); |
| | 817 | while ( arguments.read("--minLightMargin", minLightMargin ) ); |
| | 818 | while ( arguments.read("--maxFarDist", maxFarPlane ) ); |
| | 819 | while ( arguments.read("--mapres", texSize )); |
| | 820 | while ( arguments.read("--baseTextureUnit", baseTexUnit) ); |
| | 821 | while ( arguments.read("--shadowTextureUnit", shadowTexUnit) ); |
| | 822 | |
| | 823 | msm->setMinLightMargin( minLightMargin ); |
| | 824 | msm->setMaxFarPlane( maxFarPlane ); |
| | 825 | msm->setTextureSize( osg::Vec2s( texSize, texSize ) ); |
| | 826 | msm->setShadowTextureCoordIndex( shadowTexUnit ); |
| | 827 | msm->setShadowTextureUnit( shadowTexUnit ); |
| | 828 | msm->setBaseTextureCoordIndex( baseTexUnit ); |
| | 829 | msm->setBaseTextureUnit( baseTexUnit ); |