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

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

added trees

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),
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;//mShowBoundingBoxes = true;//mShowBoxes = true;
40
41        // TODO: set maxdepth to reasonable value
42        mMaxDepth = 50;
43}
44//-----------------------------------------------------------------------
45void VisibilityTerrainSceneManager::InitDepthPass()
46{
47        MaterialPtr depthMat = MaterialManager::getSingleton().getByName("Visibility/DepthPass");
48
49        if (depthMat.isNull())
50    {
51                depthMat = MaterialManager::getSingleton().create(
52                "Visibility/DepthPass",
53                ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
54
55        mDepthPass = depthMat->getTechnique(0)->getPass(0);
56                mDepthPass->setColourWriteEnabled(false);
57                mDepthPass->setDepthWriteEnabled(true);
58                mDepthPass->setLightingEnabled(false);
59        }
60        else
61        {
62                mDepthPass = depthMat->getTechnique(0)->getPass(0);
63        }
64}
65//-----------------------------------------------------------------------
66VisibilityTerrainSceneManager::~VisibilityTerrainSceneManager()
67{
68        if (mHierarchyInterface)
69        {
70                delete mHierarchyInterface;
71                mHierarchyInterface = NULL;
72        }
73}
74//-----------------------------------------------------------------------
75void VisibilityTerrainSceneManager::InitItemBufferPass()
76{
77        MaterialPtr itemBufferMat = MaterialManager::getSingleton().
78                getByName("Visibility/ItemBufferPass");
79
80        if (itemBufferMat.isNull())
81    {
82                // Init
83                itemBufferMat = MaterialManager::getSingleton().create("Visibility/ItemBufferPass",
84                ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
85
86                mItemBufferPass = itemBufferMat->getTechnique(0)->getPass(0);
87                mItemBufferPass->setColourWriteEnabled(true);
88                mItemBufferPass->setDepthWriteEnabled(true);
89                mItemBufferPass->setLightingEnabled(true);
90                //mItemBufferPass->setLightingEnabled(false);
91        }
92        else
93        {
94                mItemBufferPass = itemBufferMat->getTechnique(0)->getPass(0);
95        }
96        //mItemBufferPass->setAmbient(1, 1, 0);
97}
98//-----------------------------------------------------------------------
99void VisibilityTerrainSceneManager::PrepareVisualization(Camera *cam)
100{
101        // add player camera for visualization purpose
102        try
103        {
104                Camera *c;
105                if ((c = getCamera("PlayerCam")) != NULL)
106                {
107                        getRenderQueue()->addRenderable(c);
108                }   
109    }
110    catch (...)
111    {
112        // ignore
113    }
114        for (BoxList::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it)
115        {
116                getRenderQueue()->addRenderable(*it);
117        }
118        if (mRenderNodesForViz || mRenderNodesContentForViz)
119        {
120                // HACK: change node material so it is better suited for visualization
121                MaterialPtr nodeMat = MaterialManager::getSingleton().getByName("Core/NodeMaterial");
122                nodeMat->setAmbient(1, 1, 0);
123                nodeMat->setLightingEnabled(true);
124                nodeMat->getTechnique(0)->getPass(0)->removeAllTextureUnitStates();
125
126                for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it)
127                {
128                        if (mRenderNodesForViz)
129                        {
130                                // render the leaf nodes
131                                if (((*it)->numAttachedObjects() > 0) && ((*it)->numChildren() == 0) &&
132                                         (*it)->getAttachedObject(0)->getMovableType() == "Entity")
133                                {
134                                        getRenderQueue()->addRenderable((*it));
135                                }
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        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
287#ifdef GTP_VISIBILITY_MODIFIED_OGRE
288                // delete previously rendered content
289                _deleteRenderedQueueGroups();
290#endif
291
292                //-- prepare queue for visible objects (i.e., all but overlay and skies late)
293                clearSpecialCaseRenderQueues();
294                addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_LATE);
295                addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY);
296                setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
297
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                mRenderDepthPass = false;
319                mRenderItemBuffer = false;
320                mSkipTransparents = false;
321                mLeavePassesInQueue = 0;
322                mShadowTechnique = mSavedShadowTechnique;
323               
324
325                // add visible nodes found by the visibility culling algorithm
326                if (mUseDepthPass)
327                {
328                        for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it)
329                        {
330                                (*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false);
331                        }
332                }
333               
334                //-- now we can render all remaining queue objects
335                // used for depth pass, transparents, overlay
336                clearSpecialCaseRenderQueues();
337                TerrainSceneManager::_renderVisibleObjects();
338        }
339               
340        // set the new render level index
341        TerrainRenderable::NextRenderLevelIndex();
342       
343        // reset ambient light
344        setAmbientLight(savedAmbient);
345
346        getRenderQueue()->clear(); // finally clear render queue
347        //WriteLog(); // write out stats
348}
349
350//-----------------------------------------------------------------------
351void VisibilityTerrainSceneManager::_updateSceneGraph(Camera* cam)
352{
353        mVisibilityManager->GetCullingManager()->SetHierarchyInterface(mHierarchyInterface);
354        mHierarchyInterface->SetRenderSystem(mDestRenderSystem);
355
356        TerrainSceneManager::_updateSceneGraph(cam);
357}
358//-----------------------------------------------------------------------
359bool VisibilityTerrainSceneManager::setOption(const String & key, const void * val)
360{
361        if (key == "UseDepthPass")
362        {
363                mUseDepthPass = (*static_cast<const bool *>(val));
364                return true;
365        }
366        if (key == "PrepareVisualization")
367        {
368                mShowVisualization = (*static_cast<const bool *>(val));
369                return true;
370        }
371        if (key == "RenderNodesForViz")
372        {
373                mRenderNodesForViz = (*static_cast<const bool *>(val));
374                return true;
375        }
376        if (key == "RenderNodesContentForViz")
377        {
378                mRenderNodesContentForViz = (*static_cast<const bool *>(val));
379                return true;
380        }
381        if (key == "SkyBoxEnabled")
382        {
383                mSkyBoxEnabled = (*static_cast<const bool *>(val));
384                return true;
385        }
386        if (key == "SkyPlaneEnabled")
387        {
388                mSkyPlaneEnabled = (*static_cast<const bool *>(val));
389                return true;
390        }
391        if (key == "SkyDomeEnabled")
392        {
393                mSkyDomeEnabled = (*static_cast<const bool *>(val));
394                return true;
395        }
396        if (key == "VisualizeCulledNodes")
397        {
398                mVisualizeCulledNodes = (*static_cast<const bool *>(val));
399                return true;
400        }
401        if (key == "DelayRenderTransparents")
402        {
403                mDelayRenderTransparents = (*static_cast<const bool *>(val));
404                return true;
405        }
406
407        if (key == "DepthWrite")
408        {
409                mEnableDepthWrite = (*static_cast<const bool *>(val));
410                return true;
411        }
412        if (key == "UseItemBuffer")
413        {
414                mUseItemBuffer = (*static_cast<const bool *>(val));
415                return true;
416        }
417        if (key == "ExecuteVertexProgramForAllPasses")
418        {
419                mExecuteVertexProgramForAllPasses  = (*static_cast<const bool *>(val));
420                return true;
421        }
422        if (key == "RenderTransparentsForItemBuffer")
423        {
424                mRenderTransparentsForItemBuffer  = (*static_cast<const bool *>(val));
425                return true;
426        }
427
428        return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
429                setOption(key, val) || TerrainSceneManager::setOption(key, val);
430}
431//-----------------------------------------------------------------------
432bool VisibilityTerrainSceneManager::getOption(const String & key, void *val)
433{
434        if (key == "NumHierarchyNodes")
435        {
436                * static_cast<unsigned int *>(val) = (unsigned int)mNumOctreeNodes;
437                return true;
438        }
439       
440        return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
441                getOption(key, val) && TerrainSceneManager::getOption(key, val);
442}
443//-----------------------------------------------------------------------
444bool VisibilityTerrainSceneManager::getOptionValues(const String & key,
445                                                                                                        StringVector &refValueList)
446{
447        return TerrainSceneManager::getOptionValues( key, refValueList);
448}
449//-----------------------------------------------------------------------
450bool VisibilityTerrainSceneManager::getOptionKeys(StringVector & refKeys)
451{
452        return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
453                getOptionKeys(refKeys) || TerrainSceneManager::getOptionKeys(refKeys);
454}
455//-----------------------------------------------------------------------
456void VisibilityTerrainSceneManager::setVisibilityManager(GtpVisibility::
457                                                                                                                 VisibilityManager *visManager)
458{
459        mVisibilityManager = visManager;
460}
461//-----------------------------------------------------------------------
462GtpVisibility::VisibilityManager *VisibilityTerrainSceneManager::getVisibilityManager( void )
463{
464        return mVisibilityManager;
465}
466//-----------------------------------------------------------------------
467void VisibilityTerrainSceneManager::WriteLog()
468{
469        std::stringstream d;
470
471        d << "Depth pass: " << StringConverter::toString(mUseDepthPass) << ", "
472          << "Delay transparents: " << StringConverter::toString(mDelayRenderTransparents) << ", "
473          << "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetTestGeometryForVisibleLeaves()) << ", "
474          << "Algorithm type: " << mVisibilityManager->GetCullingManagerType() << ", "
475          << "Hierarchy nodes: " << mNumOctreeNodes << ", "
476          << "Traversed nodes: " << mHierarchyInterface->GetNumTraversedNodes() << ", "
477          << "Rendered nodes: " << mHierarchyInterface->GetNumRenderedNodes() << ", "
478          << "Query culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumQueryCulledNodes() << ", "
479          << "Frustum culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumFrustumCulledNodes() << ", "
480      << "Queries issued: " << mVisibilityManager->GetCullingManager()->GetNumQueriesIssued() << "\n";
481
482        LogManager::getSingleton().logMessage(d.str());
483}
484//-----------------------------------------------------------------------
485void VisibilityTerrainSceneManager::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 VisibilityTerrainSceneManager::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 VisibilityTerrainSceneManager::renderQueueGroupObjects(RenderQueueGroup* pGroup)
507{
508        if (!mRenderItemBuffer)
509        {
510                TerrainSceneManager::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 VisibilityTerrainSceneManager::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 VisibilityTerrainSceneManager::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 *VisibilityTerrainSceneManager::GetVisibilityManager()
628{
629        return mVisibilityManager;
630}
631//-----------------------------------------------------------------------
632void VisibilityTerrainSceneManager::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        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//-----------------------------------------------------------------------
746Entity* VisibilityTerrainSceneManager::createEntity(const String& entityName,
747                                                                                                        const String& meshName)
748{
749        Entity *ent = SceneManager::createEntity(entityName, meshName);
750
751        for (int i = 0; i < (int)ent->getNumSubEntities(); ++i)
752        {
753                ent->getSubEntity(i)->setId(mCurrentEntityId);
754        }
755
756        // increase counter of entity id values
757        ++ mCurrentEntityId;
758
759        return ent;
760}
761} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.