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

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

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

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(GtpVisibility::
17                                                                                                                         VisibilityManager *visManager):
18mVisibilityManager(visManager),
19mShowVisualization(false),
20mRenderNodesForViz(false),
21mRenderNodesContentForViz(false),
22mVisualizeCulledNodes(false),
23mLeavePassesInQueue(0),
24mDelayRenderTransparents(true),
25mUseDepthPass(false),
26mRenderDepthPass(false),
27mUseItemBuffer(false),
28//mUseItemBuffer(true),
29mRenderItemBuffer(false),
30mCurrentEntityId(1),
31mEnableDepthWrite(true),
32mSkipTransparents(false),
33mSavedShadowTechnique(SHADOWTYPE_NONE),
34mRenderTransparentsForItemBuffer(false),
35mExecuteVertexProgramForAllPasses(false)
36{
37        mHierarchyInterface = new OctreeHierarchyInterface(this, mDestRenderSystem);
38       
39        //mDisplayNodes = true;
40        //mShowBoundingBoxes = true;
41        //mShowBoxes = true;
42        //mShowBoxes = true;
43
44        // TODO: set maxdepth to reasonable value
45        mMaxDepth = 50;
46}
47//-----------------------------------------------------------------------
48void VisibilityTerrainSceneManager::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//-----------------------------------------------------------------------
69VisibilityTerrainSceneManager::~VisibilityTerrainSceneManager()
70{
71        if (mHierarchyInterface)
72        {
73                delete mHierarchyInterface;
74                mHierarchyInterface = NULL;
75        }
76}
77//-----------------------------------------------------------------------
78void VisibilityTerrainSceneManager::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 VisibilityTerrainSceneManager::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 *VisibilityTerrainSceneManager::setPass(Pass* pass)
149{
150        // TODO: setting vertex program is not efficient
151        //Pass *usedPass = ((mRenderDepthPass && !pass->hasVertexProgram()) ? mDepthPass : pass);
152       
153        // set depth fill pass if we currently do not make an aabb occlusion query
154        Pass *usedPass = (mRenderDepthPass && !mHierarchyInterface->IsBoundingBoxQuery() ?
155                                          mDepthPass : pass);
156               
157        IlluminationRenderStage savedStage = mIlluminationStage;
158       
159        // set illumination stage to NONE so no shadow material is used
160        // for depth pass or for occlusion query
161        if (mRenderDepthPass || mHierarchyInterface->IsBoundingBoxQuery())
162        {
163                mIlluminationStage = IRS_NONE;
164        }
165       
166        // --- set vertex program of current pass in order to set correct depth
167        if (mExecuteVertexProgramForAllPasses && mRenderDepthPass && pass->hasVertexProgram())
168        {
169                // add vertex program of current pass to depth pass
170                mDepthPass->setVertexProgram(pass->getVertexProgramName());
171
172                if (mDepthPass->hasVertexProgram())
173                {
174                        const GpuProgramPtr& prg = mDepthPass->getVertexProgram();
175                        // Load this program if not done already
176                        if (!prg->isLoaded())
177                                prg->load();
178                        // Copy params
179                        mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters());
180                }
181        }
182        else if (mDepthPass->hasVertexProgram())
183        {
184                mDepthPass->setVertexProgram("");
185        }
186       
187
188        bool IsDepthWrite = usedPass->getDepthWriteEnabled();
189
190        // global option which enables / disables depth writes
191        if (!mEnableDepthWrite)
192        {
193                usedPass->setDepthWriteEnabled(false);
194        }
195        //else if (mIsItemBufferPass) {usedPass = mItemBufferPass;}
196       
197        Pass *result = SceneManager::setPass(usedPass);
198
199        // reset depth write
200        if (!mEnableDepthWrite)
201        {
202                usedPass->setDepthWriteEnabled(IsDepthWrite);
203        }
204
205        // reset illumination stage
206        mIlluminationStage = savedStage;
207
208        return result;
209}
210//-----------------------------------------------------------------------
211void VisibilityTerrainSceneManager::_findVisibleObjects(Camera* cam, bool onlyShadowCasters)
212{
213        //-- show visible scene nodes and octree bounding boxes from last frame
214        if (mShowVisualization)
215    {
216                PrepareVisualization(cam);
217        }
218        else
219        {       
220                // for hierarchical culling, we interleave identification
221                // and rendering of objects in _renderVisibibleObjects
222
223                // for the shadow pass we use only standard rendering
224                // because of low occlusion
225                if (mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE &&
226                        mIlluminationStage == IRS_RENDER_TO_TEXTURE)
227                {
228                        TerrainSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
229                }
230                // only shadow casters will be rendered in shadow texture pass
231                // mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters);
232        }
233       
234       
235        // -- delete lists stored for visualization
236        mVisible.clear();
237        mBoxes.clear();
238}
239//-----------------------------------------------------------------------
240void VisibilityTerrainSceneManager::_renderVisibleObjects()
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                        // disable illumination stage to prevent rendering shadows
255                        mIlluminationStage = IRS_NONE;
256
257                // standard rendering for shadow maps because of performance
258                TerrainSceneManager::_renderVisibleObjects();
259
260                mIlluminationStage = savedStage;
261        }
262        else //-- the hierarchical culling algorithm
263        {
264                // don't render backgrounds for item buffer
265                if (mUseItemBuffer)
266                {
267                        clearSpecialCaseRenderQueues();
268                        getRenderQueue()->clear();
269                }
270
271                //-- hierarchical culling
272                // the objects of different layers (e.g., background, scene,
273                // overlay) must be identified and rendered one after another
274
275                //-- render all early skies
276                clearSpecialCaseRenderQueues();
277                addSpecialCaseRenderQueue(RENDER_QUEUE_BACKGROUND);
278                addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_EARLY);
279                setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE);
280
281                TerrainSceneManager::_renderVisibleObjects();
282               
283
284#ifdef GTP_VISIBILITY_MODIFIED_OGRE
285                // delete previously rendered content
286                _deleteRenderedQueueGroups();
287#endif
288
289                //-- prepare queue for visible objects (i.e., all but overlay and skies late)
290                clearSpecialCaseRenderQueues();
291                addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_LATE);
292                addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY);
293                setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
294
295
296                // set all necessary parameters for
297                // hierarchical visibility culling and rendering
298                InitVisibilityCulling(mCameraInProgress);
299
300                /**
301                * the hierarchical culling algorithm
302                * for depth pass: we just find objects and update depth buffer
303                * for "delayed" rendering: we render some passes afterwards
304                * e.g., transparents, because they need front-to-back sorting
305                **/
306               
307                mVisibilityManager->ApplyVisibilityCulling();
308
309                // delete remaining renderables from queue (all not in mLeavePassesInQueue)
310#ifdef GTP_VISIBILITY_MODIFIED_OGRE
311                _deleteRenderedQueueGroups(mLeavePassesInQueue);
312#endif
313
314                //-- reset parameters
315                mRenderDepthPass = false;
316                mRenderItemBuffer = false;
317                mSkipTransparents = false;
318                mLeavePassesInQueue = 0;
319                mShadowTechnique = mSavedShadowTechnique;
320               
321
322                // add visible nodes found by the visibility culling algorithm
323                if (mUseDepthPass)
324                {
325                        for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it)
326                        {
327                                (*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false);
328                        }
329                }
330               
331                //-- now we can render all remaining queue objects
332                // used for depth pass, transparents, overlay
333                clearSpecialCaseRenderQueues();
334                TerrainSceneManager::_renderVisibleObjects();
335        }
336               
337        // set the new render level index
338        TerrainRenderable::NextRenderLevelIndex();
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 VisibilityTerrainSceneManager::_updateSceneGraph(Camera* cam)
349{
350        mVisibilityManager->GetCullingManager()->SetHierarchyInterface(mHierarchyInterface);
351        mHierarchyInterface->SetRenderSystem(mDestRenderSystem);
352
353        TerrainSceneManager::_updateSceneGraph(cam);
354}
355//-----------------------------------------------------------------------
356bool VisibilityTerrainSceneManager::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) || TerrainSceneManager::setOption(key, val);
427}
428//-----------------------------------------------------------------------
429bool VisibilityTerrainSceneManager::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) && TerrainSceneManager::getOption(key, val);
439}
440//-----------------------------------------------------------------------
441bool VisibilityTerrainSceneManager::getOptionValues(const String & key,
442                                                                                                        StringVector &refValueList)
443{
444        return TerrainSceneManager::getOptionValues( key, refValueList);
445}
446//-----------------------------------------------------------------------
447bool VisibilityTerrainSceneManager::getOptionKeys(StringVector & refKeys)
448{
449        return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
450                getOptionKeys(refKeys) || TerrainSceneManager::getOptionKeys(refKeys);
451}
452//-----------------------------------------------------------------------
453void VisibilityTerrainSceneManager::setVisibilityManager(GtpVisibility::
454                                                                                                                 VisibilityManager *visManager)
455{
456        mVisibilityManager = visManager;
457}
458//-----------------------------------------------------------------------
459GtpVisibility::VisibilityManager *VisibilityTerrainSceneManager::getVisibilityManager( void )
460{
461        return mVisibilityManager;
462}
463//-----------------------------------------------------------------------
464void VisibilityTerrainSceneManager::WriteLog()
465{
466        std::stringstream d;
467
468        d << "Depth pass: " << StringConverter::toString(mUseDepthPass) << ", "
469          << "Delay transparents: " << StringConverter::toString(mDelayRenderTransparents) << ", "
470          << "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetTestGeometryForVisibleLeaves()) << ", "
471          << "Algorithm type: " << mVisibilityManager->GetCullingManagerType() << ", "
472          << "Hierarchy nodes: " << mNumOctreeNodes << ", "
473          << "Traversed nodes: " << mHierarchyInterface->GetNumTraversedNodes() << ", "
474          << "Rendered nodes: " << mHierarchyInterface->GetNumRenderedNodes() << ", "
475          << "Query culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumQueryCulledNodes() << ", "
476          << "Frustum culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumFrustumCulledNodes() << ", "
477      << "Queries issued: " << mVisibilityManager->GetCullingManager()->GetNumQueriesIssued() << "\n";
478
479        LogManager::getSingleton().logMessage(d.str());
480}
481//-----------------------------------------------------------------------
482void VisibilityTerrainSceneManager::renderObjects(
483        const RenderPriorityGroup::TransparentRenderablePassList& objs,
484    bool doLightIteration, const LightList* manualLightList)
485{
486        // for correct rendering, transparents must be rendered after hierarchical culling
487        if (!mSkipTransparents)
488        {
489                OctreeSceneManager::renderObjects(objs, doLightIteration, manualLightList);
490        }
491}
492//-----------------------------------------------------------------------
493bool VisibilityTerrainSceneManager::validatePassForRendering(Pass* pass)
494{
495        // skip all but first pass if we are doing the depth pass
496        if ((mRenderDepthPass || mRenderItemBuffer) && pass->getIndex() > 0)
497        {
498                return false;
499        }
500        return SceneManager::validatePassForRendering(pass);
501}
502//-----------------------------------------------------------------------
503void VisibilityTerrainSceneManager::renderQueueGroupObjects(RenderQueueGroup* pGroup)
504{
505        if (!mRenderItemBuffer)
506        {
507                TerrainSceneManager::renderQueueGroupObjects(pGroup);
508                return;
509        }
510
511        // --- item buffer
512
513    // Iterate through priorities
514    RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
515
516        while (groupIt.hasMoreElements())
517    {
518                RenderItemBuffer(groupIt.getNext());
519        }
520}
521//-----------------------------------------------------------------------
522void VisibilityTerrainSceneManager::RenderItemBuffer(RenderPriorityGroup* pGroup)
523{
524        // Do solids
525        RenderPriorityGroup::SolidRenderablePassMap solidObjs = pGroup->_getSolidPasses();
526
527        // ----- SOLIDS LOOP -----
528        RenderPriorityGroup::SolidRenderablePassMap::const_iterator ipass, ipassend;
529        ipassend = solidObjs.end();
530
531        for (ipass = solidObjs.begin(); ipass != ipassend; ++ipass)
532        {
533                // Fast bypass if this group is now empty
534                if (ipass->second->empty())
535                        continue;
536
537                // Render only first pass
538                if (ipass->first->getIndex() > 0)
539                        continue;
540
541                RenderPriorityGroup::RenderableList* rendList = ipass->second;
542               
543                RenderPriorityGroup::RenderableList::const_iterator irend, irendend;
544                irendend = rendList->end();
545                       
546                for (irend = rendList->begin(); irend != irendend; ++irend)
547                {
548                        std::stringstream d; d << "itembuffer, pass name: " <<
549                                ipass->first->getParent()->getParent()->getName();
550                               
551                        LogManager::getSingleton().logMessage(d.str());
552                       
553                        RenderSingleObjectForItemBuffer(*irend, ipass->first);
554                }
555        }
556
557        // -- TRANSPARENT LOOP: must be handled differently
558
559        // transparents are treated either as solids or completely discarded
560        if (mRenderTransparentsForItemBuffer)
561        {
562                RenderPriorityGroup::TransparentRenderablePassList transpObjs =
563                        pGroup->_getTransparentPasses();
564                RenderPriorityGroup::TransparentRenderablePassList::const_iterator
565                        itrans, itransend;
566
567                itransend = transpObjs.end();
568                for (itrans = transpObjs.begin(); itrans != itransend; ++itrans)
569                {
570                        // like for solids, render only first pass
571                        if (itrans->pass->getIndex() == 0)
572                        {       
573                                RenderSingleObjectForItemBuffer(itrans->renderable, itrans->pass);
574                        }
575                }
576        }
577}
578//-----------------------------------------------------------------------
579void VisibilityTerrainSceneManager::RenderSingleObjectForItemBuffer(Renderable *rend, Pass *pass)
580{
581        static LightList nullLightList;
582       
583        int col[4];
584       
585        // -- create color code out of object id
586        col[0] = (rend->getId() >> 16) & 255;
587        col[1] = (rend->getId() >> 8) & 255;
588        col[2] = rend->getId() & 255;
589//      col[3] = 255;
590
591        //mDestRenderSystem->setColour(col[0], col[1], col[2], col[3]);
592   
593        mItemBufferPass->setAmbient(ColourValue(col[0] / 255.0f,
594                                                                                    col[1] / 255.0f,
595                                                                                        col[2] / 255.0f, 1));
596
597        // set vertex program of current pass
598        if (mExecuteVertexProgramForAllPasses && pass->hasVertexProgram())
599        {
600                mItemBufferPass->setVertexProgram(pass->getVertexProgramName());
601
602                if (mItemBufferPass->hasVertexProgram())
603                {
604                        const GpuProgramPtr& prg = mItemBufferPass->getVertexProgram();
605                        // Load this program if not done already
606                        if (!prg->isLoaded())
607                                prg->load();
608                        // Copy params
609                        mItemBufferPass->setVertexProgramParameters(pass->getVertexProgramParameters());
610                }
611        }
612        else if (mItemBufferPass->hasVertexProgram())
613        {
614                mItemBufferPass->setVertexProgram("");
615        }
616
617        Pass *usedPass = setPass(mItemBufferPass);
618
619
620        // Render a single object, this will set up auto params if required
621        renderSingleObject(rend, usedPass, false, &nullLightList);
622}
623//-----------------------------------------------------------------------
624GtpVisibility::VisibilityManager *VisibilityTerrainSceneManager::GetVisibilityManager()
625{
626        return mVisibilityManager;
627}
628//-----------------------------------------------------------------------
629void VisibilityTerrainSceneManager::InitVisibilityCulling(Camera *cam)
630{
631        InitDepthPass();          // create material for depth pass
632        InitItemBufferPass(); // create material for item buffer pass
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        mLeavePassesInQueue = 0;
662
663        if (!mUseDepthPass || !mUseItemBuffer)
664        {
665                if (mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE)
666                {
667                        // TODO: remove this pass because it should be processed during hierarchical culling
668                        mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW;
669
670                        mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_DECAL;
671                        mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_DIFFUSE_SPECULAR;
672                        mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
673
674                        // just render ambient stuff
675                        mIlluminationStage = IRS_AMBIENT;
676                }
677       
678                if (mShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE)
679                {
680                        mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW;
681                        mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
682                }
683       
684                // transparents should be rendered after hierarchical culling to
685                // provide front-to-back ordering
686                if (mDelayRenderTransparents)
687                {
688                        mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
689                }
690        }
691
692        // skip rendering transparents in the hierarchical culling
693        // (because they will be rendered afterwards)
694        mSkipTransparents = mUseDepthPass ||
695                (mLeavePassesInQueue & RenderPriorityGroup::TRANSPARENT_PASSES);
696
697        // -- initialise interface for rendering traversal of the hierarchy
698        mHierarchyInterface->SetHierarchyRoot(mOctree);
699       
700        // possible two cameras (one for culling, one for rendering)
701        mHierarchyInterface->InitTraversal(mCameraInProgress,
702                                                        mCullCamera ? getCamera("CullCamera") : NULL,
703                                                        mLeavePassesInQueue);
704               
705        //std::stringstream d; d << "leave passes in queue: " << mLeavePassesInQueue;LogManager::getSingleton().logMessage(d.str());
706}
707//-----------------------------------------------------------------------
708OctreeHierarchyInterface *VisibilityTerrainSceneManager::GetHierarchyInterface()
709{
710        return mHierarchyInterface;
711}
712//-----------------------------------------------------------------------
713void VisibilityTerrainSceneManager::endFrame()
714{
715        TerrainRenderable::ResetRenderLevelIndex();
716}
717//-----------------------------------------------------------------------
718/*void VisibilityTerrainSceneManager::renderBasicQueueGroupObjects(RenderQueueGroup* pGroup)
719{
720    // Basic render loop: Iterate through priorities
721    RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
722
723    while (groupIt.hasMoreElements())
724    {
725        RenderPriorityGroup* pPriorityGrp = groupIt.getNext();
726
727        // Sort the queue first
728        pPriorityGrp->sort(mCameraInProgress);
729
730                // Do solids
731                // TODO: render other solid passes for shadows
732        renderObjects(pPriorityGrp->_getSolidPassesNoShadows(), true);
733
734                // do solid passes no shadows if addititive stencil shadows
735                if (mSavedShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE)
736                        renderObjects(pPriorityGrp->_getSolidPassesNoShadows(), true);
737               
738        // Do transparents
739        renderObjects(pPriorityGrp->_getTransparentPasses(), true);
740
741
742    }// for each priority
743}
744*/
745//-----------------------------------------------------------------------
746/*
747Entity* VisibilityTerrainSceneManager::createEntity(const String& entityName,
748                                                                                                        const String& meshName)
749{
750        Entity *ent = SceneManager::createEntity(entityName, meshName);
751
752        for (int i = 0; i < (int)ent->getNumSubEntities(); ++i)
753        {
754                ent->getSubEntity(i)->setId(mCurrentEntityId);
755        }
756
757        // increase counter of entity id values
758        ++ mCurrentEntityId;
759
760        return ent;
761}
762*/
763} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.