[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>
|
---|
[59] | 11 |
|
---|
[118] | 12 |
|
---|
[59] | 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),
|
---|
[159] | 26 | mUseDepthPass(false),
|
---|
| 27 | mRenderDepthPass(false),
|
---|
| 28 | mUseItemBuffer(false),
|
---|
| 29 | //mUseItemBuffer(true),
|
---|
| 30 | mRenderItemBuffer(false),
|
---|
| 31 | mCurrentEntityId(1),
|
---|
| 32 | mEnableDepthWrite(true),
|
---|
| 33 | mSkipTransparents(false),
|
---|
| 34 | mSavedShadowTechnique(SHADOWTYPE_NONE),
|
---|
| 35 | mRenderTransparentsForItemBuffer(false),
|
---|
| 36 | mExecuteVertexProgramForAllPasses(false)
|
---|
[59] | 37 | {
|
---|
[120] | 38 | mHierarchyInterface = new OctreeHierarchyInterface(this, mDestRenderSystem);
|
---|
[94] | 39 |
|
---|
[59] | 40 | //mDisplayNodes = true;
|
---|
[86] | 41 | //mShowBoundingBoxes = true;
|
---|
| 42 | //mShowBoxes = true;
|
---|
[87] | 43 |
|
---|
[159] | 44 | // TODO: set maxdepth to reasonable value
|
---|
[96] | 45 | mMaxDepth = 50;
|
---|
[59] | 46 | }
|
---|
| 47 | //-----------------------------------------------------------------------
|
---|
[119] | 48 | void VisibilityOctreeSceneManager::InitDepthPass()
|
---|
[115] | 49 | {
|
---|
| 50 | MaterialPtr depthMat = MaterialManager::getSingleton().getByName("Visibility/DepthPass");
|
---|
| 51 |
|
---|
| 52 | if (depthMat.isNull())
|
---|
| 53 | {
|
---|
| 54 | depthMat = MaterialManager::getSingleton().create(
|
---|
| 55 | "Visibility/DepthPass",
|
---|
| 56 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
| 57 |
|
---|
[118] | 58 | mDepthPass = depthMat->getTechnique(0)->getPass(0);
|
---|
[115] | 59 | mDepthPass->setColourWriteEnabled(false);
|
---|
| 60 | mDepthPass->setDepthWriteEnabled(true);
|
---|
| 61 | mDepthPass->setLightingEnabled(false);
|
---|
| 62 | }
|
---|
| 63 | else
|
---|
| 64 | {
|
---|
| 65 | mDepthPass = depthMat->getTechnique(0)->getPass(0);
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 | //-----------------------------------------------------------------------
|
---|
[59] | 69 | VisibilityOctreeSceneManager::~VisibilityOctreeSceneManager()
|
---|
| 70 | {
|
---|
[120] | 71 | if (mHierarchyInterface)
|
---|
| 72 | {
|
---|
| 73 | delete mHierarchyInterface;
|
---|
| 74 | mHierarchyInterface = NULL;
|
---|
| 75 | }
|
---|
[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
|
---|
| 151 | Pass *usedPass = (mRenderDepthPass && !mHierarchyInterface->IsBoundingBoxQuery() ?
|
---|
| 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
|
---|
| 158 | if (mRenderDepthPass || mHierarchyInterface->IsBoundingBoxQuery())
|
---|
| 159 | {
|
---|
| 160 | mIlluminationStage = IRS_NONE;
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | //-- set vertex program of current pass in order to set correct depth
|
---|
| 164 | if (mRenderDepthPass && mExecuteVertexProgramForAllPasses && pass->hasVertexProgram())
|
---|
| 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
|
---|
| 317 | mRenderDepthPass = false;
|
---|
| 318 | mRenderItemBuffer = false;
|
---|
| 319 | mSkipTransparents = false;
|
---|
| 320 | mLeavePassesInQueue = 0;
|
---|
| 321 | mShadowTechnique = mSavedShadowTechnique;
|
---|
[92] | 322 |
|
---|
[159] | 323 |
|
---|
| 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
|
---|
| 344 | //WriteLog(); // write out stats
|
---|
[59] | 345 | }
|
---|
[159] | 346 |
|
---|
[59] | 347 | //-----------------------------------------------------------------------
|
---|
| 348 | void VisibilityOctreeSceneManager::_updateSceneGraph(Camera* cam)
|
---|
| 349 | {
|
---|
| 350 | mVisibilityManager->GetCullingManager()->SetHierarchyInterface(mHierarchyInterface);
|
---|
| 351 | mHierarchyInterface->SetRenderSystem(mDestRenderSystem);
|
---|
| 352 |
|
---|
| 353 | OctreeSceneManager::_updateSceneGraph(cam);
|
---|
| 354 | }
|
---|
| 355 | //-----------------------------------------------------------------------
|
---|
| 356 | bool VisibilityOctreeSceneManager::setOption(const String & key, const void * val)
|
---|
| 357 | {
|
---|
[115] | 358 | if (key == "UseDepthPass")
|
---|
[87] | 359 | {
|
---|
[115] | 360 | mUseDepthPass = (*static_cast<const bool *>(val));
|
---|
[87] | 361 | return true;
|
---|
| 362 | }
|
---|
[139] | 363 | if (key == "PrepareVisualization")
|
---|
[100] | 364 | {
|
---|
| 365 | mShowVisualization = (*static_cast<const bool *>(val));
|
---|
| 366 | return true;
|
---|
| 367 | }
|
---|
[112] | 368 | if (key == "RenderNodesForViz")
|
---|
| 369 | {
|
---|
[114] | 370 | mRenderNodesForViz = (*static_cast<const bool *>(val));
|
---|
[112] | 371 | return true;
|
---|
| 372 | }
|
---|
[118] | 373 | if (key == "RenderNodesContentForViz")
|
---|
| 374 | {
|
---|
| 375 | mRenderNodesContentForViz = (*static_cast<const bool *>(val));
|
---|
| 376 | return true;
|
---|
| 377 | }
|
---|
[112] | 378 | if (key == "SkyBoxEnabled")
|
---|
| 379 | {
|
---|
| 380 | mSkyBoxEnabled = (*static_cast<const bool *>(val));
|
---|
| 381 | return true;
|
---|
| 382 | }
|
---|
| 383 | if (key == "SkyPlaneEnabled")
|
---|
| 384 | {
|
---|
| 385 | mSkyPlaneEnabled = (*static_cast<const bool *>(val));
|
---|
| 386 | return true;
|
---|
| 387 | }
|
---|
| 388 | if (key == "SkyDomeEnabled")
|
---|
| 389 | {
|
---|
| 390 | mSkyDomeEnabled = (*static_cast<const bool *>(val));
|
---|
| 391 | return true;
|
---|
| 392 | }
|
---|
| 393 | if (key == "VisualizeCulledNodes")
|
---|
| 394 | {
|
---|
| 395 | mVisualizeCulledNodes = (*static_cast<const bool *>(val));
|
---|
| 396 | return true;
|
---|
| 397 | }
|
---|
[115] | 398 | if (key == "DelayRenderTransparents")
|
---|
| 399 | {
|
---|
| 400 | mDelayRenderTransparents = (*static_cast<const bool *>(val));
|
---|
| 401 | return true;
|
---|
| 402 | }
|
---|
[159] | 403 |
|
---|
| 404 | if (key == "DepthWrite")
|
---|
| 405 | {
|
---|
| 406 | mEnableDepthWrite = (*static_cast<const bool *>(val));
|
---|
| 407 | return true;
|
---|
| 408 | }
|
---|
| 409 | if (key == "UseItemBuffer")
|
---|
| 410 | {
|
---|
| 411 | mUseItemBuffer = (*static_cast<const bool *>(val));
|
---|
| 412 | return true;
|
---|
| 413 | }
|
---|
| 414 | if (key == "ExecuteVertexProgramForAllPasses")
|
---|
| 415 | {
|
---|
| 416 | mExecuteVertexProgramForAllPasses = (*static_cast<const bool *>(val));
|
---|
| 417 | return true;
|
---|
| 418 | }
|
---|
| 419 | if (key == "RenderTransparentsForItemBuffer")
|
---|
| 420 | {
|
---|
| 421 | mRenderTransparentsForItemBuffer = (*static_cast<const bool *>(val));
|
---|
| 422 | return true;
|
---|
| 423 | }
|
---|
| 424 |
|
---|
[74] | 425 | return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
|
---|
| 426 | setOption(key, val) || OctreeSceneManager::setOption(key, val);
|
---|
[59] | 427 | }
|
---|
| 428 | //-----------------------------------------------------------------------
|
---|
| 429 | bool VisibilityOctreeSceneManager::getOption(const String & key, void *val)
|
---|
| 430 | {
|
---|
[74] | 431 | if (key == "NumHierarchyNodes")
|
---|
| 432 | {
|
---|
| 433 | * static_cast<unsigned int *>(val) = (unsigned int)mNumOctreeNodes;
|
---|
| 434 | return true;
|
---|
| 435 | }
|
---|
| 436 |
|
---|
| 437 | return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
|
---|
| 438 | getOption(key, val) && OctreeSceneManager::getOption(key, val);
|
---|
[59] | 439 | }
|
---|
| 440 | //-----------------------------------------------------------------------
|
---|
| 441 | bool VisibilityOctreeSceneManager::getOptionValues(const String & key, StringVector &refValueList)
|
---|
| 442 | {
|
---|
| 443 | return OctreeSceneManager::getOptionValues( key, refValueList );
|
---|
| 444 | }
|
---|
| 445 | //-----------------------------------------------------------------------
|
---|
| 446 | bool VisibilityOctreeSceneManager::getOptionKeys(StringVector & refKeys)
|
---|
| 447 | {
|
---|
[74] | 448 | return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
|
---|
[103] | 449 | getOptionKeys (refKeys) || OctreeSceneManager::getOptionKeys(refKeys);
|
---|
[59] | 450 | }
|
---|
| 451 | //-----------------------------------------------------------------------
|
---|
| 452 | void VisibilityOctreeSceneManager::setVisibilityManager(GtpVisibility::VisibilityManager *visManager)
|
---|
| 453 | {
|
---|
| 454 | mVisibilityManager = visManager;
|
---|
| 455 | }
|
---|
| 456 | //-----------------------------------------------------------------------
|
---|
| 457 | GtpVisibility::VisibilityManager *VisibilityOctreeSceneManager::getVisibilityManager()
|
---|
| 458 | {
|
---|
| 459 | return mVisibilityManager;
|
---|
| 460 | }
|
---|
[93] | 461 | //-----------------------------------------------------------------------
|
---|
[92] | 462 | void VisibilityOctreeSceneManager::WriteLog()
|
---|
| 463 | {
|
---|
| 464 | std::stringstream d;
|
---|
[59] | 465 |
|
---|
[120] | 466 | d << "Depth pass: " << StringConverter::toString(mUseDepthPass) << ", "
|
---|
| 467 | << "Delay transparents: " << StringConverter::toString(mDelayRenderTransparents) << ", "
|
---|
[155] | 468 | << "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetTestGeometryForVisibleLeaves()) << ", "
|
---|
[120] | 469 | << "Algorithm type: " << mVisibilityManager->GetCullingManagerType() << "\n"
|
---|
[118] | 470 | << "Hierarchy nodes: " << mNumOctreeNodes << ", "
|
---|
| 471 | << "Traversed nodes: " << mHierarchyInterface->GetNumTraversedNodes() << ", "
|
---|
[92] | 472 | << "Rendered nodes: " << mHierarchyInterface->GetNumRenderedNodes() << ", "
|
---|
| 473 | << "Query culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumQueryCulledNodes() << ", "
|
---|
| 474 | << "Frustum culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumFrustumCulledNodes() << ", "
|
---|
| 475 | << "Queries issued: " << mVisibilityManager->GetCullingManager()->GetNumQueriesIssued() << "\n";
|
---|
[120] | 476 | /*<< "avg. FPS: " << mCurrentViewport->getTarget()->getAverageFPS() << ", "
|
---|
| 477 | << "best FPS: " << mCurrentViewport->getTarget()->getBestFPS() << ", "
|
---|
| 478 | << "worst FPS: " << mCurrentViewport->getTarget()->getWorstFPS() << ", "
|
---|
| 479 | << "best frame time: " << mCurrentViewport->getTarget()->getBestFrameTime() << ", "
|
---|
| 480 | << "worst frame time: " << mCurrentViewport->getTarget()->getWorstFrameTime() << "\n";*/
|
---|
[92] | 481 |
|
---|
| 482 | LogManager::getSingleton().logMessage(d.str());
|
---|
| 483 | }
|
---|
[118] | 484 | //-----------------------------------------------------------------------
|
---|
[159] | 485 | void VisibilityOctreeSceneManager::renderObjects(
|
---|
| 486 | const RenderPriorityGroup::TransparentRenderablePassList& objs,
|
---|
[118] | 487 | bool doLightIteration, const LightList* manualLightList)
|
---|
| 488 | {
|
---|
[159] | 489 | // for correct rendering, transparents must be rendered after hierarchical culling
|
---|
[118] | 490 | if (!mSkipTransparents)
|
---|
| 491 | {
|
---|
| 492 | OctreeSceneManager::renderObjects(objs, doLightIteration, manualLightList);
|
---|
| 493 | }
|
---|
| 494 | }
|
---|
[159] | 495 | //-----------------------------------------------------------------------
|
---|
| 496 | bool VisibilityOctreeSceneManager::validatePassForRendering(Pass* pass)
|
---|
| 497 | {
|
---|
| 498 | // skip all but first pass if we are doing the depth pass
|
---|
| 499 | if ((mRenderDepthPass || mRenderItemBuffer) && pass->getIndex() > 0)
|
---|
| 500 | {
|
---|
| 501 | return false;
|
---|
| 502 | }
|
---|
| 503 | return SceneManager::validatePassForRendering(pass);
|
---|
| 504 | }
|
---|
| 505 | //-----------------------------------------------------------------------
|
---|
| 506 | void VisibilityOctreeSceneManager::renderQueueGroupObjects(RenderQueueGroup* pGroup)
|
---|
| 507 | {
|
---|
| 508 | if (!mRenderItemBuffer)
|
---|
| 509 | {
|
---|
| 510 | OctreeSceneManager::renderQueueGroupObjects(pGroup);
|
---|
| 511 | return;
|
---|
| 512 | }
|
---|
[118] | 513 |
|
---|
[159] | 514 | // --- item buffer
|
---|
| 515 |
|
---|
| 516 | // Iterate through priorities
|
---|
| 517 | RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
|
---|
| 518 |
|
---|
| 519 | while (groupIt.hasMoreElements())
|
---|
| 520 | {
|
---|
| 521 | RenderItemBuffer(groupIt.getNext());
|
---|
| 522 | }
|
---|
| 523 | }
|
---|
| 524 | //-----------------------------------------------------------------------
|
---|
| 525 | void VisibilityOctreeSceneManager::RenderItemBuffer(RenderPriorityGroup* pGroup)
|
---|
| 526 | {
|
---|
| 527 | // Do solids
|
---|
| 528 | RenderPriorityGroup::SolidRenderablePassMap solidObjs = pGroup->_getSolidPasses();
|
---|
| 529 |
|
---|
| 530 | // ----- SOLIDS LOOP -----
|
---|
| 531 | RenderPriorityGroup::SolidRenderablePassMap::const_iterator ipass, ipassend;
|
---|
| 532 | ipassend = solidObjs.end();
|
---|
| 533 |
|
---|
| 534 | for (ipass = solidObjs.begin(); ipass != ipassend; ++ipass)
|
---|
| 535 | {
|
---|
| 536 | // Fast bypass if this group is now empty
|
---|
| 537 | if (ipass->second->empty())
|
---|
| 538 | continue;
|
---|
| 539 |
|
---|
| 540 | // Render only first pass
|
---|
| 541 | if (ipass->first->getIndex() > 0)
|
---|
| 542 | continue;
|
---|
| 543 |
|
---|
| 544 | RenderPriorityGroup::RenderableList* rendList = ipass->second;
|
---|
| 545 |
|
---|
| 546 | RenderPriorityGroup::RenderableList::const_iterator irend, irendend;
|
---|
| 547 | irendend = rendList->end();
|
---|
| 548 |
|
---|
| 549 | for (irend = rendList->begin(); irend != irendend; ++irend)
|
---|
| 550 | {
|
---|
| 551 | std::stringstream d; d << "itembuffer, pass name: " <<
|
---|
| 552 | ipass->first->getParent()->getParent()->getName();
|
---|
| 553 |
|
---|
| 554 | LogManager::getSingleton().logMessage(d.str());
|
---|
| 555 |
|
---|
| 556 | RenderSingleObjectForItemBuffer(*irend, ipass->first);
|
---|
| 557 | }
|
---|
| 558 | }
|
---|
| 559 |
|
---|
| 560 | // -- TRANSPARENT LOOP: must be handled differently
|
---|
| 561 |
|
---|
| 562 | // transparents are treated either as solids or completely discarded
|
---|
| 563 | if (mRenderTransparentsForItemBuffer)
|
---|
| 564 | {
|
---|
| 565 | RenderPriorityGroup::TransparentRenderablePassList transpObjs =
|
---|
| 566 | pGroup->_getTransparentPasses();
|
---|
| 567 | RenderPriorityGroup::TransparentRenderablePassList::const_iterator
|
---|
| 568 | itrans, itransend;
|
---|
| 569 |
|
---|
| 570 | itransend = transpObjs.end();
|
---|
| 571 | for (itrans = transpObjs.begin(); itrans != itransend; ++itrans)
|
---|
| 572 | {
|
---|
| 573 | // like for solids, render only first pass
|
---|
| 574 | if (itrans->pass->getIndex() == 0)
|
---|
| 575 | {
|
---|
| 576 | RenderSingleObjectForItemBuffer(itrans->renderable, itrans->pass);
|
---|
| 577 | }
|
---|
| 578 | }
|
---|
| 579 | }
|
---|
| 580 | }
|
---|
| 581 | //-----------------------------------------------------------------------
|
---|
| 582 | void VisibilityOctreeSceneManager::RenderSingleObjectForItemBuffer(Renderable *rend, Pass *pass)
|
---|
| 583 | {
|
---|
| 584 | static LightList nullLightList;
|
---|
| 585 |
|
---|
| 586 | int col[4];
|
---|
| 587 |
|
---|
| 588 | // -- create color code out of object id
|
---|
| 589 | col[0] = (rend->getId() >> 16) & 255;
|
---|
| 590 | col[1] = (rend->getId() >> 8) & 255;
|
---|
| 591 | col[2] = rend->getId() & 255;
|
---|
| 592 | // col[3] = 255;
|
---|
| 593 |
|
---|
| 594 | //mDestRenderSystem->setColour(col[0], col[1], col[2], col[3]);
|
---|
| 595 |
|
---|
| 596 | mItemBufferPass->setAmbient(ColourValue(col[0] / 255.0f,
|
---|
| 597 | col[1] / 255.0f,
|
---|
| 598 | col[2] / 255.0f, 1));
|
---|
| 599 |
|
---|
| 600 | // set vertex program of current pass
|
---|
| 601 | if (mExecuteVertexProgramForAllPasses && pass->hasVertexProgram())
|
---|
| 602 | {
|
---|
| 603 | mItemBufferPass->setVertexProgram(pass->getVertexProgramName());
|
---|
| 604 |
|
---|
| 605 | if (mItemBufferPass->hasVertexProgram())
|
---|
| 606 | {
|
---|
| 607 | const GpuProgramPtr& prg = mItemBufferPass->getVertexProgram();
|
---|
| 608 | // Load this program if not done already
|
---|
| 609 | if (!prg->isLoaded())
|
---|
| 610 | prg->load();
|
---|
| 611 | // Copy params
|
---|
| 612 | mItemBufferPass->setVertexProgramParameters(pass->getVertexProgramParameters());
|
---|
| 613 | }
|
---|
| 614 | }
|
---|
| 615 | else if (mItemBufferPass->hasVertexProgram())
|
---|
| 616 | {
|
---|
| 617 | mItemBufferPass->setVertexProgram("");
|
---|
| 618 | }
|
---|
| 619 |
|
---|
| 620 | Pass *usedPass = setPass(mItemBufferPass);
|
---|
| 621 |
|
---|
| 622 |
|
---|
| 623 | // Render a single object, this will set up auto params if required
|
---|
| 624 | renderSingleObject(rend, usedPass, false, &nullLightList);
|
---|
| 625 | }
|
---|
| 626 | //-----------------------------------------------------------------------
|
---|
| 627 | GtpVisibility::VisibilityManager *VisibilityOctreeSceneManager::GetVisibilityManager()
|
---|
| 628 | {
|
---|
| 629 | return mVisibilityManager;
|
---|
| 630 | }
|
---|
| 631 | //-----------------------------------------------------------------------
|
---|
| 632 | void VisibilityOctreeSceneManager::InitVisibilityCulling(Camera *cam)
|
---|
| 633 | {
|
---|
| 634 | // reset culling manager stats
|
---|
| 635 | mVisibilityManager->GetCullingManager()->InitFrame(mVisualizeCulledNodes);
|
---|
| 636 |
|
---|
| 637 | // save shadow technique. It will be reset after hierarchical culling
|
---|
| 638 | mSavedShadowTechnique = mShadowTechnique;
|
---|
| 639 |
|
---|
| 640 | // render standard solids without shadows during hierarchical culling pass
|
---|
| 641 | if ((mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE) ||
|
---|
| 642 | (mShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE))
|
---|
| 643 | {
|
---|
| 644 | mShadowTechnique = SHADOWTYPE_NONE;
|
---|
| 645 | }
|
---|
| 646 |
|
---|
| 647 | // set depth pass flag before rendering
|
---|
| 648 | mRenderDepthPass = mUseDepthPass;
|
---|
| 649 |
|
---|
| 650 | // item buffer needs full ambient lighting to use item colors as unique id
|
---|
| 651 | if (mUseItemBuffer)
|
---|
| 652 | {
|
---|
| 653 | mRenderItemBuffer = true;
|
---|
| 654 | setAmbientLight(ColourValue(1,1,1,1));
|
---|
| 655 | }
|
---|
| 656 |
|
---|
| 657 |
|
---|
| 658 | // set passes which are stored in render queue
|
---|
| 659 | // for rendering AFTER hierarchical culling, i.e., passes which need
|
---|
| 660 | // a special rendering order
|
---|
| 661 |
|
---|
| 662 | mLeavePassesInQueue = 0;
|
---|
| 663 |
|
---|
| 664 | if (!mUseDepthPass || !mUseItemBuffer)
|
---|
| 665 | {
|
---|
| 666 | if (mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE)
|
---|
| 667 | {
|
---|
| 668 | // TODO: remove this pass because it should be processed during hierarchical culling
|
---|
| 669 | mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW;
|
---|
| 670 |
|
---|
| 671 | mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_DECAL;
|
---|
| 672 | mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_DIFFUSE_SPECULAR;
|
---|
| 673 | mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
|
---|
| 674 |
|
---|
| 675 | // just render ambient passes
|
---|
| 676 | mIlluminationStage = IRS_AMBIENT;
|
---|
| 677 | }
|
---|
| 678 |
|
---|
| 679 | if (mShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE)
|
---|
| 680 | {
|
---|
| 681 | mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW;
|
---|
| 682 | mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
|
---|
| 683 | }
|
---|
| 684 |
|
---|
| 685 | // transparents should be rendered after hierarchical culling to
|
---|
| 686 | // provide front-to-back ordering
|
---|
| 687 | if (mDelayRenderTransparents)
|
---|
| 688 | {
|
---|
| 689 | mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
|
---|
| 690 | }
|
---|
| 691 | }
|
---|
| 692 |
|
---|
| 693 | // skip rendering transparents in the hierarchical culling
|
---|
| 694 | // (because they will be rendered afterwards)
|
---|
| 695 | mSkipTransparents = mUseDepthPass ||
|
---|
| 696 | (mLeavePassesInQueue & RenderPriorityGroup::TRANSPARENT_PASSES);
|
---|
| 697 |
|
---|
| 698 | // -- initialise interface for rendering traversal of the hierarchy
|
---|
| 699 | mHierarchyInterface->SetHierarchyRoot(mOctree);
|
---|
| 700 |
|
---|
| 701 | // possible two cameras (one for culling, one for rendering)
|
---|
| 702 | mHierarchyInterface->InitTraversal(mCameraInProgress,
|
---|
| 703 | mCullCamera ? getCamera("CullCamera") : NULL,
|
---|
| 704 | mLeavePassesInQueue);
|
---|
| 705 |
|
---|
| 706 | //std::stringstream d; d << "leave passes in queue: " << mLeavePassesInQueue;LogManager::getSingleton().logMessage(d.str());
|
---|
| 707 | }
|
---|
| 708 | //-----------------------------------------------------------------------
|
---|
| 709 | OctreeHierarchyInterface *VisibilityOctreeSceneManager::GetHierarchyInterface()
|
---|
| 710 | {
|
---|
| 711 | return mHierarchyInterface;
|
---|
| 712 | }
|
---|
| 713 | //-----------------------------------------------------------------------
|
---|
| 714 | /*void VisibilityOctreeSceneManager::renderBasicQueueGroupObjects(RenderQueueGroup* pGroup)
|
---|
| 715 | {
|
---|
| 716 | // Basic render loop: Iterate through priorities
|
---|
| 717 | RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
|
---|
| 718 |
|
---|
| 719 | while (groupIt.hasMoreElements())
|
---|
| 720 | {
|
---|
| 721 | RenderPriorityGroup* pPriorityGrp = groupIt.getNext();
|
---|
| 722 |
|
---|
| 723 | // Sort the queue first
|
---|
| 724 | pPriorityGrp->sort(mCameraInProgress);
|
---|
| 725 |
|
---|
| 726 | // Do solids
|
---|
| 727 | // TODO: render other solid passes for shadows
|
---|
| 728 | renderObjects(pPriorityGrp->_getSolidPassesNoShadows(), true);
|
---|
| 729 |
|
---|
| 730 | // do solid passes no shadows if addititive stencil shadows
|
---|
| 731 | if (mSavedShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE)
|
---|
| 732 | renderObjects(pPriorityGrp->_getSolidPassesNoShadows(), true);
|
---|
| 733 |
|
---|
| 734 | // Do transparents
|
---|
| 735 | renderObjects(pPriorityGrp->_getTransparentPasses(), true);
|
---|
| 736 |
|
---|
| 737 |
|
---|
| 738 | }// for each priority
|
---|
| 739 | }*/
|
---|
[59] | 740 | } // namespace Ogre |
---|