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

Revision 259, 25.1 KB checked in by mattausch, 19 years ago (diff)

refined measurements

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