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

Revision 259, 25.1 KB checked in by mattausch, 19 years ago (diff)

refined measurements

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),
[254]26mIsDepthPassPhase(false),
[154]27mUseItemBuffer(false),
28//mUseItemBuffer(true),
[254]29mIsItemBufferPhase(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
[254]149        //Pass *usedPass = ((mIsDepthPassPhase && !pass->hasVertexProgram()) ? mDepthPass : pass);
[121]150       
[156]151        // set depth fill pass if we currently do not make an aabb occlusion query
[254]152        Pass *usedPass = (mIsDepthPassPhase && !mHierarchyInterface->IsBoundingBoxQuery() ?
[133]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
[254]159        if (mIsDepthPassPhase || mHierarchyInterface->IsBoundingBoxQuery())
[121]160        {
161                mIlluminationStage = IRS_NONE;
162        }
163       
[159]164        // --- set vertex program of current pass in order to set correct depth
[254]165        if (mExecuteVertexProgramForAllPasses && mIsDepthPassPhase && 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{
[259]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();
[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);
[259]295       
296                // exclude this queues from hierarchical rendering
[139]297                setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
[59]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
[254]318                mIsDepthPassPhase = false;
319                mIsItemBufferPhase = false;
[139]320                mSkipTransparents = false;
321                mLeavePassesInQueue = 0;
[153]322               
[139]323
324                // add visible nodes found by the visibility culling algorithm
325                if (mUseDepthPass)
[115]326                {
[139]327                        for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it)
328                        {
329                                (*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false);
330                        }
[122]331                }
[139]332               
333                //-- now we can render all remaining queue objects
[159]334                // used for depth pass, transparents, overlay
[139]335                clearSpecialCaseRenderQueues();
[259]336
[139]337                TerrainSceneManager::_renderVisibleObjects();
[115]338        }
[139]339               
[259]340        // HACK: set the new render level index, important to avoid cracks
341        // in terrain caused by LOD
[159]342        TerrainRenderable::NextRenderLevelIndex();
343       
[150]344        // reset ambient light
345        setAmbientLight(savedAmbient);
[153]346
[159]347        getRenderQueue()->clear(); // finally clear render queue
[187]348        OGRE_DELETE(mRenderQueue); // HACK: should be cleared before...
[99]349        //WriteLog(); // write out stats
[259]350
[59]351}
[122]352
[59]353//-----------------------------------------------------------------------
354void VisibilityTerrainSceneManager::_updateSceneGraph(Camera* cam)
355{
356        mVisibilityManager->GetCullingManager()->SetHierarchyInterface(mHierarchyInterface);
357        mHierarchyInterface->SetRenderSystem(mDestRenderSystem);
[74]358
[59]359        TerrainSceneManager::_updateSceneGraph(cam);
360}
361//-----------------------------------------------------------------------
362bool VisibilityTerrainSceneManager::setOption(const String & key, const void * val)
363{
[115]364        if (key == "UseDepthPass")
[87]365        {
[115]366                mUseDepthPass = (*static_cast<const bool *>(val));
[87]367                return true;
368        }
[139]369        if (key == "PrepareVisualization")
[99]370        {
371                mShowVisualization = (*static_cast<const bool *>(val));
372                return true;
373        }
[103]374        if (key == "RenderNodesForViz")
375        {
376                mRenderNodesForViz = (*static_cast<const bool *>(val));
377                return true;
378        }
[113]379        if (key == "RenderNodesContentForViz")
380        {
381                mRenderNodesContentForViz = (*static_cast<const bool *>(val));
382                return true;
383        }
[100]384        if (key == "SkyBoxEnabled")
385        {
386                mSkyBoxEnabled = (*static_cast<const bool *>(val));
387                return true;
388        }
389        if (key == "SkyPlaneEnabled")
390        {
391                mSkyPlaneEnabled = (*static_cast<const bool *>(val));
392                return true;
393        }
394        if (key == "SkyDomeEnabled")
395        {
396                mSkyDomeEnabled = (*static_cast<const bool *>(val));
397                return true;
398        }
[112]399        if (key == "VisualizeCulledNodes")
400        {
401                mVisualizeCulledNodes = (*static_cast<const bool *>(val));
402                return true;
403        }
[115]404        if (key == "DelayRenderTransparents")
405        {
406                mDelayRenderTransparents = (*static_cast<const bool *>(val));
407                return true;
408        }
[159]409
[134]410        if (key == "DepthWrite")
[133]411        {
412                mEnableDepthWrite = (*static_cast<const bool *>(val));
413                return true;
414        }
[153]415        if (key == "UseItemBuffer")
[150]416        {
[153]417                mUseItemBuffer = (*static_cast<const bool *>(val));
[150]418                return true;
419        }
[159]420        if (key == "ExecuteVertexProgramForAllPasses")
421        {
422                mExecuteVertexProgramForAllPasses  = (*static_cast<const bool *>(val));
423                return true;
424        }
425        if (key == "RenderTransparentsForItemBuffer")
426        {
427                mRenderTransparentsForItemBuffer  = (*static_cast<const bool *>(val));
428                return true;
429        }
[187]430        if (key == "NodeVizScale")
431        {
432                OctreeNode::setVizScale(*static_cast<const float *>(val));
433                return true;
434        }
[159]435
[74]436        return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
437                setOption(key, val) || TerrainSceneManager::setOption(key, val);
[59]438}
439//-----------------------------------------------------------------------
440bool VisibilityTerrainSceneManager::getOption(const String & key, void *val)
441{
[74]442        if (key == "NumHierarchyNodes")
443        {
[259]444                * static_cast<unsigned int *>(val) = (unsigned int)mNumOctants;
[74]445                return true;
446        }
447       
448        return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
449                getOption(key, val) && TerrainSceneManager::getOption(key, val);
[59]450}
451//-----------------------------------------------------------------------
[153]452bool VisibilityTerrainSceneManager::getOptionValues(const String & key,
453                                                                                                        StringVector &refValueList)
[59]454{
[74]455        return TerrainSceneManager::getOptionValues( key, refValueList);
[59]456}
457//-----------------------------------------------------------------------
458bool VisibilityTerrainSceneManager::getOptionKeys(StringVector & refKeys)
459{
[74]460        return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
461                getOptionKeys(refKeys) || TerrainSceneManager::getOptionKeys(refKeys);
[59]462}
463//-----------------------------------------------------------------------
[153]464void VisibilityTerrainSceneManager::setVisibilityManager(GtpVisibility::
465                                                                                                                 VisibilityManager *visManager)
[59]466{
467        mVisibilityManager = visManager;
468}
469//-----------------------------------------------------------------------
470GtpVisibility::VisibilityManager *VisibilityTerrainSceneManager::getVisibilityManager( void )
471{
472        return mVisibilityManager;
473}
[93]474//-----------------------------------------------------------------------
475void VisibilityTerrainSceneManager::WriteLog()
476{
477        std::stringstream d;
478
[120]479        d << "Depth pass: " << StringConverter::toString(mUseDepthPass) << ", "
480          << "Delay transparents: " << StringConverter::toString(mDelayRenderTransparents) << ", "
[155]481          << "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetTestGeometryForVisibleLeaves()) << ", "
[120]482          << "Algorithm type: " << mVisibilityManager->GetCullingManagerType() << ", "
[259]483          << "Hierarchy nodes: " << mNumOctants << ", "
[101]484          << "Traversed nodes: " << mHierarchyInterface->GetNumTraversedNodes() << ", "
[93]485          << "Rendered nodes: " << mHierarchyInterface->GetNumRenderedNodes() << ", "
486          << "Query culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumQueryCulledNodes() << ", "
487          << "Frustum culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumFrustumCulledNodes() << ", "
488      << "Queries issued: " << mVisibilityManager->GetCullingManager()->GetNumQueriesIssued() << "\n";
489
490        LogManager::getSingleton().logMessage(d.str());
491}
[114]492//-----------------------------------------------------------------------
[139]493void VisibilityTerrainSceneManager::renderObjects(
494        const RenderPriorityGroup::TransparentRenderablePassList& objs,
495    bool doLightIteration, const LightList* manualLightList)
[114]496{
[121]497        // for correct rendering, transparents must be rendered after hierarchical culling
[115]498        if (!mSkipTransparents)
[114]499        {
500                OctreeSceneManager::renderObjects(objs, doLightIteration, manualLightList);
501        }
502}
[121]503//-----------------------------------------------------------------------
504bool VisibilityTerrainSceneManager::validatePassForRendering(Pass* pass)
505{
506        // skip all but first pass if we are doing the depth pass
[254]507        if ((mIsDepthPassPhase || mIsItemBufferPhase) && pass->getIndex() > 0)
[121]508        {
509                return false;
510        }
511        return SceneManager::validatePassForRendering(pass);
512}
[122]513//-----------------------------------------------------------------------
514void VisibilityTerrainSceneManager::renderQueueGroupObjects(RenderQueueGroup* pGroup)
515{
[254]516        if (!mIsItemBufferPhase)
[122]517        {
518                TerrainSceneManager::renderQueueGroupObjects(pGroup);
519                return;
520        }
[103]521
[164]522        //-- item buffer
[156]523
[122]524    // Iterate through priorities
525    RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
526
527        while (groupIt.hasMoreElements())
528    {
529                RenderItemBuffer(groupIt.getNext());
530        }
531}
532//-----------------------------------------------------------------------
533void VisibilityTerrainSceneManager::RenderItemBuffer(RenderPriorityGroup* pGroup)
534{
535        // Do solids
536        RenderPriorityGroup::SolidRenderablePassMap solidObjs = pGroup->_getSolidPasses();
537
538        // ----- SOLIDS LOOP -----
539        RenderPriorityGroup::SolidRenderablePassMap::const_iterator ipass, ipassend;
540        ipassend = solidObjs.end();
541
542        for (ipass = solidObjs.begin(); ipass != ipassend; ++ipass)
543        {
544                // Fast bypass if this group is now empty
545                if (ipass->second->empty())
546                        continue;
547
548                // Render only first pass
549                if (ipass->first->getIndex() > 0)
550                        continue;
551
552                RenderPriorityGroup::RenderableList* rendList = ipass->second;
553               
554                RenderPriorityGroup::RenderableList::const_iterator irend, irendend;
555                irendend = rendList->end();
556                       
557                for (irend = rendList->begin(); irend != irendend; ++irend)
558                {
[129]559                        std::stringstream d; d << "itembuffer, pass name: " <<
560                                ipass->first->getParent()->getParent()->getName();
[139]561                               
[129]562                        LogManager::getSingleton().logMessage(d.str());
563                       
[139]564                        RenderSingleObjectForItemBuffer(*irend, ipass->first);
[122]565                }
566        }
567
[159]568        // -- TRANSPARENT LOOP: must be handled differently
[122]569
[159]570        // transparents are treated either as solids or completely discarded
571        if (mRenderTransparentsForItemBuffer)
[122]572        {
[159]573                RenderPriorityGroup::TransparentRenderablePassList transpObjs =
574                        pGroup->_getTransparentPasses();
575                RenderPriorityGroup::TransparentRenderablePassList::const_iterator
576                        itrans, itransend;
577
578                itransend = transpObjs.end();
579                for (itrans = transpObjs.begin(); itrans != itransend; ++itrans)
580                {
581                        // like for solids, render only first pass
582                        if (itrans->pass->getIndex() == 0)
583                        {       
584                                RenderSingleObjectForItemBuffer(itrans->renderable, itrans->pass);
585                        }
[122]586                }
[159]587        }
[122]588}
589//-----------------------------------------------------------------------
[129]590void VisibilityTerrainSceneManager::RenderSingleObjectForItemBuffer(Renderable *rend, Pass *pass)
[122]591{
592        static LightList nullLightList;
[150]593       
594        int col[4];
595       
[154]596        // -- create color code out of object id
[150]597        col[0] = (rend->getId() >> 16) & 255;
598        col[1] = (rend->getId() >> 8) & 255;
599        col[2] = rend->getId() & 255;
[157]600//      col[3] = 255;
[129]601
[150]602        //mDestRenderSystem->setColour(col[0], col[1], col[2], col[3]);
603   
604        mItemBufferPass->setAmbient(ColourValue(col[0] / 255.0f,
605                                                                                    col[1] / 255.0f,
606                                                                                        col[2] / 255.0f, 1));
[122]607
[129]608        // set vertex program of current pass
[159]609        if (mExecuteVertexProgramForAllPasses && pass->hasVertexProgram())
[129]610        {
611                mItemBufferPass->setVertexProgram(pass->getVertexProgramName());
612
613                if (mItemBufferPass->hasVertexProgram())
614                {
615                        const GpuProgramPtr& prg = mItemBufferPass->getVertexProgram();
616                        // Load this program if not done already
617                        if (!prg->isLoaded())
618                                prg->load();
619                        // Copy params
620                        mItemBufferPass->setVertexProgramParameters(pass->getVertexProgramParameters());
621                }
622        }
623        else if (mItemBufferPass->hasVertexProgram())
624        {
625                mItemBufferPass->setVertexProgram("");
626        }
627
628        Pass *usedPass = setPass(mItemBufferPass);
629
[156]630
[122]631        // Render a single object, this will set up auto params if required
[129]632        renderSingleObject(rend, usedPass, false, &nullLightList);
[122]633}
634//-----------------------------------------------------------------------
[130]635GtpVisibility::VisibilityManager *VisibilityTerrainSceneManager::GetVisibilityManager()
[122]636{
[130]637        return mVisibilityManager;
638}
639//-----------------------------------------------------------------------
[139]640void VisibilityTerrainSceneManager::InitVisibilityCulling(Camera *cam)
641{
[153]642        // reset culling manager stats
643        mVisibilityManager->GetCullingManager()->InitFrame(mVisualizeCulledNodes);
644
645        // set depth pass flag before rendering
[254]646        mIsDepthPassPhase = mUseDepthPass;
[153]647
[150]648        // item buffer needs full ambient lighting to use item colors as unique id
649        if (mUseItemBuffer)
650        {
[254]651                mIsItemBufferPhase = true;
[150]652                setAmbientLight(ColourValue(1,1,1,1));
653        }
654
655
[159]656        // set passes which are stored in render queue
[153]657        // for rendering AFTER hierarchical culling, i.e., passes which need
658        // a special rendering order
659        mLeavePassesInQueue = 0;
[150]660
[202]661        if (!mUseDepthPass && !mUseItemBuffer)
[139]662        {
[202]663                if (mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE)
[139]664                {
[153]665                        // TODO: remove this pass because it should be processed during hierarchical culling
[202]666                        //mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW;
[139]667
668                        mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_DECAL;
669                        mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_DIFFUSE_SPECULAR;
670                        mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
[153]671
672                        // just render ambient stuff
673                        mIlluminationStage = IRS_AMBIENT;
[139]674                }
[153]675       
[202]676                if (mShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE)
[139]677                {
678                        mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW;
679                        mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
680                }
[141]681       
[153]682                // transparents should be rendered after hierarchical culling to
683                // provide front-to-back ordering
684                if (mDelayRenderTransparents)
685                {
686                        mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
687                }
[139]688        }
689
[153]690        // skip rendering transparents in the hierarchical culling
691        // (because they will be rendered afterwards)
692        mSkipTransparents = mUseDepthPass ||
693                (mLeavePassesInQueue & RenderPriorityGroup::TRANSPARENT_PASSES);
694
[155]695        // -- initialise interface for rendering traversal of the hierarchy
696        mHierarchyInterface->SetHierarchyRoot(mOctree);
697       
[139]698        // possible two cameras (one for culling, one for rendering)
[155]699        mHierarchyInterface->InitTraversal(mCameraInProgress,
700                                                        mCullCamera ? getCamera("CullCamera") : NULL,
701                                                        mLeavePassesInQueue);
[139]702               
[153]703        //std::stringstream d; d << "leave passes in queue: " << mLeavePassesInQueue;LogManager::getSingleton().logMessage(d.str());
[139]704}
705//-----------------------------------------------------------------------
[153]706OctreeHierarchyInterface *VisibilityTerrainSceneManager::GetHierarchyInterface()
707{
708        return mHierarchyInterface;
709}
710//-----------------------------------------------------------------------
[159]711void VisibilityTerrainSceneManager::endFrame()
712{
713        TerrainRenderable::ResetRenderLevelIndex();
714}
715//-----------------------------------------------------------------------
716Entity* VisibilityTerrainSceneManager::createEntity(const String& entityName,
717                                                                                                        const String& meshName)
718{
719        Entity *ent = SceneManager::createEntity(entityName, meshName);
720
721        for (int i = 0; i < (int)ent->getNumSubEntities(); ++i)
722        {
723                ent->getSubEntity(i)->setId(mCurrentEntityId);
724        }
725
726        // increase counter of entity id values
727        ++ mCurrentEntityId;
728
729        return ent;
730}
[202]731//-----------------------------------------------------------------------
732void VisibilityTerrainSceneManager::renderAdditiveStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup)
733{
734        // only render solid passes during hierarchical culling
735        if (mIsHierarchicalCulling)
736        {
737                RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
738            LightList lightList;
739
740                while (groupIt.hasMoreElements())
741                {
742                        RenderPriorityGroup* pPriorityGrp = groupIt.getNext();
743
744                        // Sort the queue first
745                        pPriorityGrp->sort(mCameraInProgress);
746
747                        // Clear light list
748                        lightList.clear();
749
750                        // Render all the ambient passes first, no light iteration, no lights
751                        mIlluminationStage = IRS_AMBIENT;
752
753                        OctreeSceneManager::renderObjects(pPriorityGrp->_getSolidPasses(), false, &lightList);
754                        // Also render any objects which have receive shadows disabled
755                        OctreeSceneManager::renderObjects(pPriorityGrp->_getSolidPassesNoShadow(), true);
756                }
757        }
758        else
759        {
760                OctreeSceneManager::renderAdditiveStencilShadowedQueueGroupObjects(pGroup);
761        }
762}
763//-----------------------------------------------------------------------
764void VisibilityTerrainSceneManager::renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup)
765{
766   if (mIsHierarchicalCulling)
767   {
768           // Iterate through priorities
769           RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
770
771           while (groupIt.hasMoreElements())
772           {
773                   RenderPriorityGroup* pPriorityGrp = groupIt.getNext();
774
775                   // Sort the queue first
776                   pPriorityGrp->sort(mCameraInProgress);
777
778                   // Do (shadowable) solids
779                   OctreeSceneManager::renderObjects(pPriorityGrp->_getSolidPasses(), true);
780           }
781   }
782   else
783   {
784           SceneManager::renderModulativeStencilShadowedQueueGroupObjects(pGroup);
785   }
786}
[59]787} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.