source: trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp @ 175

Revision 175, 23.9 KB checked in by mattausch, 19 years ago (diff)

added trees

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