Changeset 122 for trunk/VUT/Ogre


Ignore:
Timestamp:
06/10/05 01:46:50 (19 years ago)
Author:
mattausch
Message:
 
Location:
trunk/VUT/Ogre
Files:
5 edited

Legend:

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

    r119 r122  
    7777        bool mDelayRenderTransparents; 
    7878        bool mUseDepthPass; 
    79         bool mIsDepthPass; 
     79        bool mRenderDepthPass; 
    8080 
    8181        Pass *mDepthPass; 
  • trunk/VUT/Ogre/include/OgreVisibilityTerrainSceneManager.h

    r121 r122  
    6767        bool validatePassForRendering(Pass* pass); 
    6868 
     69        void RenderItemBuffer(RenderPriorityGroup* pGroup); 
     70        void RenderSingleObjectForItemBuffer(Renderable *rend); 
     71        void renderQueueGroupObjects(RenderQueueGroup* pGroup); 
     72 
     73        /** Override from SceneManager so that sub entities can be assigned an id for item buffer */ 
     74        Entity* createEntity(const String& entityName, const String& meshName); 
     75 
    6976protected: 
    70         /** Creates material for depth pass, e.g., a pass that only fills the depth buffer */ 
     77         
     78        /** Creates material for depth pass, e.g., a pass that only fills the depth buffer. */ 
    7179        void InitDepthPass(); 
     80        /** Creates material for item buffer. */ 
     81        void InitItemBufferPass(); 
     82        /** Fills render queue so that a visualization can be rendered. */ 
    7283        void ShowVisualization(Camera *cam); 
     84 
    7385        OctreeHierarchyInterface *mHierarchyInterface; 
    7486        GtpVisibility::VisibilityManager *mVisibilityManager; 
     
    8294        bool mDelayRenderTransparents; 
    8395        bool mUseDepthPass; 
    84         bool mIsDepthPass; 
     96        bool mRenderDepthPass; 
     97        bool mRenderItemBuffer; 
    8598 
    8699        Pass *mDepthPass; 
     100        Pass *mItemBufferPass; 
     101 
     102        int mCurrentEntityId; 
    87103}; 
    88104 
  • trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp

    r121 r122  
    173173        //-- the actual query test 
    174174        query->BeginQuery(); 
    175                          
     175         
    176176        // if node is leaf and was visible => will be rendered anyway. 
    177177        // In this case we can also test with the real geometry. 
    178178        // If camera for culling is different from camera for rendering or only solids  
    179179        // will be rendereded => cannot optimize 
    180         if (mUseOptimization && (mCamera == mCullCamera) && wasVisible && IsLeaf(node) )  
     180        if (mUseOptimization && (mCamera == mCullCamera) && wasVisible && IsLeaf(node))  
    181181        { 
    182182                //LogManager::getSingleton().logMessage("render node\n"); 
  • trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp

    r121 r122  
    1616:  
    1717mVisibilityManager(visManager),  
    18 mIsDepthPass(false), 
     18mRenderDepthPass(false), 
    1919mShowVisualization(false), 
    2020mRenderNodesForViz(false), 
     
    6969{ 
    7070        // setting vertex program is not efficient 
    71         Pass *usedPass = ((mIsDepthPass && pass->getDepthWriteEnabled() && !pass->hasVertexProgram()) ? mDepthPass : pass);              
     71        Pass *usedPass = ((mRenderDepthPass && pass->getDepthWriteEnabled() &&  
     72                !pass->hasVertexProgram()) ? mDepthPass : pass);                 
    7273 
    7374        /* 
    7475        // set depth fill pass only if depth write enabled 
    75         Pass *usedPass = (mIsDepthPass && pass->getDepthWriteEnabled() ? mDepthPass : pass); 
    76  
    77     if (mIsDepthPass && pass->hasVertexProgram()) 
     76        Pass *usedPass = (mRenderDepthPass && pass->getDepthWriteEnabled() ? mDepthPass : pass); 
     77 
     78    if (mRenderDepthPass && pass->hasVertexProgram()) 
    7879    { 
    7980                // set vertex program of current pass to depth pass 
     
    127128 
    128129                for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it) 
    129         { 
     130                { 
    130131 
    131132                        if (mRenderNodesForViz) 
     
    169170        // create material for depth pass 
    170171        InitDepthPass(); 
    171  
     172         
    172173        // visualization: apply standard rendering 
    173174        if (mShowVisualization) 
     
    175176                OctreeSceneManager::_renderVisibleObjects(); 
    176177                return; 
    177         }  
    178          
     178        }        
    179179 
    180180        //-- hierarchical culling 
     
    218218 
    219219        // set state for depth pass 
    220     mIsDepthPass = mUseDepthPass; 
     220    mRenderDepthPass = mUseDepthPass; 
    221221         
    222222        /**  
     
    241241                        (*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false); 
    242242                } 
    243                 mIsDepthPass = false; 
     243                mRenderDepthPass = false; 
    244244    } 
    245245        mSkipTransparents = false; 
  • trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp

    r121 r122  
    77#include <OgreLogManager.h> 
    88#include <OgreStringConverter.h> 
    9  
     9#include <OgreEntity.h> 
     10#include <OgreSubEntity.h> 
    1011 
    1112namespace Ogre { 
     
    1516        GtpVisibility::VisibilityManager *visManager):  
    1617mVisibilityManager(visManager),  
    17 mIsDepthPass(false), 
     18mRenderDepthPass(false), 
    1819mShowVisualization(false), 
    1920mRenderNodesForViz(false), 
     
    2223mSkipTransparents(false), 
    2324mDelayRenderTransparents(true), 
    24 mUseDepthPass(false) 
     25mUseDepthPass(false), 
     26mRenderItemBuffer(true), 
     27mCurrentEntityId(0) 
    2528{ 
    2629        mHierarchyInterface = new OctreeHierarchyInterface(this, mDestRenderSystem); 
     
    5457} 
    5558//----------------------------------------------------------------------- 
     59void VisibilityTerrainSceneManager::InitItemBufferPass() 
     60{ 
     61        MaterialPtr itemBufferMat = MaterialManager::getSingleton(). 
     62                getByName("Visibility/ItemBufferPass"); 
     63 
     64        if (itemBufferMat.isNull()) 
     65    { 
     66                // Init 
     67                itemBufferMat = MaterialManager::getSingleton().create("Visibility/ItemBufferPass", 
     68                ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); 
     69 
     70                mItemBufferPass = itemBufferMat->getTechnique(0)->getPass(0); 
     71                mItemBufferPass->setColourWriteEnabled(true); 
     72                mItemBufferPass->setDepthWriteEnabled(true); 
     73                mItemBufferPass->setLightingEnabled(true); 
     74        } 
     75        else 
     76        { 
     77                mItemBufferPass = itemBufferMat->getTechnique(0)->getPass(0); 
     78        } 
     79        mItemBufferPass->setAmbient(0, 0, 0); 
     80} 
     81//----------------------------------------------------------------------- 
    5682VisibilityTerrainSceneManager::~VisibilityTerrainSceneManager() 
    5783{ 
     
    6591void VisibilityTerrainSceneManager::ShowVisualization(Camera *cam) 
    6692{ 
     93        LogManager::getSingleton().logMessage("***********VISUALIZATION************"); 
    6794        // add player camera for visualization purpose 
    6895        try  
     
    101128                        if (mRenderNodesContentForViz)  
    102129                        { 
    103                                 (*it)->_myAddToRenderQueue(cam, getRenderQueue(), false); 
     130                                (*it)->_addToRenderQueue(cam, getRenderQueue(), false); 
    104131                        } 
    105132                } 
     
    109136Pass *VisibilityTerrainSceneManager::setPass(Pass* pass) 
    110137{ 
    111         //Pass *usedPass = ((mIsDepthPass && !pass->hasVertexProgram()) ? mDepthPass : pass); // setting vertex program is not efficient 
     138        //Pass *usedPass = ((mRenderDepthPass && !pass->hasVertexProgram()) ? mDepthPass : pass); // setting vertex program is not efficient 
    112139         
    113140        // set depth fill pass only if depth write enabled 
    114         Pass *usedPass = (mIsDepthPass && !mHierarchyInterface->IsBoundingBoxQuery() ? mDepthPass : pass); 
     141        Pass *usedPass = (mRenderDepthPass && !mHierarchyInterface->IsBoundingBoxQuery() ? mDepthPass : pass); 
    115142                 
    116143        IlluminationRenderStage savedStage = mIlluminationStage;  
     
    118145        // set illumination stage to NONE so no shadow material is used  
    119146        // for depth pass or for occlusion query 
    120         if (mIsDepthPass || mHierarchyInterface->IsBoundingBoxQuery()) 
     147        if (mRenderDepthPass || mHierarchyInterface->IsBoundingBoxQuery()) 
    121148        { 
    122149                mIlluminationStage = IRS_NONE; 
    123150        } 
    124151         
    125         if (mIsDepthPass) 
     152        if (mRenderDepthPass) 
    126153        { 
    127154                // set vertex program of current pass 
     
    157184void VisibilityTerrainSceneManager::_findVisibleObjects(Camera* cam, bool onlyShadowCasters) 
    158185{ 
     186        // needs full ambient lighting for item colors to be exact 
     187        if (mRenderItemBuffer) 
     188        { 
     189                setAmbientLight(ColourValue(1,1,1,1)); 
     190        } 
     191 
     192        LogManager::getSingleton().logMessage("***********FIND OBJECTS************"); 
     193        getRenderQueue()->clear(); 
     194 
    159195        //-- show visible scene nodes and octree bounding boxes from last frame 
    160196        if (mShowVisualization) 
     
    163199        } 
    164200         
     201        //TerrainSceneManager::_findVisibleObjects(cam, onlyShadowCasters); 
     202         
    165203        mVisible.clear(); 
    166204        mBoxes.clear(); 
    167205         
    168         //TerrainSceneManager::_findVisibleObjects(cam, onlyShadowCasters);              
    169  
    170206        // if there is no depth pass => 
    171207        // we interleave identification and rendering of objects  
     
    185221void VisibilityTerrainSceneManager::_renderVisibleObjects() 
    186222{ 
     223    std::stringstream d; 
     224        d << "Terrain render level: " << TerrainRenderable::getCurrentRenderLevelIndex(); 
     225        LogManager::getSingleton().logMessage(d.str()); 
     226 
     227        // increase terrain renderlevel 
     228        int renderLevel = TerrainRenderable::getCurrentRenderLevelIndex() + 1; 
     229 
     230        if (TerrainRenderable::getCurrentRenderLevelIndex() >= 10) 
     231        {   // max. 10 different renderlevels 
     232                renderLevel = 0; 
     233        } 
     234 
    187235        // visualization: apply standard rendering 
    188236        if (mShowVisualization) 
    189237        {        
    190238                TerrainSceneManager::_renderVisibleObjects(); 
     239                TerrainRenderable::setCurrentRenderLevelIndex(renderLevel); 
    191240                return; 
    192241        } 
    193          
    194         // create material for depth pass 
    195         InitDepthPass(); 
     242 
     243        LogManager::getSingleton().logMessage("***********RENDER OBJECTS************"); 
     244 
     245        InitDepthPass();        // create material for depth pass 
     246        InitItemBufferPass(); // create material for item buffer pass 
    196247 
    197248        //-- hierarchical culling 
     
    228279 
    229280        // set state for depth pass 
    230     mIsDepthPass = mUseDepthPass; 
     281    mRenderDepthPass = mUseDepthPass; 
    231282         
    232283        /**  
     
    242293        if (mUseDepthPass) 
    243294        { 
    244                 /*for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it) 
     295                for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it) 
    245296                { 
    246297                        (*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false); 
    247                 }*/ 
    248                 mIsDepthPass = false; 
     298                } 
     299                mRenderDepthPass = false; 
    249300        } 
    250301 
     
    257308        TerrainSceneManager::_renderVisibleObjects(); 
    258309 
    259         getRenderQueue()->clear(); 
     310        TerrainRenderable::setCurrentRenderLevelIndex(renderLevel); 
    260311        //WriteLog(); // write out stats 
    261312} 
     313 
    262314//----------------------------------------------------------------------- 
    263315void VisibilityTerrainSceneManager::_updateSceneGraph(Camera* cam) 
     
    318370                mDelayRenderTransparents = (*static_cast<const bool *>(val)); 
    319371                return true; 
     372        } 
     373        // notifiy that frame has ended so terrain render level can be reset for correct 
     374        // terrain rendering 
     375        if (key == "TerrainLevelIdx") 
     376        { 
     377                TerrainRenderable::setCurrentRenderLevelIndex((*static_cast<const int *>(val))); 
    320378        } 
    321379        return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface). 
     
    387445{ 
    388446        // skip all but first pass if we are doing the depth pass 
    389         if (mIsDepthPass && pass->getIndex() > 0) 
     447        if ((mRenderDepthPass || mRenderItemBuffer) && pass->getIndex() > 0) 
    390448        { 
    391449                return false; 
     
    393451        return SceneManager::validatePassForRendering(pass); 
    394452} 
     453//----------------------------------------------------------------------- 
     454void VisibilityTerrainSceneManager::renderQueueGroupObjects(RenderQueueGroup* pGroup) 
     455{ 
     456        if (!mRenderItemBuffer) 
     457        { 
     458                TerrainSceneManager::renderQueueGroupObjects(pGroup); 
     459                return; 
     460        } 
     461 
     462        //--- item buffer 
     463    // Iterate through priorities 
     464    RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator(); 
     465 
     466        while (groupIt.hasMoreElements()) 
     467    { 
     468                RenderItemBuffer(groupIt.getNext()); 
     469        } 
     470} 
     471//----------------------------------------------------------------------- 
     472void VisibilityTerrainSceneManager::RenderItemBuffer(RenderPriorityGroup* pGroup) 
     473{ 
     474        // Do solids 
     475        RenderPriorityGroup::SolidRenderablePassMap solidObjs = pGroup->_getSolidPasses(); 
     476 
     477        // ----- SOLIDS LOOP ----- 
     478        RenderPriorityGroup::SolidRenderablePassMap::const_iterator ipass, ipassend; 
     479        ipassend = solidObjs.end(); 
     480 
     481        for (ipass = solidObjs.begin(); ipass != ipassend; ++ipass) 
     482        { 
     483                // Fast bypass if this group is now empty 
     484                if (ipass->second->empty())  
     485                        continue; 
     486 
     487                // Render only first pass 
     488                if (ipass->first->getIndex() > 0) 
     489                        continue; 
     490 
     491                RenderPriorityGroup::RenderableList* rendList = ipass->second; 
     492                 
     493                RenderPriorityGroup::RenderableList::const_iterator irend, irendend; 
     494                irendend = rendList->end(); 
     495                         
     496                for (irend = rendList->begin(); irend != irendend; ++irend) 
     497                { 
     498                        RenderSingleObjectForItemBuffer(*irend); 
     499                } 
     500        } 
     501 
     502        // ----- TRANSPARENT LOOP 
     503        RenderPriorityGroup::TransparentRenderablePassList 
     504                transpObjs = pGroup->_getTransparentPasses(); 
     505        RenderPriorityGroup::TransparentRenderablePassList::const_iterator itrans, itransend; 
     506 
     507        itransend = transpObjs.end(); 
     508        for (itrans = transpObjs.begin(); itrans != itransend; ++itrans) 
     509        { 
     510                // Render only first pass 
     511                if (itrans->pass->getIndex() == 0) 
     512                {                        
     513                        RenderSingleObjectForItemBuffer(itrans->renderable); 
     514                } 
     515        }  
     516} 
     517//----------------------------------------------------------------------- 
     518void VisibilityTerrainSceneManager::RenderSingleObjectForItemBuffer(Renderable *rend) 
     519{ 
     520        static LightList nullLightList; 
     521        Real col = (Real)rend->getId() / (Real)mCurrentEntityId; 
     522        mItemBufferPass->setAmbient(col, 0, 0); 
     523 
     524        setPass(mItemBufferPass); 
     525 
     526        std::stringstream d; 
     527        d << "item buffer id: " << rend->getId() << ", col: " << col; 
     528        LogManager::getSingleton().logMessage(d.str()); 
     529        // Render a single object, this will set up auto params if required 
     530        renderSingleObject(rend, mItemBufferPass, true, &nullLightList); 
     531} 
     532//----------------------------------------------------------------------- 
     533Entity* VisibilityTerrainSceneManager::createEntity(const String& entityName, const String& meshName) 
     534{ 
     535        Entity *ent = SceneManager::createEntity(entityName, meshName); 
     536 
     537        for (int i = 0; i < ent->getNumSubEntities(); ++i) 
     538        { 
     539                ent->getSubEntity(i)->setId(mCurrentEntityId ++); 
     540        } 
     541 
     542        return ent; 
     543} 
    395544 
    396545} // namespace Ogre 
Note: See TracChangeset for help on using the changeset viewer.