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