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