Changeset 115 for trunk/VUT/Ogre


Ignore:
Timestamp:
05/30/05 03:20:23 (19 years ago)
Author:
mattausch
Message:

added depth pass algorithm + delayed transparent object rendering (so depth ordering is right)

Location:
trunk/VUT/Ogre
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/Ogre/include/OgrePlatformHierarchyInterface.h

    r112 r115  
    5151                @remark If null, the actual camera is used for both viewing and culling          
    5252        */ 
    53         void InitFrame(GtpVisibility::HierarchyNode *root, Camera *cam, Camera *cullCam = NULL); 
     53        void InitFrame(GtpVisibility::HierarchyNode *root, Camera *cam, Camera *cullCam = NULL, bool leaveTransparentsInQueue = false); 
    5454        /** Checks if the node is visible from the current view frustum. 
    5555                @param node the current node 
     
    8686 
    8787protected: 
     88        /** true if query should test using geomery whenever it is possible, false if  
     89                bounding boxes are always used. 
     90        */ 
     91        bool UseOptimization() const; 
     92 
    8893        /** materials for visualizing frustum and query culled nodes */ 
    89         void CreateCulledNodeMaterials(); 
     94        void CreateNodeVizMaterials(); 
    9095 
    9196        /** A pass that prepares an occlusion query. 
     
    126131 
    127132        bool mOnlyShadowCasters; 
     133        bool mLeaveTransparentsInQueue; 
    128134}; 
    129135 
  • trunk/VUT/Ogre/include/OgreVisibilityOctreeSceneManager.h

    r114 r115  
    5050        GtpVisibility::VisibilityManager *getVisibilityManager( void ); 
    5151 
    52         //writes out stats into the Ogre log file 
     52        /** Writes out stats into the Ogre log file. 
     53        */ 
    5354        void WriteLog(); 
     55         
    5456        /** Render a set of objects, see renderSingleObject for param definitions  
    5557                Override so we can handle delayed rendering of transparent objects 
     
    5860            bool doLightIteration, const LightList* manualLightList = 0); 
    5961protected: 
    60          
     62 
     63        void CreateDepthPass(); 
     64 
    6165        OctreeHierarchyInterface *mHierarchyInterface; 
    6266        GtpVisibility::VisibilityManager *mVisibilityManager; 
    6367         
    64         bool mUseVisibilityCulling; 
    6568        bool mShowVisualization; 
    66         bool mRenderTransparentObjects; 
     69        bool mSkipTransparents; 
    6770        bool mVisualizeCulledNodes; 
    6871 
    6972        bool mRenderNodesForViz; 
    7073        bool mRenderNodesContentForViz; 
     74        bool mDelayRenderTransparents; 
     75        bool mUseDepthPass; 
     76 
     77        Pass *mDepthPass; 
    7178}; 
    7279 
  • trunk/VUT/Ogre/include/OgreVisibilitySceneManager.h

    r112 r115  
    1515        visibility culling. 
    1616*/ 
    17 class VisibilitySceneManager : public SceneManager 
     17class VisibilitySceneManager: public SceneManager 
    1818{ 
    1919public: 
     
    5757        GtpVisibility::VisibilityManager *mVisibilityManager; 
    5858 
    59         bool mUseVisibilityCulling; 
     59        bool mUseDepthPass; 
    6060        bool mShowVisualization; 
    6161 
  • trunk/VUT/Ogre/include/OgreVisibilityTerrainSceneManager.h

    r114 r115  
    5656        virtual void renderObjects(const RenderPriorityGroup::TransparentRenderablePassList& objs,  
    5757            bool doLightIteration, const LightList* manualLightList = 0); 
    58 protected: 
    59          
    60         /** Writes out stats into the Ogre log file 
     58 
     59        /** Writes out stats into the Ogre log file. 
    6160        */ 
    6261        void WriteLog(); 
    6362 
     63        /** Override pass so we can do the z-fail pass */ 
     64        Pass* setPass(Pass* pass); 
     65 
     66protected: 
     67        /** Creates material for depth pass, e.g., a pass that only fills the depth buffer */ 
     68        void CreateDepthPass(); 
     69        void ShowVisualization(Camera *cam); 
    6470        OctreeHierarchyInterface *mHierarchyInterface; 
    6571        GtpVisibility::VisibilityManager *mVisibilityManager; 
    6672 
    67         bool mUseVisibilityCulling; 
    6873        bool mShowVisualization; 
    69         bool mRenderTransparentObjects; 
     74        bool mSkipTransparents; 
    7075        bool mVisualizeCulledNodes; 
    7176 
    7277        bool mRenderNodesForViz; 
    7378        bool mRenderNodesContentForViz; 
     79        bool mDelayRenderTransparents; 
     80        bool mUseDepthPass; 
     81        bool mIsDepthPass; 
     82 
     83        Pass *mDepthPass; 
    7484}; 
    7585 
  • trunk/VUT/Ogre/resources/VisibilityDemo.overlay

    r87 r115  
    1010                top 5 
    1111                width 400 
    12                 height 60 
     12                height 75 
    1313                material Core/StatsBlockCenter 
    1414                border_size 1 1 1 1 
     
    103103                        colour_bottom 0.3 0.5 0.3 
    104104                } 
     105                element TextArea(Example/Visibility/UseDepthPass) 
     106                { 
     107                        metrics_mode pixels 
     108                        left 5 
     109                        top 50 
     110                        width 90 
     111                        height 30 
     112                        font_name TrebuchetMSBold 
     113                        char_height 16 
     114                        caption [X] Depth pass 
     115                        colour_top 0.5 0.7 0.5 
     116                        colour_bottom 0.3 0.5 0.3 
     117                } 
     118                element TextArea(Example/Visibility/UseDepthPassInfo) 
     119                { 
     120                        metrics_mode pixels 
     121                        left 155 
     122                        top 50 
     123                        width 90 
     124                        height 30 
     125                        font_name TrebuchetMSBold 
     126                        char_height 16 
     127                        caption : 
     128                        colour_top 0.5 0.7 0.5 
     129                        colour_bottom 0.3 0.5 0.3 
     130                } 
     131 
    105132        } 
    106133 
  • trunk/VUT/Ogre/scripts/Plugin_VisibilitySceneManager.vcproj

    r107 r115  
    1313                <Configuration 
    1414                        Name="Debug|Win32" 
    15                         OutputDirectory="..\bin\$(ConfigurationName)" 
     15                        OutputDirectory="..\lib\$(ConfigurationName)" 
    1616                        IntermediateDirectory="..\obj\$(ConfigurationName)" 
    1717                        ConfigurationType="2" 
     
    144144                        Name="SceneManager_Plugins" 
    145145                        Filter=""> 
    146                         <File 
    147                                 RelativePath="..\..\GtpVisibility\include\VisibilityManager.h"> 
    148                         </File> 
    149146                        <Filter 
    150147                                Name="Header Files" 
  • trunk/VUT/Ogre/src/OgreOctreeHierarchyInterface.cpp

    r113 r115  
    44#include <OgreLogManager.h> 
    55#include <OgreStringConverter.h> 
    6 #include <windows.h> 
     6 
    77 
    88namespace Ogre { 
     
    107107 
    108108                static_cast<OctreeSceneManager *>(mSceneManager)->_renderOctant(mCamera,  
    109                         octant, mOnlyShadowCasters); 
     109                        octant, mOnlyShadowCasters, mLeaveTransparentsInQueue); 
    110110 
    111111                mNumRenderedNodes ++; 
  • trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp

    r113 r115  
    1010PlatformHierarchyInterface::PlatformHierarchyInterface(SceneManager *sm, RenderSystem *rsys): 
    1111mSceneManager(sm), mRenderSystem(rsys), mSolidBoundingBox(NULL), 
    12 mCamera(NULL), mCullCamera(NULL), mOnlyShadowCasters(false) 
    13 { 
    14 } 
    15 //----------------------------------------------------------------------- 
    16 void PlatformHierarchyInterface::CreateCulledNodeMaterials() 
     12mCamera(NULL), mCullCamera(NULL), mOnlyShadowCasters(false), mLeaveTransparentsInQueue(false) 
     13{ 
     14} 
     15//----------------------------------------------------------------------- 
     16void PlatformHierarchyInterface::CreateNodeVizMaterials() 
    1717{ 
    1818        // material for frustum culled nodes 
     
    2525                mat->createTechnique()->createPass(); 
    2626                 
    27                 mat->getTechnique(0)->getPass(0)->setAmbient(1,0,0); 
     27                mat->getTechnique(0)->getPass(0)->setAmbient(1, 0, 0); 
    2828                mat->getTechnique(0)->getPass(0)->setLightingEnabled(true); 
    2929                //mat->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false); 
    30                  
    3130                mat->load(); 
    3231        } 
     
    4140                mat->createTechnique()->createPass(); 
    4241                 
    43                 mat->getTechnique(0)->getPass(0)->setAmbient(0,0,1); 
     42                mat->getTechnique(0)->getPass(0)->setAmbient(0, 0, 1); 
    4443                mat->getTechnique(0)->getPass(0)->setLightingEnabled(true); 
    4544                mat->load(); 
    4645        } 
     46 
     47        // material for scene nodes 
     48        /*mat = MaterialManager::getSingleton().getByName("SceneNodesMaterial"); 
     49 
     50        if (mat.isNull()) 
     51        { 
     52                mat = MaterialManager::getSingleton().create("SceneNodesMaterial",  
     53                        ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); 
     54                mat->createTechnique()->createPass(); 
     55                 
     56                mat->getTechnique(0)->getPass(0)->setAmbient(1, 1, 0); 
     57                mat->getTechnique(0)->getPass(0)->setLightingEnabled(true); 
     58                mat->load(); 
     59        }*/ 
    4760} 
    4861//----------------------------------------------------------------------- 
     
    7184        mRenderSystem->_setWorldMatrix(Ogre::Matrix4::IDENTITY); 
    7285        mSceneManager->useRenderableViewProjMode(solidBox); 
    73         //mSceneManager->setOcclusionPass(solidBox->getTechnique()->getPass(0)); 
     86         
     87        // set no depth write, no color, no lighting material 
     88        //mSceneManager->setPass(solidBox->getTechnique()->getPass(0)); 
    7489        SetOcclusionPass(); 
    7590 
     
    112127//----------------------------------------------------------------------- 
    113128void PlatformHierarchyInterface::InitFrame(GtpVisibility::HierarchyNode *root,  
    114                                                                                    Camera *cam, Camera *cullCam) 
     129                                                                                   Camera *cam, Camera *cullCam, bool leaveTransparentsInQueue) 
    115130{ 
    116131        GtpVisibility::HierarchyInterface::InitFrame(root); 
    117132        mPreviousNode = NULL; 
    118  
     133        mLeaveTransparentsInQueue = leaveTransparentsInQueue; 
    119134        SetCamera(cam); 
    120135 
     
    128143        } 
    129144 
    130         CreateCulledNodeMaterials(); 
     145        CreateNodeVizMaterials(); 
    131146} 
    132147//----------------------------------------------------------------------- 
     
    151166} 
    152167//----------------------------------------------------------------------- 
     168bool PlatformHierarchyInterface::UseOptimization() const 
     169{ 
     170        /* If camera for culling is different from camera for rendering or only solids 
     171           will be rendereded => cannot optimize 
     172    */ 
     173        return mUseOptimization && (mCamera == mCullCamera); 
     174} 
     175 
     176//----------------------------------------------------------------------- 
    153177GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::IssueOcclusionQuery( 
    154178        GtpVisibility::HierarchyNode *node, const bool wasVisible)  
     
    162186        // if node is leaf and was visible => will be rendered anyway. 
    163187        // In this case we can also test with the real geometry. 
    164         // if camera for culling is different from camera for rendering => cannot optimize 
    165         if (mUseOptimization && wasVisible && IsLeaf(node) && (mCamera == mCullCamera)) 
     188        if (UseOptimization() && wasVisible && IsLeaf(node) )  
    166189        { 
    167190                //LogManager::getSingleton().logMessage("render node\n"); 
  • trunk/VUT/Ogre/src/OgrePlatformOcclusionQuery.cpp

    r96 r115  
    11#include "OgrePlatformOcclusionQuery.h" 
     2#include <OgreLogManager.h> 
    23 
    34namespace Ogre { 
  • trunk/VUT/Ogre/src/OgreSceneNodeHierarchyInterface.cpp

    r112 r115  
    4242                mNumRenderedNodes ++; 
    4343 
    44                 mSceneManager->_renderSceneNode(mCamera, sceneNode); 
     44                mSceneManager->_renderSceneNode(mCamera, sceneNode, mLeaveTransparentsInQueue); 
    4545        } 
    4646#endif 
  • trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp

    r114 r115  
    1414:  
    1515mVisibilityManager(visManager),  
    16 mUseVisibilityCulling(true), 
     16mUseDepthPass(false), 
    1717mShowVisualization(false), 
    1818mRenderNodesForViz(false), 
    1919mVisualizeCulledNodes(false), 
    20 mRenderTransparentObjects(false) 
     20mSkipTransparents(false), 
     21mDelayRenderTransparents(true) 
    2122{ 
    2223        mHierarchyInterface =  
     
    2930        // TODO: find reasonable value for max depth 
    3031        mMaxDepth = 50; 
     32 
     33        CreateDepthPass(); 
     34} 
     35//----------------------------------------------------------------------- 
     36void VisibilityOctreeSceneManager::CreateDepthPass() 
     37{ 
     38        MaterialPtr depthMat = MaterialManager::getSingleton().getByName("Visibility/DepthPass"); 
     39 
     40        if (depthMat.isNull()) 
     41    { 
     42                // Init 
     43                depthMat = MaterialManager::getSingleton().create( 
     44                "Visibility/DepthPass", 
     45                ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); 
     46 
     47                depthMat->createTechnique()->createPass(); 
     48        mDepthPass = depthMat->getTechnique(0)->getPass(0); 
     49                mDepthPass->setColourWriteEnabled(false); 
     50                mDepthPass->setDepthWriteEnabled(true); 
     51                mDepthPass->setLightingEnabled(false); 
     52        } 
     53        else 
     54        { 
     55                mDepthPass = depthMat->getTechnique(0)->getPass(0); 
     56        } 
    3157} 
    3258//----------------------------------------------------------------------- 
     
    3864void VisibilityOctreeSceneManager::_renderVisibleObjects() 
    3965{ 
    40         // two cameras (one for culling, one for rendering) 
    41         mHierarchyInterface->InitFrame(mOctree, mCameraInProgress,  
    42                                                         mCullCamera ? getCamera("CullCamera") : NULL); 
    43  
    44         if (!mShowVisualization) 
     66                if (!mShowVisualization) 
    4567        { 
    4668                // two cameras (one for culling, one for rendering) 
    4769                mHierarchyInterface->InitFrame(mOctree, mCameraInProgress,  
    48                                                                 mCullCamera ? getCamera("CullCamera") : NULL); 
     70                                                                mCullCamera ? getCamera("CullCamera") : NULL, mDelayRenderTransparents); 
    4971 
    5072                // call initframe to reset culling manager stats 
    5173                mVisibilityManager->GetCullingManager()->InitFrame(mVisualizeCulledNodes); 
    5274        } 
     75         
     76        // standard terrain scenemanager rendering without hierarchical culling 
     77        if (!mUseDepthPass || mShowVisualization) 
     78        {        
     79                OctreeSceneManager::_renderVisibleObjects(); 
     80         
     81                return; 
     82        }  
    5383         
    5484        //-- hierarchical culling 
    5585        // the objects of different layers (e.g., background, scene,  
    5686        // overlay) must be identified and rendered one after another 
     87 
     88        mSkipTransparents = false; 
    5789 
    5890        //-- render background 
     
    6597 
    6698#ifdef GTP_VISIBILITY_MODIFIED_OGRE 
    67         _deleteRenderedQueueGroups(); 
     99        _deleteRenderedQueueGroups(false); 
    68100#endif 
    69101 
     
    72104        addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY); 
    73105        setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE); 
    74  
     106         
     107        // render only solids in hierarchical algorithm.  
     108        // Transparents need sorting, thus we render them afterwards 
     109        mSkipTransparents = mDelayRenderTransparents; 
    75110 
    76111        /**  
    77112        * the hierarchical culling algorithm 
    78113        **/ 
     114         
    79115        mVisibilityManager->ApplyVisibilityCulling(); 
    80  
    81  
    82 #ifdef GTP_VISIBILITY_MODIFIED_OGRE 
    83         _deleteRenderedQueueGroups(); 
    84 #endif 
    85  
    86         //-- render overlay 
     116         
     117        //-- now we can savely render all remaining objects, e.g., transparents, overlay 
     118        mSkipTransparents = false; 
     119 
    87120        clearSpecialCaseRenderQueues(); 
    88121        SceneManager::_renderVisibleObjects(); 
     
    99132        // we interleave identification and rendering of objects  
    100133        // in _renderVisibibleObjects 
    101         if (!mUseVisibilityCulling) 
     134        if (!mUseDepthPass) 
    102135        { 
    103136                OctreeSceneManager::_findVisibleObjects(cam, onlyShadowCasters); 
     
    123156                if (mRenderNodesForViz || mRenderNodesContentForViz) 
    124157                { 
    125                         // change node material so it is better suited for visualization 
    126                 /*      MaterialPtr nodeMat = MaterialManager::getSingleton().getByName("Core/NodeMaterial"); 
     158                /*      // change node material so it is better suited for visualization 
     159                        MaterialPtr nodeMat = MaterialManager::getSingleton().getByName("Core/NodeMaterial"); 
    127160                        nodeMat->setAmbient(1, 1, 0); 
    128161                        nodeMat->setLightingEnabled(true); 
     
    164197bool VisibilityOctreeSceneManager::setOption(const String & key, const void * val) 
    165198{ 
    166         if (key == "UseVisibilityCulling") 
    167         { 
    168                 mUseVisibilityCulling = (*static_cast<const bool *>(val)); 
     199        if (key == "UseDepthPass") 
     200        { 
     201                mUseDepthPass = (*static_cast<const bool *>(val)); 
    169202                return true; 
    170203        } 
     
    199232                return true; 
    200233        } 
    201  
     234        if (key == "DelayRenderTransparents") 
     235        { 
     236                mDelayRenderTransparents = (*static_cast<const bool *>(val)); 
     237                return true; 
     238        } 
    202239        return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface). 
    203240                setOption(key, val) || OctreeSceneManager::setOption(key, val); 
     
    240277            bool doLightIteration, const LightList* manualLightList) 
    241278{ 
    242         if (mRenderTransparentObjects) 
     279        if (!mSkipTransparents) 
    243280        { 
    244281                OctreeSceneManager::renderObjects(objs, doLightIteration, manualLightList); 
  • trunk/VUT/Ogre/src/OgreVisibilitySceneManager.cpp

    r112 r115  
    1212//----------------------------------------------------------------------- 
    1313VisibilitySceneManager::VisibilitySceneManager(GtpVisibility::VisibilityManager *visManager) 
    14 :mVisibilityManager(visManager), mUseVisibilityCulling(true), mShowVisualization(false) 
     14:mVisibilityManager(visManager), mUseDepthPass(false), mShowVisualization(false) 
    1515{ 
    1616        mHierarchyInterface =  
     
    2929        // we interleave identification and rendering of objects  
    3030        // in _renderVisibibleObjects 
    31         if (!mUseVisibilityCulling) 
     31        if (!mUseDepthPass) 
    3232        { 
    3333                SceneManager::_findVisibleObjects(cam, onlyShadowCasters); 
     
    4848 
    4949        // standard terrain scenemanager rendering without hierarchical culling 
    50         if (!mUseVisibilityCulling || mShowVisualization) 
     50        if (!mUseDepthPass || mShowVisualization) 
    5151        {        
    5252                SceneManager::_renderVisibleObjects(); 
     
    6868 
    6969#ifdef GTP_VISIBILITY_MODIFIED_OGRE 
    70         _deleteRenderedQueueGroups(); 
     70        _deleteRenderedQueueGroups(false); 
    7171#endif 
    7272 
     
    8484 
    8585#ifdef GTP_VISIBILITY_MODIFIED_OGRE 
    86         _deleteRenderedQueueGroups(); 
     86        //_deleteRenderedQueueGroups(); 
    8787#endif 
    8888 
     
    136136} 
    137137//----------------------------------------------------------------------- 
    138 GtpVisibility::VisibilityManager *VisibilitySceneManager::getVisibilityManager( void ) 
     138GtpVisibility::VisibilityManager *VisibilitySceneManager::getVisibilityManager() 
    139139{ 
    140140        return mVisibilityManager; 
  • trunk/VUT/Ogre/src/OgreVisibilitySceneManagerDll.cpp

    r104 r115  
    2727#include <OgreVisibilityOctreeSceneManager.h> 
    2828//#include <OgreVisibilityDotSceneManager.h> 
     29 
    2930#include <OgreHeightmapTerrainPageSource.h> 
    3031#include <OgreRoot.h> 
    31  
     32#include <OgreLogManager.h> 
    3233#include "VisibilityManager.h" 
    33 #include "StopAndWaitCullingManager.h" 
    3434#include "VisibilityEnvironment.h" 
    3535 
     
    3939namespace Ogre { 
    4040 
    41 // VisibilityDotSceneManager *cullingDotPlugin; 
    42 VisibilityOctreeSceneManager *cullingOctreePlugin; 
    43 VisibilityTerrainSceneManager *cullingTerrainPlugin; 
     41VisibilityOctreeSceneManager *visibilityOctreePlugin; 
     42VisibilityTerrainSceneManager *visibilityTerrainPlugin; 
     43//VisibilityDotSceneManager *visibilityDotPlugin; 
    4444 
    4545HeightmapTerrainPageSource *heightmapTerrainPageSource; 
     
    4848extern "C" void dllStartPlugin(void) 
    4949{ 
     50        //visEnv = new GtpVisibility::VisibilityEnvironment(); 
    5051        visManager = new GtpVisibility::VisibilityManager(visEnv); 
     52 
    5153        // Create new scene manager 
     54        visibilityOctreePlugin = new VisibilityOctreeSceneManager(visManager); 
     55        visibilityTerrainPlugin = new VisibilityTerrainSceneManager(visManager); 
    5256        //occlusionDotPlugin = new VisibilityDotSceneManager(); 
    53         cullingOctreePlugin = new VisibilityOctreeSceneManager(visManager); 
    54         cullingTerrainPlugin = new VisibilityTerrainSceneManager(visManager); 
     57 
    5558        heightmapTerrainPageSource = new HeightmapTerrainPageSource(); 
     59        visibilityTerrainPlugin->registerPageSource("Heightmap", heightmapTerrainPageSource); 
    5660 
    57         cullingTerrainPlugin->registerPageSource("Heightmap", heightmapTerrainPageSource); 
     61         
     62        // Register 
     63        Root::getSingleton().setSceneManager(ST_GENERIC, visibilityOctreePlugin); 
     64        Root::getSingleton().setSceneManager(ST_EXTERIOR_CLOSE, visibilityTerrainPlugin); 
     65        //Root::getSingleton().setSceneManager(ST_GENERIC, occlusionDotPlugin); 
    5866 
    59         // Register 
    60         //Root::getSingleton().setSceneManager( ST_GENERIC, occlusionDotPlugin ); 
    61         Root::getSingleton().setSceneManager( ST_GENERIC, cullingOctreePlugin ); 
    62         Root::getSingleton().setSceneManager( ST_EXTERIOR_CLOSE, cullingTerrainPlugin ); 
     67        LogManager::getSingleton().logMessage("registered akira plugins"); 
    6368} 
     69//----------------------------------------------------------------------- 
    6470extern "C" void dllStopPlugin(void) 
    6571{ 
    6672        delete heightmapTerrainPageSource; 
    67     //delete occlusionDotPlugin; 
    68         delete cullingOctreePlugin; 
    69         delete cullingTerrainPlugin; 
     73   
     74        delete visibilityOctreePlugin; 
     75        delete visibilityTerrainPlugin; 
     76        //delete occlusionDotPlugin; 
     77 
    7078        delete visManager; 
     79        //delete visEnv; 
    7180} 
    7281 
  • trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp

    r114 r115  
    99#include <OgreStringConverter.h> 
    1010 
    11 #include <windows.h> 
    1211 
    1312namespace Ogre { 
     
    1514//----------------------------------------------------------------------- 
    1615VisibilityTerrainSceneManager::VisibilityTerrainSceneManager( 
    17         GtpVisibility::VisibilityManager *visManager) 
    18 : mVisibilityManager(visManager),  
    19 mUseVisibilityCulling(true), 
     16        GtpVisibility::VisibilityManager *visManager):  
     17mVisibilityManager(visManager),  
     18mUseDepthPass(false), 
     19mIsDepthPass(false), 
    2020mShowVisualization(false), 
    2121mRenderNodesForViz(false), 
    2222mRenderNodesContentForViz(false), 
    2323mVisualizeCulledNodes(false), 
    24 mRenderTransparentObjects(false) 
     24mSkipTransparents(false), 
     25mDelayRenderTransparents(true) 
    2526{ 
    2627        mHierarchyInterface =  
     
    3233        // TODO: set maxdepth to reasonable value 
    3334        mMaxDepth = 50; 
     35        // create material for depth pass 
     36        CreateDepthPass(); 
     37} 
     38//----------------------------------------------------------------------- 
     39void VisibilityTerrainSceneManager::CreateDepthPass() 
     40{ 
     41        MaterialPtr depthMat = MaterialManager::getSingleton().getByName("Visibility/DepthPass"); 
     42 
     43        if (depthMat.isNull()) 
     44    { 
     45                // Init 
     46                depthMat = MaterialManager::getSingleton().create( 
     47                "Visibility/DepthPass", 
     48                ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); 
     49        mDepthPass = depthMat->getTechnique(0)->getPass(0); 
     50                mDepthPass->setColourWriteEnabled(false); 
     51                mDepthPass->setDepthWriteEnabled(true); 
     52                mDepthPass->setLightingEnabled(false); 
     53        } 
     54        else 
     55        { 
     56                mDepthPass = depthMat->getTechnique(0)->getPass(0); 
     57        } 
    3458} 
    3559//----------------------------------------------------------------------- 
     
    3963} 
    4064//----------------------------------------------------------------------- 
     65Pass *VisibilityTerrainSceneManager::setPass(Pass* pass) 
     66{ 
     67        // setting vertex program is not efficient 
     68        //Pass *usedPass = ((mIsDepthPass && !pass->hasVertexProgram()) ? mDepthPass : pass);            
     69        Pass *usedPass = (mIsDepthPass ? mDepthPass : pass);     
     70 
     71        if (mIsDepthPass) 
     72        { 
     73                // set vertex program of current pass 
     74        if (pass->hasVertexProgram()) 
     75                { 
     76                        mDepthPass->setVertexProgram(pass->getVertexProgramName()); 
     77 
     78                        if (mDepthPass->hasVertexProgram()) 
     79                        { 
     80                                const GpuProgramPtr& prg = mDepthPass->getVertexProgram(); 
     81                                // Load this program if not done already 
     82                                if (!prg->isLoaded()) 
     83                                        prg->load(); 
     84                                // Copy params 
     85                                mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters()); 
     86                        } 
     87                } 
     88                else if (mDepthPass->hasVertexProgram()) 
     89                { 
     90                        mDepthPass->setVertexProgram(""); 
     91                } 
     92        } 
     93 
     94        TerrainSceneManager::setPass(usedPass); 
     95 
     96        return usedPass; 
     97} 
     98//----------------------------------------------------------------------- 
     99void VisibilityTerrainSceneManager::ShowVisualization(Camera *cam) 
     100{ 
     101        // add player camera for visualization purpose 
     102        try { 
     103                Camera *c; 
     104                if ((c = getCamera("PlayerCam")) != NULL) 
     105                { 
     106                        getRenderQueue()->addRenderable(c); 
     107                }    
     108    } 
     109    catch(...) 
     110    { 
     111        // ignore 
     112    } 
     113         
     114        if (mRenderNodesForViz || mRenderNodesContentForViz) 
     115        { 
     116                for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it) 
     117                { 
     118                        if (mRenderNodesForViz) 
     119                        { 
     120                                //getRenderQueue()->addRenderable(*it); 
     121                                // addbounding boxes instead of node itself 
     122                                (*it)->_addBoundingBoxToQueue(getRenderQueue()); 
     123                        } 
     124                        if (mRenderNodesContentForViz)  
     125                        { 
     126                                (*it)->_addToRenderQueue(cam, getRenderQueue(), false); 
     127                        } 
     128                } 
     129        } 
     130        for (BoxList::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it) 
     131        { 
     132                getRenderQueue()->addRenderable(*it); 
     133        } 
     134} 
     135//----------------------------------------------------------------------- 
    41136void VisibilityTerrainSceneManager::_findVisibleObjects(Camera* cam, bool onlyShadowCasters) 
    42137{ 
    43         // only shadow casters will be rendered in shadow texture pass 
    44         mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters); 
    45  
    46         // does nothing if hierarchical culling is used => 
    47         // we interleave identification and rendering of objects  
    48         // in _renderVisibibleObjects 
    49         if (!mUseVisibilityCulling) 
    50         { 
    51                 OctreeSceneManager::_findVisibleObjects(cam, onlyShadowCasters); 
    52                 return;  
    53         } 
    54  
    55         //-- show visibile scene nodes and octree bounding boxes from last frame 
     138        //-- show visible scene nodes and octree bounding boxes from last frame 
    56139        if (mShowVisualization) 
    57140    { 
    58                 // add player camera for visualization purpose 
    59                 try { 
    60                         Camera *c; 
    61                         if ((c = getCamera("PlayerCam")) != NULL) 
    62                         { 
    63                                 getRenderQueue()->addRenderable(c); 
    64                         }    
    65         } 
    66         catch(...) 
    67         { 
    68             // ignore 
    69         } 
     141                ShowVisualization(cam); 
     142        } 
     143        else  
     144        { 
     145                mVisible.clear(); 
     146            mBoxes.clear(); 
    70147                 
    71                 if (mRenderNodesForViz || mRenderNodesContentForViz) 
    72                 { 
    73                         // change node material so it is better suited for visualization 
    74                         /*MaterialPtr nodeMat = MaterialManager::getSingleton().getByName("Core/NodeMaterial"); 
    75                         nodeMat->setAmbient(1, 1, 0); 
    76                         nodeMat->setLightingEnabled(true); 
    77                         nodeMat->getTechnique(0)->getPass(0)->removeAllTextureUnitStates();*/ 
    78  
    79                         for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it) 
    80                         { 
    81                                 if (mRenderNodesForViz) 
    82                                 { 
    83                                         getRenderQueue()->addRenderable(*it); 
    84                                 } 
    85                                 if (mRenderNodesContentForViz)  
    86                                 { 
    87                                         (*it)->_addToRenderQueue(cam, getRenderQueue(), false); 
    88                                 } 
    89                         } 
    90                 } 
    91                 for (BoxList::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it) 
    92                 { 
    93                         getRenderQueue()->addRenderable(*it); 
    94                 } 
    95         } 
    96          
    97         mVisible.clear(); 
    98     mBoxes.clear(); 
     148                // if there is no depth pass => 
     149                // we interleave identification and rendering of objects  
     150                // in _renderVisibibleObjects 
     151 
     152                // only shadow casters will be rendered in shadow texture pass 
     153                mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters); 
     154        } 
    99155} 
    100156//----------------------------------------------------------------------- 
    101157void VisibilityTerrainSceneManager::_renderVisibleObjects() 
    102158{ 
    103         if (!mShowVisualization) 
    104         { 
    105                 // two cameras (one for culling, one for rendering) 
    106                 mHierarchyInterface->InitFrame(mOctree, mCameraInProgress,  
    107                                                                 mCullCamera ? getCamera("CullCamera") : NULL); 
    108  
    109                 // call initframe to reset culling manager stats 
    110                 mVisibilityManager->GetCullingManager()->InitFrame(mVisualizeCulledNodes); 
    111         } 
    112          
    113         // standard terrain scenemanager rendering without hierarchical culling 
    114         if (!mUseVisibilityCulling || mShowVisualization) 
     159        // visualization: apply standard rendering 
     160        if (mShowVisualization) 
    115161        {        
    116162                TerrainSceneManager::_renderVisibleObjects(); 
    117          
    118163                return; 
    119         }  
    120          
     164        } 
     165 
     166 
    121167        //-- hierarchical culling 
    122168        // the objects of different layers (e.g., background, scene,  
    123169        // overlay) must be identified and rendered one after another 
    124170 
    125         //-- render background 
     171        bool leaveTransparentsInQueue = mDelayRenderTransparents && !mUseDepthPass; 
     172 
     173        // possible two cameras (one for culling, one for rendering) 
     174        mHierarchyInterface->InitFrame(mOctree, mCameraInProgress,  
     175                                                        mCullCamera ? getCamera("CullCamera") : NULL, 
     176                                                        leaveTransparentsInQueue); 
     177 
     178        // call initframe to reset culling manager stats 
     179        mVisibilityManager->GetCullingManager()->InitFrame(mVisualizeCulledNodes); 
     180         
     181        mSkipTransparents = false; 
     182 
     183        //-- render background, in case there is one 
    126184        clearSpecialCaseRenderQueues(); 
    127185        addSpecialCaseRenderQueue(RENDER_QUEUE_BACKGROUND); 
    128186        addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_EARLY); 
    129  
    130187        setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE); 
     188 
    131189        SceneManager::_renderVisibleObjects(); 
    132190 
     191 
    133192#ifdef GTP_VISIBILITY_MODIFIED_OGRE 
    134         _deleteRenderedQueueGroups(); 
     193        _deleteRenderedQueueGroups(false); 
    135194#endif 
    136195 
    137         //-- render visible objects (i.e., all but overlay) 
     196        //-- render visible objects (i.e., all but overlay and skies late) 
    138197        clearSpecialCaseRenderQueues(); 
     198        addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_LATE); 
    139199        addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY); 
    140200        setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE); 
    141201 
    142  
     202        // transparents are skipped from hierarchical rendering 
     203        // => they need sorting, thus we render them afterwards 
     204        mSkipTransparents = mDelayRenderTransparents; 
     205 
     206        // set state for depth pass 
     207    mIsDepthPass = mUseDepthPass; 
     208         
    143209        /**  
    144         * the hierarchical culling algorithm 
     210          * the hierarchical culling algorithm 
     211          * for depth pass: will just find objects and update depth buffer 
     212          * for delayed rendering: will render all but transparents 
    145213        **/ 
     214         
    146215        mVisibilityManager->ApplyVisibilityCulling(); 
    147216 
    148217 
    149 #ifdef GTP_VISIBILITY_MODIFIED_OGRE 
    150         _deleteRenderedQueueGroups(); 
    151 #endif 
    152  
    153         //-- render overlay 
     218        // for depth pass: add visible nodes found with the visibility culling 
     219        if (mUseDepthPass) 
     220        { 
     221                for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it) 
     222                { 
     223                        (*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false); 
     224                } 
     225                mIsDepthPass = false; 
     226        } 
     227        mSkipTransparents = false; 
     228 
     229        //-- now we can render all remaining queue objects 
     230        // for depth pass: all 
     231        // for delayed rendering: transparents, overlay  
    154232        clearSpecialCaseRenderQueues(); 
    155233        SceneManager::_renderVisibleObjects(); 
     
    171249bool VisibilityTerrainSceneManager::setOption(const String & key, const void * val) 
    172250{ 
    173         if (key == "UseVisibilityCulling") 
    174         { 
    175                 mUseVisibilityCulling = (*static_cast<const bool *>(val)); 
     251        if (key == "UseDepthPass") 
     252        { 
     253                mUseDepthPass = (*static_cast<const bool *>(val)); 
    176254                return true; 
    177255        } 
     
    209287        { 
    210288                mVisualizeCulledNodes = (*static_cast<const bool *>(val)); 
     289                return true; 
     290        } 
     291        if (key == "DelayRenderTransparents") 
     292        { 
     293                mDelayRenderTransparents = (*static_cast<const bool *>(val)); 
    211294                return true; 
    212295        } 
     
    266349            bool doLightIteration, const LightList* manualLightList) 
    267350{ 
    268         if (mRenderTransparentObjects) 
     351        if (!mSkipTransparents) 
    269352        { 
    270353                OctreeSceneManager::renderObjects(objs, doLightIteration, manualLightList); 
Note: See TracChangeset for help on using the changeset viewer.