source: trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp @ 160

Revision 160, 24.4 KB checked in by mattausch, 19 years ago (diff)

added animation

RevLine 
[59]1#include "OgreVisibilityTerrainSceneManager.h"
[74]2#include "OgreVisibilityOptionsManager.h"
[59]3#include <OgreMath.h>
4#include <OgreIteratorWrappers.h>
5#include <OgreRenderSystem.h>
6#include <OgreCamera.h>
[93]7#include <OgreLogManager.h>
[100]8#include <OgreStringConverter.h>
[122]9#include <OgreEntity.h>
10#include <OgreSubEntity.h>
[59]11
[156]12
[59]13namespace Ogre {
[87]14
[59]15//-----------------------------------------------------------------------
[153]16VisibilityTerrainSceneManager::VisibilityTerrainSceneManager(GtpVisibility::
17                                                                                                                         VisibilityManager *visManager):
[115]18mVisibilityManager(visManager),
[103]19mShowVisualization(false),
[112]20mRenderNodesForViz(false),
[113]21mRenderNodesContentForViz(false),
[114]22mVisualizeCulledNodes(false),
[139]23mLeavePassesInQueue(0),
[120]24mDelayRenderTransparents(true),
[122]25mUseDepthPass(false),
[153]26mRenderDepthPass(false),
[154]27mUseItemBuffer(false),
28//mUseItemBuffer(true),
[153]29mRenderItemBuffer(false),
[154]30mCurrentEntityId(1),
[139]31mEnableDepthWrite(true),
32mSkipTransparents(false),
[159]33mSavedShadowTechnique(SHADOWTYPE_NONE),
34mRenderTransparentsForItemBuffer(false),
35mExecuteVertexProgramForAllPasses(false)
[59]36{
[120]37        mHierarchyInterface = new OctreeHierarchyInterface(this, mDestRenderSystem);
[139]38       
[120]39        //mDisplayNodes = true;
[85]40        //mShowBoundingBoxes = true;
[159]41        //mShowBoxes = true;
[103]42
43        // TODO: set maxdepth to reasonable value
[96]44        mMaxDepth = 50;
[59]45}
46//-----------------------------------------------------------------------
[119]47void VisibilityTerrainSceneManager::InitDepthPass()
[115]48{
49        MaterialPtr depthMat = MaterialManager::getSingleton().getByName("Visibility/DepthPass");
50
51        if (depthMat.isNull())
52    {
53                depthMat = MaterialManager::getSingleton().create(
54                "Visibility/DepthPass",
55                ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
[159]56
[115]57        mDepthPass = depthMat->getTechnique(0)->getPass(0);
58                mDepthPass->setColourWriteEnabled(false);
59                mDepthPass->setDepthWriteEnabled(true);
60                mDepthPass->setLightingEnabled(false);
61        }
62        else
63        {
64                mDepthPass = depthMat->getTechnique(0)->getPass(0);
65        }
66}
67//-----------------------------------------------------------------------
[159]68VisibilityTerrainSceneManager::~VisibilityTerrainSceneManager()
69{
70        if (mHierarchyInterface)
71        {
72                delete mHierarchyInterface;
73                mHierarchyInterface = NULL;
74        }
75}
76//-----------------------------------------------------------------------
[122]77void VisibilityTerrainSceneManager::InitItemBufferPass()
78{
79        MaterialPtr itemBufferMat = MaterialManager::getSingleton().
80                getByName("Visibility/ItemBufferPass");
81
82        if (itemBufferMat.isNull())
83    {
84                // Init
85                itemBufferMat = MaterialManager::getSingleton().create("Visibility/ItemBufferPass",
86                ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
87
88                mItemBufferPass = itemBufferMat->getTechnique(0)->getPass(0);
89                mItemBufferPass->setColourWriteEnabled(true);
90                mItemBufferPass->setDepthWriteEnabled(true);
91                mItemBufferPass->setLightingEnabled(true);
[150]92                //mItemBufferPass->setLightingEnabled(false);
[122]93        }
94        else
95        {
96                mItemBufferPass = itemBufferMat->getTechnique(0)->getPass(0);
97        }
[150]98        //mItemBufferPass->setAmbient(1, 1, 0);
[122]99}
100//-----------------------------------------------------------------------
[139]101void VisibilityTerrainSceneManager::PrepareVisualization(Camera *cam)
[115]102{
103        // add player camera for visualization purpose
[121]104        try
105        {
[115]106                Camera *c;
107                if ((c = getCamera("PlayerCam")) != NULL)
108                {
109                        getRenderQueue()->addRenderable(c);
110                }   
111    }
[121]112    catch (...)
[115]113    {
114        // ignore
115    }
[118]116        for (BoxList::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it)
117        {
118                getRenderQueue()->addRenderable(*it);
119        }
[115]120        if (mRenderNodesForViz || mRenderNodesContentForViz)
121        {
[118]122                // change node material so it is better suited for visualization
123                MaterialPtr nodeMat = MaterialManager::getSingleton().getByName("Core/NodeMaterial");
124                nodeMat->setAmbient(1, 1, 0);
125                nodeMat->setLightingEnabled(true);
126                nodeMat->getTechnique(0)->getPass(0)->removeAllTextureUnitStates();
127
[115]128                for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it)
129                {
130                        if (mRenderNodesForViz)
131                        {
[155]132                                if (((*it)->numAttachedObjects() > 0) && ((*it)->numChildren() == 0)
133                                        && (*it)->getAttachedObject(0)->getMovableType() == "Entity")
134                                getRenderQueue()->addRenderable((*it));
[121]135
[115]136                                // addbounding boxes instead of node itself
[139]137                                //(*it)->_addBoundingBoxToQueue(getRenderQueue());
[115]138                        }
139                        if (mRenderNodesContentForViz)
140                        {
[122]141                                (*it)->_addToRenderQueue(cam, getRenderQueue(), false);
[115]142                        }
143                }
[121]144        }       
[103]145}
146//-----------------------------------------------------------------------
[120]147Pass *VisibilityTerrainSceneManager::setPass(Pass* pass)
148{
[139]149        // TODO: setting vertex program is not efficient
150        //Pass *usedPass = ((mRenderDepthPass && !pass->hasVertexProgram()) ? mDepthPass : pass);
[121]151       
[156]152        // set depth fill pass if we currently do not make an aabb occlusion query
[133]153        Pass *usedPass = (mRenderDepthPass && !mHierarchyInterface->IsBoundingBoxQuery() ?
154                                          mDepthPass : pass);
[121]155               
156        IlluminationRenderStage savedStage = mIlluminationStage;
[120]157       
[121]158        // set illumination stage to NONE so no shadow material is used
159        // for depth pass or for occlusion query
[122]160        if (mRenderDepthPass || mHierarchyInterface->IsBoundingBoxQuery())
[121]161        {
162                mIlluminationStage = IRS_NONE;
163        }
164       
[159]165        // --- set vertex program of current pass in order to set correct depth
166        if (mExecuteVertexProgramForAllPasses && mRenderDepthPass && pass->hasVertexProgram())
[120]167        {
[159]168                // add vertex program of current pass to depth pass
169                mDepthPass->setVertexProgram(pass->getVertexProgramName());
[120]170
[159]171                if (mDepthPass->hasVertexProgram())
[120]172                {
[159]173                        const GpuProgramPtr& prg = mDepthPass->getVertexProgram();
174                        // Load this program if not done already
175                        if (!prg->isLoaded())
176                                prg->load();
177                        // Copy params
178                        mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters());
[120]179                }
180        }
[159]181        else if (mDepthPass->hasVertexProgram())
182        {
183                mDepthPass->setVertexProgram("");
184        }
185       
[133]186
187        bool IsDepthWrite = usedPass->getDepthWriteEnabled();
[139]188
[133]189        // global option which enables / disables depth writes
190        if (!mEnableDepthWrite)
191        {
192                usedPass->setDepthWriteEnabled(false);
193        }
[121]194        //else if (mIsItemBufferPass) {usedPass = mItemBufferPass;}
195       
196        Pass *result = SceneManager::setPass(usedPass);
[120]197
[133]198        // reset depth write
199        if (!mEnableDepthWrite)
200        {
201                usedPass->setDepthWriteEnabled(IsDepthWrite);
202        }
203
[121]204        // reset illumination stage
205        mIlluminationStage = savedStage;
206
207        return result;
[120]208}
209//-----------------------------------------------------------------------
[115]210void VisibilityTerrainSceneManager::_findVisibleObjects(Camera* cam, bool onlyShadowCasters)
[103]211{
[115]212        //-- show visible scene nodes and octree bounding boxes from last frame
213        if (mShowVisualization)
214    {
[139]215                PrepareVisualization(cam);
[115]216        }
[155]217        else
[139]218        {       
[148]219                // for hierarchical culling, we interleave identification
[147]220                // and rendering of objects in _renderVisibibleObjects
[148]221
[155]222                // for the shadow pass we use only standard rendering
223                // because of low occlusion
[147]224                if (mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE &&
225                        mIlluminationStage == IRS_RENDER_TO_TEXTURE)
226                {
227                        TerrainSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
228                }
[139]229                // only shadow casters will be rendered in shadow texture pass
[155]230                // mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters);
[139]231        }
[122]232       
[159]233       
[156]234        // -- delete lists stored for visualization
[121]235        mVisible.clear();
236        mBoxes.clear();
[115]237}
238//-----------------------------------------------------------------------
239void VisibilityTerrainSceneManager::_renderVisibleObjects()
240{
[155]241        // save ambient light to reset later
[150]242        ColourValue savedAmbient = mAmbientLight;
243
[159]244        //-- apply standard rendering for some modes (e.g., visualization, shadow pass)
[155]245
[158]246        if (mShowVisualization ||
[156]247           (mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE &&
248            mIlluminationStage == IRS_RENDER_TO_TEXTURE))
[87]249        {       
[139]250                IlluminationRenderStage savedStage = mIlluminationStage;
251       
[158]252                if (mShowVisualization)
253                        // disable illumination stage to prevent rendering shadows
[148]254                        mIlluminationStage = IRS_NONE;
255
256                // standard rendering for shadow maps because of performance
[101]257                TerrainSceneManager::_renderVisibleObjects();
[147]258
259                mIlluminationStage = savedStage;
[115]260        }
[159]261        else //-- the hierarchical culling algorithm
[147]262        {
[153]263                // don't render backgrounds for item buffer
264                if (mUseItemBuffer)
265                {
266                        clearSpecialCaseRenderQueues();
267                        getRenderQueue()->clear();
268                }
269
[159]270                //-- hierarchical culling
[139]271                // the objects of different layers (e.g., background, scene,
272                // overlay) must be identified and rendered one after another
[115]273
[139]274                //-- render all early skies
275                clearSpecialCaseRenderQueues();
276                addSpecialCaseRenderQueue(RENDER_QUEUE_BACKGROUND);
277                addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_EARLY);
278                setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE);
[122]279
[139]280                TerrainSceneManager::_renderVisibleObjects();
[153]281               
[87]282
[59]283#ifdef GTP_VISIBILITY_MODIFIED_OGRE
[159]284                // delete previously rendered content
[139]285                _deleteRenderedQueueGroups();
[59]286#endif
287
[139]288                //-- prepare queue for visible objects (i.e., all but overlay and skies late)
289                clearSpecialCaseRenderQueues();
290                addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_LATE);
291                addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY);
292                setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
[59]293
[100]294
[153]295                // set all necessary parameters for
296                // hierarchical visibility culling and rendering
[139]297                InitVisibilityCulling(mCameraInProgress);
[59]298
[139]299                /**
300                * the hierarchical culling algorithm
[159]301                * for depth pass: we just find objects and update depth buffer
302                * for "delayed" rendering: we render some passes afterwards
303                * e.g., transparents, because they need front-to-back sorting
[139]304                **/
305               
306                mVisibilityManager->ApplyVisibilityCulling();
307
308                // delete remaining renderables from queue (all not in mLeavePassesInQueue)
[135]309#ifdef GTP_VISIBILITY_MODIFIED_OGRE
[139]310                _deleteRenderedQueueGroups(mLeavePassesInQueue);
[135]311#endif
[100]312
[139]313                //-- reset parameters
314                mRenderDepthPass = false;
[153]315                mRenderItemBuffer = false;
[139]316                mSkipTransparents = false;
317                mLeavePassesInQueue = 0;
318                mShadowTechnique = mSavedShadowTechnique;
[153]319               
[139]320
321                // add visible nodes found by the visibility culling algorithm
322                if (mUseDepthPass)
[115]323                {
[139]324                        for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it)
325                        {
326                                (*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false);
327                        }
[122]328                }
[139]329               
330                //-- now we can render all remaining queue objects
[159]331                // used for depth pass, transparents, overlay
[139]332                clearSpecialCaseRenderQueues();
333                TerrainSceneManager::_renderVisibleObjects();
[115]334        }
[139]335               
[159]336        // set the new render level index
337        TerrainRenderable::NextRenderLevelIndex();
338       
[150]339        // reset ambient light
340        setAmbientLight(savedAmbient);
[153]341
[159]342        getRenderQueue()->clear(); // finally clear render queue
[99]343        //WriteLog(); // write out stats
[59]344}
[122]345
[59]346//-----------------------------------------------------------------------
347void VisibilityTerrainSceneManager::_updateSceneGraph(Camera* cam)
348{
349        mVisibilityManager->GetCullingManager()->SetHierarchyInterface(mHierarchyInterface);
350        mHierarchyInterface->SetRenderSystem(mDestRenderSystem);
[74]351
[59]352        TerrainSceneManager::_updateSceneGraph(cam);
353}
354//-----------------------------------------------------------------------
355bool VisibilityTerrainSceneManager::setOption(const String & key, const void * val)
356{
[115]357        if (key == "UseDepthPass")
[87]358        {
[115]359                mUseDepthPass = (*static_cast<const bool *>(val));
[87]360                return true;
361        }
[139]362        if (key == "PrepareVisualization")
[99]363        {
364                mShowVisualization = (*static_cast<const bool *>(val));
365                return true;
366        }
[103]367        if (key == "RenderNodesForViz")
368        {
369                mRenderNodesForViz = (*static_cast<const bool *>(val));
370                return true;
371        }
[113]372        if (key == "RenderNodesContentForViz")
373        {
374                mRenderNodesContentForViz = (*static_cast<const bool *>(val));
375                return true;
376        }
[100]377        if (key == "SkyBoxEnabled")
378        {
379                mSkyBoxEnabled = (*static_cast<const bool *>(val));
380                return true;
381        }
382        if (key == "SkyPlaneEnabled")
383        {
384                mSkyPlaneEnabled = (*static_cast<const bool *>(val));
385                return true;
386        }
387        if (key == "SkyDomeEnabled")
388        {
389                mSkyDomeEnabled = (*static_cast<const bool *>(val));
390                return true;
391        }
[112]392        if (key == "VisualizeCulledNodes")
393        {
394                mVisualizeCulledNodes = (*static_cast<const bool *>(val));
395                return true;
396        }
[115]397        if (key == "DelayRenderTransparents")
398        {
399                mDelayRenderTransparents = (*static_cast<const bool *>(val));
400                return true;
401        }
[159]402
[134]403        if (key == "DepthWrite")
[133]404        {
405                mEnableDepthWrite = (*static_cast<const bool *>(val));
406                return true;
407        }
[153]408        if (key == "UseItemBuffer")
[150]409        {
[153]410                mUseItemBuffer = (*static_cast<const bool *>(val));
[150]411                return true;
412        }
[159]413        if (key == "ExecuteVertexProgramForAllPasses")
414        {
415                mExecuteVertexProgramForAllPasses  = (*static_cast<const bool *>(val));
416                return true;
417        }
418        if (key == "RenderTransparentsForItemBuffer")
419        {
420                mRenderTransparentsForItemBuffer  = (*static_cast<const bool *>(val));
421                return true;
422        }
423
[74]424        return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
425                setOption(key, val) || TerrainSceneManager::setOption(key, val);
[59]426}
427//-----------------------------------------------------------------------
428bool VisibilityTerrainSceneManager::getOption(const String & key, void *val)
429{
[74]430        if (key == "NumHierarchyNodes")
431        {
432                * static_cast<unsigned int *>(val) = (unsigned int)mNumOctreeNodes;
433                return true;
434        }
435       
436        return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
437                getOption(key, val) && TerrainSceneManager::getOption(key, val);
[59]438}
439//-----------------------------------------------------------------------
[153]440bool VisibilityTerrainSceneManager::getOptionValues(const String & key,
441                                                                                                        StringVector &refValueList)
[59]442{
[74]443        return TerrainSceneManager::getOptionValues( key, refValueList);
[59]444}
445//-----------------------------------------------------------------------
446bool VisibilityTerrainSceneManager::getOptionKeys(StringVector & refKeys)
447{
[74]448        return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
449                getOptionKeys(refKeys) || TerrainSceneManager::getOptionKeys(refKeys);
[59]450}
451//-----------------------------------------------------------------------
[153]452void VisibilityTerrainSceneManager::setVisibilityManager(GtpVisibility::
453                                                                                                                 VisibilityManager *visManager)
[59]454{
455        mVisibilityManager = visManager;
456}
457//-----------------------------------------------------------------------
458GtpVisibility::VisibilityManager *VisibilityTerrainSceneManager::getVisibilityManager( void )
459{
460        return mVisibilityManager;
461}
[93]462//-----------------------------------------------------------------------
463void VisibilityTerrainSceneManager::WriteLog()
464{
465        std::stringstream d;
466
[120]467        d << "Depth pass: " << StringConverter::toString(mUseDepthPass) << ", "
468          << "Delay transparents: " << StringConverter::toString(mDelayRenderTransparents) << ", "
[155]469          << "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetTestGeometryForVisibleLeaves()) << ", "
[120]470          << "Algorithm type: " << mVisibilityManager->GetCullingManagerType() << ", "
[101]471          << "Hierarchy nodes: " << mNumOctreeNodes << ", "
472          << "Traversed nodes: " << mHierarchyInterface->GetNumTraversedNodes() << ", "
[93]473          << "Rendered nodes: " << mHierarchyInterface->GetNumRenderedNodes() << ", "
474          << "Query culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumQueryCulledNodes() << ", "
475          << "Frustum culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumFrustumCulledNodes() << ", "
476      << "Queries issued: " << mVisibilityManager->GetCullingManager()->GetNumQueriesIssued() << "\n";
477
478        LogManager::getSingleton().logMessage(d.str());
479}
[114]480//-----------------------------------------------------------------------
[139]481void VisibilityTerrainSceneManager::renderObjects(
482        const RenderPriorityGroup::TransparentRenderablePassList& objs,
483    bool doLightIteration, const LightList* manualLightList)
[114]484{
[121]485        // for correct rendering, transparents must be rendered after hierarchical culling
[115]486        if (!mSkipTransparents)
[114]487        {
488                OctreeSceneManager::renderObjects(objs, doLightIteration, manualLightList);
489        }
490}
[121]491//-----------------------------------------------------------------------
492bool VisibilityTerrainSceneManager::validatePassForRendering(Pass* pass)
493{
494        // skip all but first pass if we are doing the depth pass
[122]495        if ((mRenderDepthPass || mRenderItemBuffer) && pass->getIndex() > 0)
[121]496        {
497                return false;
498        }
499        return SceneManager::validatePassForRendering(pass);
500}
[122]501//-----------------------------------------------------------------------
502void VisibilityTerrainSceneManager::renderQueueGroupObjects(RenderQueueGroup* pGroup)
503{
504        if (!mRenderItemBuffer)
505        {
506                TerrainSceneManager::renderQueueGroupObjects(pGroup);
507                return;
508        }
[103]509
[156]510        // --- item buffer
511
[122]512    // Iterate through priorities
513    RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
514
515        while (groupIt.hasMoreElements())
516    {
517                RenderItemBuffer(groupIt.getNext());
518        }
519}
520//-----------------------------------------------------------------------
521void VisibilityTerrainSceneManager::RenderItemBuffer(RenderPriorityGroup* pGroup)
522{
523        // Do solids
524        RenderPriorityGroup::SolidRenderablePassMap solidObjs = pGroup->_getSolidPasses();
525
526        // ----- SOLIDS LOOP -----
527        RenderPriorityGroup::SolidRenderablePassMap::const_iterator ipass, ipassend;
528        ipassend = solidObjs.end();
529
530        for (ipass = solidObjs.begin(); ipass != ipassend; ++ipass)
531        {
532                // Fast bypass if this group is now empty
533                if (ipass->second->empty())
534                        continue;
535
536                // Render only first pass
537                if (ipass->first->getIndex() > 0)
538                        continue;
539
540                RenderPriorityGroup::RenderableList* rendList = ipass->second;
541               
542                RenderPriorityGroup::RenderableList::const_iterator irend, irendend;
543                irendend = rendList->end();
544                       
545                for (irend = rendList->begin(); irend != irendend; ++irend)
546                {
[129]547                        std::stringstream d; d << "itembuffer, pass name: " <<
548                                ipass->first->getParent()->getParent()->getName();
[139]549                               
[129]550                        LogManager::getSingleton().logMessage(d.str());
551                       
[139]552                        RenderSingleObjectForItemBuffer(*irend, ipass->first);
[122]553                }
554        }
555
[159]556        // -- TRANSPARENT LOOP: must be handled differently
[122]557
[159]558        // transparents are treated either as solids or completely discarded
559        if (mRenderTransparentsForItemBuffer)
[122]560        {
[159]561                RenderPriorityGroup::TransparentRenderablePassList transpObjs =
562                        pGroup->_getTransparentPasses();
563                RenderPriorityGroup::TransparentRenderablePassList::const_iterator
564                        itrans, itransend;
565
566                itransend = transpObjs.end();
567                for (itrans = transpObjs.begin(); itrans != itransend; ++itrans)
568                {
569                        // like for solids, render only first pass
570                        if (itrans->pass->getIndex() == 0)
571                        {       
572                                RenderSingleObjectForItemBuffer(itrans->renderable, itrans->pass);
573                        }
[122]574                }
[159]575        }
[122]576}
577//-----------------------------------------------------------------------
[129]578void VisibilityTerrainSceneManager::RenderSingleObjectForItemBuffer(Renderable *rend, Pass *pass)
[122]579{
580        static LightList nullLightList;
[150]581       
582        int col[4];
583       
[154]584        // -- create color code out of object id
[150]585        col[0] = (rend->getId() >> 16) & 255;
586        col[1] = (rend->getId() >> 8) & 255;
587        col[2] = rend->getId() & 255;
[157]588//      col[3] = 255;
[129]589
[150]590        //mDestRenderSystem->setColour(col[0], col[1], col[2], col[3]);
591   
592        mItemBufferPass->setAmbient(ColourValue(col[0] / 255.0f,
593                                                                                    col[1] / 255.0f,
594                                                                                        col[2] / 255.0f, 1));
[122]595
[129]596        // set vertex program of current pass
[159]597        if (mExecuteVertexProgramForAllPasses && pass->hasVertexProgram())
[129]598        {
599                mItemBufferPass->setVertexProgram(pass->getVertexProgramName());
600
601                if (mItemBufferPass->hasVertexProgram())
602                {
603                        const GpuProgramPtr& prg = mItemBufferPass->getVertexProgram();
604                        // Load this program if not done already
605                        if (!prg->isLoaded())
606                                prg->load();
607                        // Copy params
608                        mItemBufferPass->setVertexProgramParameters(pass->getVertexProgramParameters());
609                }
610        }
611        else if (mItemBufferPass->hasVertexProgram())
612        {
613                mItemBufferPass->setVertexProgram("");
614        }
615
616        Pass *usedPass = setPass(mItemBufferPass);
617
[156]618
[122]619        // Render a single object, this will set up auto params if required
[129]620        renderSingleObject(rend, usedPass, false, &nullLightList);
[122]621}
622//-----------------------------------------------------------------------
[130]623GtpVisibility::VisibilityManager *VisibilityTerrainSceneManager::GetVisibilityManager()
[122]624{
[130]625        return mVisibilityManager;
626}
627//-----------------------------------------------------------------------
[139]628void VisibilityTerrainSceneManager::InitVisibilityCulling(Camera *cam)
629{
630        InitDepthPass();          // create material for depth pass
631        InitItemBufferPass(); // create material for item buffer pass
[122]632
[153]633        // reset culling manager stats
634        mVisibilityManager->GetCullingManager()->InitFrame(mVisualizeCulledNodes);
635
[149]636        // save shadow technique. It will be reset after hierarchical culling
[139]637        mSavedShadowTechnique = mShadowTechnique;
638
[153]639        // render standard solids without shadows during hierarchical culling pass
640        if ((mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE) ||
641            (mShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE))
[159]642        {       
[153]643                mShadowTechnique = SHADOWTYPE_NONE;
644        }
[139]645
[153]646        // set depth pass flag before rendering
647        mRenderDepthPass = mUseDepthPass;
648
[150]649        // item buffer needs full ambient lighting to use item colors as unique id
650        if (mUseItemBuffer)
651        {
652                mRenderItemBuffer = true;
653                setAmbientLight(ColourValue(1,1,1,1));
654        }
655
656
[159]657        // set passes which are stored in render queue
[153]658        // for rendering AFTER hierarchical culling, i.e., passes which need
659        // a special rendering order
660        mLeavePassesInQueue = 0;
[150]661
[153]662        if (!mUseDepthPass || !mUseItemBuffer)
[139]663        {
[153]664                if (mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE)
[139]665                {
[153]666                        // TODO: remove this pass because it should be processed during hierarchical culling
[139]667                        mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW;
668
669                        mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_DECAL;
670                        mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_DIFFUSE_SPECULAR;
671                        mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
[153]672
673                        // just render ambient stuff
674                        mIlluminationStage = IRS_AMBIENT;
[139]675                }
[153]676       
677                if (mShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE)
[139]678                {
679                        mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW;
680                        mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
681                }
[141]682       
[153]683                // transparents should be rendered after hierarchical culling to
684                // provide front-to-back ordering
685                if (mDelayRenderTransparents)
686                {
687                        mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
688                }
[139]689        }
690
[153]691        // skip rendering transparents in the hierarchical culling
692        // (because they will be rendered afterwards)
693        mSkipTransparents = mUseDepthPass ||
694                (mLeavePassesInQueue & RenderPriorityGroup::TRANSPARENT_PASSES);
695
[155]696        // -- initialise interface for rendering traversal of the hierarchy
697        mHierarchyInterface->SetHierarchyRoot(mOctree);
698       
[139]699        // possible two cameras (one for culling, one for rendering)
[155]700        mHierarchyInterface->InitTraversal(mCameraInProgress,
701                                                        mCullCamera ? getCamera("CullCamera") : NULL,
702                                                        mLeavePassesInQueue);
[139]703               
[153]704        //std::stringstream d; d << "leave passes in queue: " << mLeavePassesInQueue;LogManager::getSingleton().logMessage(d.str());
[139]705}
706//-----------------------------------------------------------------------
[153]707OctreeHierarchyInterface *VisibilityTerrainSceneManager::GetHierarchyInterface()
708{
709        return mHierarchyInterface;
710}
711//-----------------------------------------------------------------------
[159]712void VisibilityTerrainSceneManager::endFrame()
713{
714        TerrainRenderable::ResetRenderLevelIndex();
715}
716//-----------------------------------------------------------------------
[139]717/*void VisibilityTerrainSceneManager::renderBasicQueueGroupObjects(RenderQueueGroup* pGroup)
718{
[153]719    // Basic render loop: Iterate through priorities
[139]720    RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
721
722    while (groupIt.hasMoreElements())
723    {
724        RenderPriorityGroup* pPriorityGrp = groupIt.getNext();
725
726        // Sort the queue first
727        pPriorityGrp->sort(mCameraInProgress);
728
[153]729                // Do solids
730                // TODO: render other solid passes for shadows
[139]731        renderObjects(pPriorityGrp->_getSolidPassesNoShadows(), true);
732
733                // do solid passes no shadows if addititive stencil shadows
734                if (mSavedShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE)
735                        renderObjects(pPriorityGrp->_getSolidPassesNoShadows(), true);
736               
737        // Do transparents
738        renderObjects(pPriorityGrp->_getTransparentPasses(), true);
739
740
741    }// for each priority
742}
743*/
[159]744//-----------------------------------------------------------------------
745/*
746Entity* VisibilityTerrainSceneManager::createEntity(const String& entityName,
747                                                                                                        const String& meshName)
748{
749        Entity *ent = SceneManager::createEntity(entityName, meshName);
750
751        for (int i = 0; i < (int)ent->getNumSubEntities(); ++i)
752        {
753                ent->getSubEntity(i)->setId(mCurrentEntityId);
754        }
755
756        // increase counter of entity id values
757        ++ mCurrentEntityId;
758
759        return ent;
760}
761*/
[59]762} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.