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

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

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

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