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

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

stable

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),
[187]33mRenderTransparentsForItemBuffer(true),
[202]34mExecuteVertexProgramForAllPasses(true),
35mIsHierarchicalCulling(false)
[59]36{
[120]37        mHierarchyInterface = new OctreeHierarchyInterface(this, mDestRenderSystem);
[139]38       
[187]39        //mDisplayNodes = true;
40        //mShowBoundingBoxes = true;
41        //mShowBoxes = true;
[103]42
43        // TODO: set maxdepth to reasonable value
[96]44        mMaxDepth = 50;
[59]45}
46//-----------------------------------------------------------------------
[119]47void VisibilityTerrainSceneManager::InitDepthPass()
[115]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);
[159]56
[115]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//-----------------------------------------------------------------------
[159]68VisibilityTerrainSceneManager::~VisibilityTerrainSceneManager()
69{
[192]70        OGRE_DELETE(mHierarchyInterface);
[159]71}
72//-----------------------------------------------------------------------
[122]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);
[150]88                //mItemBufferPass->setLightingEnabled(false);
[122]89        }
90        else
91        {
92                mItemBufferPass = itemBufferMat->getTechnique(0)->getPass(0);
93        }
[150]94        //mItemBufferPass->setAmbient(1, 1, 0);
[122]95}
96//-----------------------------------------------------------------------
[139]97void VisibilityTerrainSceneManager::PrepareVisualization(Camera *cam)
[115]98{
99        // add player camera for visualization purpose
[121]100        try
101        {
[115]102                Camera *c;
103                if ((c = getCamera("PlayerCam")) != NULL)
104                {
105                        getRenderQueue()->addRenderable(c);
106                }   
107    }
[121]108    catch (...)
[115]109    {
110        // ignore
111    }
[118]112        for (BoxList::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it)
113        {
114                getRenderQueue()->addRenderable(*it);
115        }
[115]116        if (mRenderNodesForViz || mRenderNodesContentForViz)
117        {
[164]118                // HACK: change node material so it is better suited for visualization
[118]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
[115]124                for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it)
125                {
126                        if (mRenderNodesForViz)
127                        {
[164]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                                }
[121]134
[115]135                                // addbounding boxes instead of node itself
[139]136                                //(*it)->_addBoundingBoxToQueue(getRenderQueue());
[115]137                        }
138                        if (mRenderNodesContentForViz)
139                        {
[122]140                                (*it)->_addToRenderQueue(cam, getRenderQueue(), false);
[115]141                        }
142                }
[121]143        }       
[103]144}
145//-----------------------------------------------------------------------
[120]146Pass *VisibilityTerrainSceneManager::setPass(Pass* pass)
147{
[139]148        // TODO: setting vertex program is not efficient
149        //Pass *usedPass = ((mRenderDepthPass && !pass->hasVertexProgram()) ? mDepthPass : pass);
[121]150       
[156]151        // set depth fill pass if we currently do not make an aabb occlusion query
[133]152        Pass *usedPass = (mRenderDepthPass && !mHierarchyInterface->IsBoundingBoxQuery() ?
153                                          mDepthPass : pass);
[121]154               
155        IlluminationRenderStage savedStage = mIlluminationStage;
[120]156       
[121]157        // set illumination stage to NONE so no shadow material is used
158        // for depth pass or for occlusion query
[122]159        if (mRenderDepthPass || mHierarchyInterface->IsBoundingBoxQuery())
[121]160        {
161                mIlluminationStage = IRS_NONE;
162        }
163       
[159]164        // --- set vertex program of current pass in order to set correct depth
165        if (mExecuteVertexProgramForAllPasses && mRenderDepthPass && pass->hasVertexProgram())
[120]166        {
[159]167                // add vertex program of current pass to depth pass
168                mDepthPass->setVertexProgram(pass->getVertexProgramName());
[120]169
[159]170                if (mDepthPass->hasVertexProgram())
[120]171                {
[159]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());
[120]178                }
179        }
[159]180        else if (mDepthPass->hasVertexProgram())
181        {
182                mDepthPass->setVertexProgram("");
183        }
184       
[133]185
186        bool IsDepthWrite = usedPass->getDepthWriteEnabled();
[139]187
[133]188        // global option which enables / disables depth writes
189        if (!mEnableDepthWrite)
190        {
191                usedPass->setDepthWriteEnabled(false);
192        }
[121]193        //else if (mIsItemBufferPass) {usedPass = mItemBufferPass;}
194       
195        Pass *result = SceneManager::setPass(usedPass);
[120]196
[133]197        // reset depth write
198        if (!mEnableDepthWrite)
199        {
200                usedPass->setDepthWriteEnabled(IsDepthWrite);
201        }
202
[121]203        // reset illumination stage
204        mIlluminationStage = savedStage;
205
206        return result;
[120]207}
208//-----------------------------------------------------------------------
[187]209void VisibilityTerrainSceneManager::_findVisibleObjects(Camera* cam,
210                                                                                                                bool onlyShadowCasters)
[103]211{
[115]212        //-- show visible scene nodes and octree bounding boxes from last frame
213        if (mShowVisualization)
214    {
[139]215                PrepareVisualization(cam);
[115]216        }
[155]217        else
[139]218        {       
[148]219                // for hierarchical culling, we interleave identification
[147]220                // and rendering of objects in _renderVisibibleObjects
[148]221
[155]222                // for the shadow pass we use only standard rendering
223                // because of low occlusion
[147]224                if (mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE &&
225                        mIlluminationStage == IRS_RENDER_TO_TEXTURE)
226                {
227                        TerrainSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
228                }
[139]229                // only shadow casters will be rendered in shadow texture pass
[155]230                // mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters);
[139]231        }
[122]232       
[159]233       
[156]234        // -- delete lists stored for visualization
[121]235        mVisible.clear();
236        mBoxes.clear();
[115]237}
238//-----------------------------------------------------------------------
239void VisibilityTerrainSceneManager::_renderVisibleObjects()
240{
[175]241        InitDepthPass();          // create material for depth pass
242        InitItemBufferPass(); // create material for item buffer pass
243
[155]244        // save ambient light to reset later
[150]245        ColourValue savedAmbient = mAmbientLight;
246
[159]247        //-- apply standard rendering for some modes (e.g., visualization, shadow pass)
[155]248
[158]249        if (mShowVisualization ||
[156]250           (mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE &&
251            mIlluminationStage == IRS_RENDER_TO_TEXTURE))
[87]252        {       
[139]253                IlluminationRenderStage savedStage = mIlluminationStage;
254       
[158]255                if (mShowVisualization)
256                        // disable illumination stage to prevent rendering shadows
[148]257                        mIlluminationStage = IRS_NONE;
258
259                // standard rendering for shadow maps because of performance
[101]260                TerrainSceneManager::_renderVisibleObjects();
[147]261
262                mIlluminationStage = savedStage;
[115]263        }
[159]264        else //-- the hierarchical culling algorithm
[147]265        {
[153]266                // don't render backgrounds for item buffer
267                if (mUseItemBuffer)
268                {
269                        clearSpecialCaseRenderQueues();
270                        getRenderQueue()->clear();
271                }
272
[159]273                //-- hierarchical culling
[139]274                // the objects of different layers (e.g., background, scene,
275                // overlay) must be identified and rendered one after another
[115]276
[139]277                //-- render all early skies
278                clearSpecialCaseRenderQueues();
279                addSpecialCaseRenderQueue(RENDER_QUEUE_BACKGROUND);
280                addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_EARLY);
281                setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE);
[122]282
[139]283                TerrainSceneManager::_renderVisibleObjects();
[153]284               
[87]285
[59]286#ifdef GTP_VISIBILITY_MODIFIED_OGRE
[159]287                // delete previously rendered content
[139]288                _deleteRenderedQueueGroups();
[59]289#endif
290
[139]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);
[59]296
[100]297
[153]298                // set all necessary parameters for
299                // hierarchical visibility culling and rendering
[139]300                InitVisibilityCulling(mCameraInProgress);
[59]301
[139]302                /**
303                * the hierarchical culling algorithm
[159]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
[139]307                **/
308               
309                mVisibilityManager->ApplyVisibilityCulling();
310
311                // delete remaining renderables from queue (all not in mLeavePassesInQueue)
[135]312#ifdef GTP_VISIBILITY_MODIFIED_OGRE
[139]313                _deleteRenderedQueueGroups(mLeavePassesInQueue);
[135]314#endif
[100]315
[139]316                //-- reset parameters
317                mRenderDepthPass = false;
[153]318                mRenderItemBuffer = false;
[139]319                mSkipTransparents = false;
320                mLeavePassesInQueue = 0;
[153]321               
[139]322
323                // add visible nodes found by the visibility culling algorithm
324                if (mUseDepthPass)
[115]325                {
[139]326                        for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it)
327                        {
328                                (*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false);
329                        }
[122]330                }
[139]331               
332                //-- now we can render all remaining queue objects
[159]333                // used for depth pass, transparents, overlay
[139]334                clearSpecialCaseRenderQueues();
335                TerrainSceneManager::_renderVisibleObjects();
[115]336        }
[139]337               
[159]338        // set the new render level index
339        TerrainRenderable::NextRenderLevelIndex();
340       
[150]341        // reset ambient light
342        setAmbientLight(savedAmbient);
[153]343
[159]344        getRenderQueue()->clear(); // finally clear render queue
[187]345        OGRE_DELETE(mRenderQueue); // HACK: should be cleared before...
[99]346        //WriteLog(); // write out stats
[59]347}
[122]348
[59]349//-----------------------------------------------------------------------
350void VisibilityTerrainSceneManager::_updateSceneGraph(Camera* cam)
351{
352        mVisibilityManager->GetCullingManager()->SetHierarchyInterface(mHierarchyInterface);
353        mHierarchyInterface->SetRenderSystem(mDestRenderSystem);
[74]354
[59]355        TerrainSceneManager::_updateSceneGraph(cam);
356}
357//-----------------------------------------------------------------------
358bool VisibilityTerrainSceneManager::setOption(const String & key, const void * val)
359{
[115]360        if (key == "UseDepthPass")
[87]361        {
[115]362                mUseDepthPass = (*static_cast<const bool *>(val));
[87]363                return true;
364        }
[139]365        if (key == "PrepareVisualization")
[99]366        {
367                mShowVisualization = (*static_cast<const bool *>(val));
368                return true;
369        }
[103]370        if (key == "RenderNodesForViz")
371        {
372                mRenderNodesForViz = (*static_cast<const bool *>(val));
373                return true;
374        }
[113]375        if (key == "RenderNodesContentForViz")
376        {
377                mRenderNodesContentForViz = (*static_cast<const bool *>(val));
378                return true;
379        }
[100]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        }
[112]395        if (key == "VisualizeCulledNodes")
396        {
397                mVisualizeCulledNodes = (*static_cast<const bool *>(val));
398                return true;
399        }
[115]400        if (key == "DelayRenderTransparents")
401        {
402                mDelayRenderTransparents = (*static_cast<const bool *>(val));
403                return true;
404        }
[159]405
[134]406        if (key == "DepthWrite")
[133]407        {
408                mEnableDepthWrite = (*static_cast<const bool *>(val));
409                return true;
410        }
[153]411        if (key == "UseItemBuffer")
[150]412        {
[153]413                mUseItemBuffer = (*static_cast<const bool *>(val));
[150]414                return true;
415        }
[159]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        }
[187]426        if (key == "NodeVizScale")
427        {
428                OctreeNode::setVizScale(*static_cast<const float *>(val));
429                return true;
430        }
[159]431
[74]432        return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
433                setOption(key, val) || TerrainSceneManager::setOption(key, val);
[59]434}
435//-----------------------------------------------------------------------
436bool VisibilityTerrainSceneManager::getOption(const String & key, void *val)
437{
[74]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);
[59]446}
447//-----------------------------------------------------------------------
[153]448bool VisibilityTerrainSceneManager::getOptionValues(const String & key,
449                                                                                                        StringVector &refValueList)
[59]450{
[74]451        return TerrainSceneManager::getOptionValues( key, refValueList);
[59]452}
453//-----------------------------------------------------------------------
454bool VisibilityTerrainSceneManager::getOptionKeys(StringVector & refKeys)
455{
[74]456        return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
457                getOptionKeys(refKeys) || TerrainSceneManager::getOptionKeys(refKeys);
[59]458}
459//-----------------------------------------------------------------------
[153]460void VisibilityTerrainSceneManager::setVisibilityManager(GtpVisibility::
461                                                                                                                 VisibilityManager *visManager)
[59]462{
463        mVisibilityManager = visManager;
464}
465//-----------------------------------------------------------------------
466GtpVisibility::VisibilityManager *VisibilityTerrainSceneManager::getVisibilityManager( void )
467{
468        return mVisibilityManager;
469}
[93]470//-----------------------------------------------------------------------
471void VisibilityTerrainSceneManager::WriteLog()
472{
473        std::stringstream d;
474
[120]475        d << "Depth pass: " << StringConverter::toString(mUseDepthPass) << ", "
476          << "Delay transparents: " << StringConverter::toString(mDelayRenderTransparents) << ", "
[155]477          << "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetTestGeometryForVisibleLeaves()) << ", "
[120]478          << "Algorithm type: " << mVisibilityManager->GetCullingManagerType() << ", "
[101]479          << "Hierarchy nodes: " << mNumOctreeNodes << ", "
480          << "Traversed nodes: " << mHierarchyInterface->GetNumTraversedNodes() << ", "
[93]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}
[114]488//-----------------------------------------------------------------------
[139]489void VisibilityTerrainSceneManager::renderObjects(
490        const RenderPriorityGroup::TransparentRenderablePassList& objs,
491    bool doLightIteration, const LightList* manualLightList)
[114]492{
[121]493        // for correct rendering, transparents must be rendered after hierarchical culling
[115]494        if (!mSkipTransparents)
[114]495        {
496                OctreeSceneManager::renderObjects(objs, doLightIteration, manualLightList);
497        }
498}
[121]499//-----------------------------------------------------------------------
500bool VisibilityTerrainSceneManager::validatePassForRendering(Pass* pass)
501{
502        // skip all but first pass if we are doing the depth pass
[122]503        if ((mRenderDepthPass || mRenderItemBuffer) && pass->getIndex() > 0)
[121]504        {
505                return false;
506        }
507        return SceneManager::validatePassForRendering(pass);
508}
[122]509//-----------------------------------------------------------------------
510void VisibilityTerrainSceneManager::renderQueueGroupObjects(RenderQueueGroup* pGroup)
511{
512        if (!mRenderItemBuffer)
513        {
514                TerrainSceneManager::renderQueueGroupObjects(pGroup);
515                return;
516        }
[103]517
[164]518        //-- item buffer
[156]519
[122]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                {
[129]555                        std::stringstream d; d << "itembuffer, pass name: " <<
556                                ipass->first->getParent()->getParent()->getName();
[139]557                               
[129]558                        LogManager::getSingleton().logMessage(d.str());
559                       
[139]560                        RenderSingleObjectForItemBuffer(*irend, ipass->first);
[122]561                }
562        }
563
[159]564        // -- TRANSPARENT LOOP: must be handled differently
[122]565
[159]566        // transparents are treated either as solids or completely discarded
567        if (mRenderTransparentsForItemBuffer)
[122]568        {
[159]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                        }
[122]582                }
[159]583        }
[122]584}
585//-----------------------------------------------------------------------
[129]586void VisibilityTerrainSceneManager::RenderSingleObjectForItemBuffer(Renderable *rend, Pass *pass)
[122]587{
588        static LightList nullLightList;
[150]589       
590        int col[4];
591       
[154]592        // -- create color code out of object id
[150]593        col[0] = (rend->getId() >> 16) & 255;
594        col[1] = (rend->getId() >> 8) & 255;
595        col[2] = rend->getId() & 255;
[157]596//      col[3] = 255;
[129]597
[150]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));
[122]603
[129]604        // set vertex program of current pass
[159]605        if (mExecuteVertexProgramForAllPasses && pass->hasVertexProgram())
[129]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
[156]626
[122]627        // Render a single object, this will set up auto params if required
[129]628        renderSingleObject(rend, usedPass, false, &nullLightList);
[122]629}
630//-----------------------------------------------------------------------
[130]631GtpVisibility::VisibilityManager *VisibilityTerrainSceneManager::GetVisibilityManager()
[122]632{
[130]633        return mVisibilityManager;
634}
635//-----------------------------------------------------------------------
[139]636void VisibilityTerrainSceneManager::InitVisibilityCulling(Camera *cam)
637{
[153]638        // reset culling manager stats
639        mVisibilityManager->GetCullingManager()->InitFrame(mVisualizeCulledNodes);
640
641        // set depth pass flag before rendering
642        mRenderDepthPass = mUseDepthPass;
643
[150]644        // item buffer needs full ambient lighting to use item colors as unique id
645        if (mUseItemBuffer)
646        {
647                mRenderItemBuffer = true;
648                setAmbientLight(ColourValue(1,1,1,1));
649        }
650
651
[159]652        // set passes which are stored in render queue
[153]653        // for rendering AFTER hierarchical culling, i.e., passes which need
654        // a special rendering order
655        mLeavePassesInQueue = 0;
[150]656
[202]657        if (!mUseDepthPass && !mUseItemBuffer)
[139]658        {
[202]659                if (mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE)
[139]660                {
[153]661                        // TODO: remove this pass because it should be processed during hierarchical culling
[202]662                        //mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW;
[139]663
664                        mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_DECAL;
665                        mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_DIFFUSE_SPECULAR;
666                        mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
[153]667
668                        // just render ambient stuff
669                        mIlluminationStage = IRS_AMBIENT;
[139]670                }
[153]671       
[202]672                if (mShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE)
[139]673                {
674                        mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW;
675                        mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
676                }
[141]677       
[153]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                }
[139]684        }
685
[153]686        // skip rendering transparents in the hierarchical culling
687        // (because they will be rendered afterwards)
688        mSkipTransparents = mUseDepthPass ||
689                (mLeavePassesInQueue & RenderPriorityGroup::TRANSPARENT_PASSES);
690
[155]691        // -- initialise interface for rendering traversal of the hierarchy
692        mHierarchyInterface->SetHierarchyRoot(mOctree);
693       
[139]694        // possible two cameras (one for culling, one for rendering)
[155]695        mHierarchyInterface->InitTraversal(mCameraInProgress,
696                                                        mCullCamera ? getCamera("CullCamera") : NULL,
697                                                        mLeavePassesInQueue);
[139]698               
[153]699        //std::stringstream d; d << "leave passes in queue: " << mLeavePassesInQueue;LogManager::getSingleton().logMessage(d.str());
[139]700}
701//-----------------------------------------------------------------------
[153]702OctreeHierarchyInterface *VisibilityTerrainSceneManager::GetHierarchyInterface()
703{
704        return mHierarchyInterface;
705}
706//-----------------------------------------------------------------------
[159]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}
[202]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}
[59]783} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.