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

Revision 254, 25.0 KB checked in by mattausch, 19 years ago (diff)

added some hack for video recording

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