Ignore:
Timestamp:
07/06/05 17:52:44 (19 years ago)
Author:
mattausch
Message:

added flags for switching on/off transparents for item buffer and vertex programs for depth pass / item buffer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp

    r158 r159  
    3131mEnableDepthWrite(true), 
    3232mSkipTransparents(false), 
    33 mSavedShadowTechnique(SHADOWTYPE_NONE) 
     33mSavedShadowTechnique(SHADOWTYPE_NONE), 
     34mRenderTransparentsForItemBuffer(false), 
     35mExecuteVertexProgramForAllPasses(false) 
    3436{ 
    3537        mHierarchyInterface = new OctreeHierarchyInterface(this, mDestRenderSystem); 
     
    3739        //mDisplayNodes = true; 
    3840        //mShowBoundingBoxes = true; 
     41        //mShowBoxes = true; 
     42        //mShowBoxes = true; 
    3943 
    4044        // TODO: set maxdepth to reasonable value 
     
    4852        if (depthMat.isNull()) 
    4953    { 
    50                 // Init 
    5154                depthMat = MaterialManager::getSingleton().create( 
    5255                "Visibility/DepthPass", 
    5356                ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); 
     57 
    5458        mDepthPass = depthMat->getTechnique(0)->getPass(0); 
    5559                mDepthPass->setColourWriteEnabled(false); 
     
    6064        { 
    6165                mDepthPass = depthMat->getTechnique(0)->getPass(0); 
     66        } 
     67} 
     68//----------------------------------------------------------------------- 
     69VisibilityTerrainSceneManager::~VisibilityTerrainSceneManager() 
     70{ 
     71        if (mHierarchyInterface) 
     72        { 
     73                delete mHierarchyInterface; 
     74                mHierarchyInterface = NULL; 
    6275        } 
    6376} 
     
    8598        } 
    8699        //mItemBufferPass->setAmbient(1, 1, 0); 
    87 } 
    88 //----------------------------------------------------------------------- 
    89 VisibilityTerrainSceneManager::~VisibilityTerrainSceneManager() 
    90 { 
    91         if (mHierarchyInterface) 
    92         { 
    93                 delete mHierarchyInterface; 
    94                 mHierarchyInterface = NULL; 
    95         } 
    96100} 
    97101//----------------------------------------------------------------------- 
     
    160164        } 
    161165         
    162         if (mRenderDepthPass) 
    163         { 
    164                 // --- set vertex program of current pass so z-buffer is updated correctly 
    165         if (pass->hasVertexProgram()) 
    166                 { 
    167                         mDepthPass->setVertexProgram(pass->getVertexProgramName()); 
    168  
    169                         if (mDepthPass->hasVertexProgram()) 
    170                         { 
    171                                 const GpuProgramPtr& prg = mDepthPass->getVertexProgram(); 
    172                                 // Load this program if not done already 
    173                                 if (!prg->isLoaded()) 
    174                                         prg->load(); 
    175                                 // Copy params 
    176                                 mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters()); 
    177                         } 
    178                 } 
    179                 else if (mDepthPass->hasVertexProgram()) 
    180                 { 
    181                         mDepthPass->setVertexProgram(""); 
    182                 } 
    183         } 
     166        // --- set vertex program of current pass in order to set correct depth 
     167        if (mExecuteVertexProgramForAllPasses && mRenderDepthPass && pass->hasVertexProgram()) 
     168        { 
     169                // add vertex program of current pass to depth pass 
     170                mDepthPass->setVertexProgram(pass->getVertexProgramName()); 
     171 
     172                if (mDepthPass->hasVertexProgram()) 
     173                { 
     174                        const GpuProgramPtr& prg = mDepthPass->getVertexProgram(); 
     175                        // Load this program if not done already 
     176                        if (!prg->isLoaded()) 
     177                                prg->load(); 
     178                        // Copy params 
     179                        mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters()); 
     180                } 
     181        } 
     182        else if (mDepthPass->hasVertexProgram()) 
     183        { 
     184                mDepthPass->setVertexProgram(""); 
     185        } 
     186         
    184187 
    185188        bool IsDepthWrite = usedPass->getDepthWriteEnabled(); 
     
    228231                // mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters); 
    229232        } 
    230         //TerrainSceneManager::_findVisibleObjects(cam, onlyShadowCasters); 
     233         
    231234         
    232235        // -- delete lists stored for visualization 
     
    240243        ColourValue savedAmbient = mAmbientLight; 
    241244 
    242         // --- apply standard rendering for some cases (e.g., visualization, shadow pass) 
     245        //-- apply standard rendering for some modes (e.g., visualization, shadow pass) 
    243246 
    244247        if (mShowVisualization || 
     
    257260                mIlluminationStage = savedStage; 
    258261        } 
    259         else // -- the hierarchical culling algorithm 
     262        else //-- the hierarchical culling algorithm 
    260263        { 
    261264                // don't render backgrounds for item buffer 
     
    266269                } 
    267270 
     271                //-- hierarchical culling 
    268272                // the objects of different layers (e.g., background, scene,  
    269273                // overlay) must be identified and rendered one after another 
     
    279283 
    280284#ifdef GTP_VISIBILITY_MODIFIED_OGRE 
    281                 // delete previously rendered contenbt 
     285                // delete previously rendered content 
    282286                _deleteRenderedQueueGroups(); 
    283287#endif 
     
    296300                /**  
    297301                * the hierarchical culling algorithm 
    298                 * if we use a depth pass: will just find objects and update depth buffer 
    299                 * for "delayed" rendering: will render some passes afterwards, e.g., transparents 
     302                * for depth pass: we just find objects and update depth buffer 
     303                * for "delayed" rendering: we render some passes afterwards 
     304                * e.g., transparents, because they need front-to-back sorting 
    300305                **/ 
    301306                 
     
    325330                 
    326331                //-- now we can render all remaining queue objects 
    327                 // for depth pass, transparents, overlay  
     332                // used for depth pass, transparents, overlay  
    328333                clearSpecialCaseRenderQueues(); 
    329334                TerrainSceneManager::_renderVisibleObjects(); 
    330335        } 
    331336                 
    332         // set the new render level index afterwards => new level in the next frame  
    333         int levelIdx = TerrainRenderable::getCurrentRenderLevelIndex() + 1; 
    334         TerrainRenderable::setCurrentRenderLevelIndex(levelIdx); 
    335  
     337        // set the new render level index  
     338        TerrainRenderable::NextRenderLevelIndex(); 
     339         
    336340        // reset ambient light 
    337341        setAmbientLight(savedAmbient); 
    338342 
    339         getRenderQueue()->clear(); 
     343        getRenderQueue()->clear(); // finally clear render queue 
    340344        //WriteLog(); // write out stats 
    341345} 
     
    397401                return true; 
    398402        } 
    399         // notifiy that frame has ended so terrain render level can be reset for correct 
    400         // terrain rendering 
    401         if (key == "TerrainLevelIdx") 
    402         { 
    403                 TerrainRenderable::setCurrentRenderLevelIndex((*static_cast<const int *>(val))); 
    404                 return true; 
    405         } 
     403 
    406404        if (key == "DepthWrite") 
    407405        { 
     
    414412                return true; 
    415413        } 
    416          
     414        if (key == "ExecuteVertexProgramForAllPasses") 
     415        {  
     416                mExecuteVertexProgramForAllPasses  = (*static_cast<const bool *>(val)); 
     417                return true; 
     418        } 
     419        if (key == "RenderTransparentsForItemBuffer") 
     420        {  
     421                mRenderTransparentsForItemBuffer  = (*static_cast<const bool *>(val)); 
     422                return true; 
     423        } 
     424 
    417425        return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface). 
    418426                setOption(key, val) || TerrainSceneManager::setOption(key, val); 
     
    547555        } 
    548556 
    549         // ----- TRANSPARENT LOOP: must be handled differently  
    550         // TODO: HOW TO HANDLE OCCLUDED OBJECTS ???? 
    551         RenderPriorityGroup::TransparentRenderablePassList 
    552                 transpObjs = pGroup->_getTransparentPasses(); 
    553         RenderPriorityGroup::TransparentRenderablePassList::const_iterator itrans, itransend; 
    554  
    555         itransend = transpObjs.end(); 
    556         for (itrans = transpObjs.begin(); itrans != itransend; ++itrans) 
    557         { 
    558                 // like for solids, render only first pass 
    559                 if (itrans->pass->getIndex() == 0) 
    560                 {        
    561                         RenderSingleObjectForItemBuffer(itrans->renderable, itrans->pass); 
    562                 } 
    563         }  
     557        // -- TRANSPARENT LOOP: must be handled differently  
     558 
     559        // transparents are treated either as solids or completely discarded 
     560        if (mRenderTransparentsForItemBuffer) 
     561        { 
     562                RenderPriorityGroup::TransparentRenderablePassList transpObjs =  
     563                        pGroup->_getTransparentPasses(); 
     564                RenderPriorityGroup::TransparentRenderablePassList::const_iterator  
     565                        itrans, itransend; 
     566 
     567                itransend = transpObjs.end(); 
     568                for (itrans = transpObjs.begin(); itrans != itransend; ++itrans) 
     569                { 
     570                        // like for solids, render only first pass 
     571                        if (itrans->pass->getIndex() == 0) 
     572                        {        
     573                                RenderSingleObjectForItemBuffer(itrans->renderable, itrans->pass); 
     574                        } 
     575                } 
     576        } 
    564577} 
    565578//----------------------------------------------------------------------- 
     
    583596 
    584597        // set vertex program of current pass 
    585         if (pass->hasVertexProgram()) 
     598        if (mExecuteVertexProgramForAllPasses && pass->hasVertexProgram()) 
    586599        { 
    587600                mItemBufferPass->setVertexProgram(pass->getVertexProgramName()); 
     
    614627} 
    615628//----------------------------------------------------------------------- 
    616 Entity* VisibilityTerrainSceneManager::createEntity(const String& entityName,  
    617                                                                                                         const String& meshName) 
    618 { 
    619         Entity *ent = SceneManager::createEntity(entityName, meshName); 
    620  
    621         for (int i = 0; i < (int)ent->getNumSubEntities(); ++i) 
    622         { 
    623                 ent->getSubEntity(i)->setId(mCurrentEntityId); 
    624         } 
    625  
    626         // increase counter of entity id values 
    627         ++ mCurrentEntityId; 
    628  
    629         return ent; 
    630 } 
    631 //----------------------------------------------------------------------- 
    632629void VisibilityTerrainSceneManager::InitVisibilityCulling(Camera *cam) 
    633630{ 
     
    644641        if ((mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE) || 
    645642            (mShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE)) 
    646         { 
    647          
     643        {        
    648644                mShadowTechnique = SHADOWTYPE_NONE; 
    649645        } 
     
    660656 
    661657 
    662         // set passes which should be stored in render queue  
     658        // set passes which are stored in render queue  
    663659        // for rendering AFTER hierarchical culling, i.e., passes which need  
    664660        // a special rendering order 
     
    715711} 
    716712//----------------------------------------------------------------------- 
     713void VisibilityTerrainSceneManager::endFrame() 
     714{ 
     715        TerrainRenderable::ResetRenderLevelIndex(); 
     716} 
     717//----------------------------------------------------------------------- 
    717718/*void VisibilityTerrainSceneManager::renderBasicQueueGroupObjects(RenderQueueGroup* pGroup) 
    718719{ 
     
    742743} 
    743744*/ 
     745//----------------------------------------------------------------------- 
     746/* 
     747Entity* VisibilityTerrainSceneManager::createEntity(const String& entityName,  
     748                                                                                                        const String& meshName) 
     749{ 
     750        Entity *ent = SceneManager::createEntity(entityName, meshName); 
     751 
     752        for (int i = 0; i < (int)ent->getNumSubEntities(); ++i) 
     753        { 
     754                ent->getSubEntity(i)->setId(mCurrentEntityId); 
     755        } 
     756 
     757        // increase counter of entity id values 
     758        ++ mCurrentEntityId; 
     759 
     760        return ent; 
     761} 
     762*/ 
    744763} // namespace Ogre 
Note: See TracChangeset for help on using the changeset viewer.