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

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

added trees

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