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

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

added animation

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