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