[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 | {
|
---|
[159] | 239 | // save ambient light to reset later
|
---|
| 240 | ColourValue savedAmbient = mAmbientLight;
|
---|
| 241 |
|
---|
| 242 | //-- apply standard rendering for some modes (e.g., visualization, shadow pass)
|
---|
| 243 |
|
---|
| 244 | if (mShowVisualization ||
|
---|
| 245 | (mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE &&
|
---|
| 246 | mIlluminationStage == IRS_RENDER_TO_TEXTURE))
|
---|
| 247 | {
|
---|
| 248 | IlluminationRenderStage savedStage = mIlluminationStage;
|
---|
[122] | 249 |
|
---|
[159] | 250 | if (mShowVisualization)
|
---|
| 251 | {
|
---|
| 252 | // disable illumination stage to prevent rendering shadows
|
---|
| 253 | mIlluminationStage = IRS_NONE;
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | // standard rendering for shadow maps because of performance
|
---|
[115] | 257 | OctreeSceneManager::_renderVisibleObjects();
|
---|
[118] | 258 |
|
---|
[159] | 259 | mIlluminationStage = savedStage;
|
---|
| 260 | }
|
---|
| 261 | else //-- the hierarchical culling algorithm
|
---|
| 262 | {
|
---|
| 263 | // don't render backgrounds for item buffer
|
---|
| 264 | if (mUseItemBuffer)
|
---|
| 265 | {
|
---|
| 266 | clearSpecialCaseRenderQueues();
|
---|
| 267 | getRenderQueue()->clear();
|
---|
| 268 | }
|
---|
[87] | 269 |
|
---|
[159] | 270 | //-- hierarchical culling
|
---|
| 271 | // the objects of different layers (e.g., background, scene,
|
---|
| 272 | // overlay) must be identified and rendered one after another
|
---|
[118] | 273 |
|
---|
[159] | 274 | //-- render all early skies
|
---|
| 275 | clearSpecialCaseRenderQueues();
|
---|
| 276 | addSpecialCaseRenderQueue(RENDER_QUEUE_BACKGROUND);
|
---|
| 277 | addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_EARLY);
|
---|
| 278 | setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE);
|
---|
[118] | 279 |
|
---|
[159] | 280 | OctreeSceneManager::_renderVisibleObjects();
|
---|
[115] | 281 |
|
---|
[59] | 282 |
|
---|
| 283 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
[159] | 284 | // delete previously rendered content
|
---|
| 285 | _deleteRenderedQueueGroups();
|
---|
[59] | 286 | #endif
|
---|
| 287 |
|
---|
[159] | 288 | //-- prepare queue for visible objects (i.e., all but overlay and skies late)
|
---|
| 289 | clearSpecialCaseRenderQueues();
|
---|
| 290 | addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_LATE);
|
---|
| 291 | addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY);
|
---|
| 292 | setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
|
---|
[115] | 293 |
|
---|
[59] | 294 |
|
---|
[159] | 295 | // set all necessary parameters for
|
---|
| 296 | // hierarchical visibility culling and rendering
|
---|
| 297 | InitVisibilityCulling(mCameraInProgress);
|
---|
[118] | 298 |
|
---|
[159] | 299 | /**
|
---|
| 300 | * the hierarchical culling algorithm
|
---|
| 301 | * for depth pass: we just find objects and update depth buffer
|
---|
| 302 | * for "delayed" rendering: we render some passes afterwards
|
---|
| 303 | * e.g., transparents, because they need front-to-back sorting
|
---|
| 304 | **/
|
---|
[115] | 305 |
|
---|
[159] | 306 | mVisibilityManager->ApplyVisibilityCulling();
|
---|
[115] | 307 |
|
---|
[159] | 308 | // delete remaining renderables from queue (all not in mLeavePassesInQueue)
|
---|
| 309 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
| 310 | _deleteRenderedQueueGroups(mLeavePassesInQueue);
|
---|
| 311 | #endif
|
---|
[59] | 312 |
|
---|
[159] | 313 | //-- reset parameters
|
---|
| 314 | mRenderDepthPass = false;
|
---|
| 315 | mRenderItemBuffer = false;
|
---|
| 316 | mSkipTransparents = false;
|
---|
| 317 | mLeavePassesInQueue = 0;
|
---|
| 318 | mShadowTechnique = mSavedShadowTechnique;
|
---|
[92] | 319 |
|
---|
[159] | 320 |
|
---|
| 321 | // add visible nodes found by the visibility culling algorithm
|
---|
| 322 | if (mUseDepthPass)
|
---|
[120] | 323 | {
|
---|
[159] | 324 | for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it)
|
---|
| 325 | {
|
---|
| 326 | (*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false);
|
---|
| 327 | }
|
---|
[120] | 328 | }
|
---|
[114] | 329 |
|
---|
[159] | 330 | //-- we render all remaining queue objects
|
---|
| 331 | // used for depth pass, transparents, overlay
|
---|
| 332 | clearSpecialCaseRenderQueues();
|
---|
| 333 | OctreeSceneManager::_renderVisibleObjects();
|
---|
| 334 |
|
---|
| 335 | } // hierarchical culling
|
---|
| 336 |
|
---|
| 337 | // reset ambient light
|
---|
| 338 | setAmbientLight(savedAmbient);
|
---|
| 339 |
|
---|
| 340 | getRenderQueue()->clear(); // finally clear render queue
|
---|
| 341 | //WriteLog(); // write out stats
|
---|
[59] | 342 | }
|
---|
[159] | 343 |
|
---|
[59] | 344 | //-----------------------------------------------------------------------
|
---|
| 345 | void VisibilityOctreeSceneManager::_updateSceneGraph(Camera* cam)
|
---|
| 346 | {
|
---|
| 347 | mVisibilityManager->GetCullingManager()->SetHierarchyInterface(mHierarchyInterface);
|
---|
| 348 | mHierarchyInterface->SetRenderSystem(mDestRenderSystem);
|
---|
| 349 |
|
---|
| 350 | OctreeSceneManager::_updateSceneGraph(cam);
|
---|
| 351 | }
|
---|
| 352 | //-----------------------------------------------------------------------
|
---|
| 353 | bool VisibilityOctreeSceneManager::setOption(const String & key, const void * val)
|
---|
| 354 | {
|
---|
[115] | 355 | if (key == "UseDepthPass")
|
---|
[87] | 356 | {
|
---|
[115] | 357 | mUseDepthPass = (*static_cast<const bool *>(val));
|
---|
[87] | 358 | return true;
|
---|
| 359 | }
|
---|
[139] | 360 | if (key == "PrepareVisualization")
|
---|
[100] | 361 | {
|
---|
| 362 | mShowVisualization = (*static_cast<const bool *>(val));
|
---|
| 363 | return true;
|
---|
| 364 | }
|
---|
[112] | 365 | if (key == "RenderNodesForViz")
|
---|
| 366 | {
|
---|
[114] | 367 | mRenderNodesForViz = (*static_cast<const bool *>(val));
|
---|
[112] | 368 | return true;
|
---|
| 369 | }
|
---|
[118] | 370 | if (key == "RenderNodesContentForViz")
|
---|
| 371 | {
|
---|
| 372 | mRenderNodesContentForViz = (*static_cast<const bool *>(val));
|
---|
| 373 | return true;
|
---|
| 374 | }
|
---|
[112] | 375 | if (key == "SkyBoxEnabled")
|
---|
| 376 | {
|
---|
| 377 | mSkyBoxEnabled = (*static_cast<const bool *>(val));
|
---|
| 378 | return true;
|
---|
| 379 | }
|
---|
| 380 | if (key == "SkyPlaneEnabled")
|
---|
| 381 | {
|
---|
| 382 | mSkyPlaneEnabled = (*static_cast<const bool *>(val));
|
---|
| 383 | return true;
|
---|
| 384 | }
|
---|
| 385 | if (key == "SkyDomeEnabled")
|
---|
| 386 | {
|
---|
| 387 | mSkyDomeEnabled = (*static_cast<const bool *>(val));
|
---|
| 388 | return true;
|
---|
| 389 | }
|
---|
| 390 | if (key == "VisualizeCulledNodes")
|
---|
| 391 | {
|
---|
| 392 | mVisualizeCulledNodes = (*static_cast<const bool *>(val));
|
---|
| 393 | return true;
|
---|
| 394 | }
|
---|
[115] | 395 | if (key == "DelayRenderTransparents")
|
---|
| 396 | {
|
---|
| 397 | mDelayRenderTransparents = (*static_cast<const bool *>(val));
|
---|
| 398 | return true;
|
---|
| 399 | }
|
---|
[159] | 400 |
|
---|
| 401 | if (key == "DepthWrite")
|
---|
| 402 | {
|
---|
| 403 | mEnableDepthWrite = (*static_cast<const bool *>(val));
|
---|
| 404 | return true;
|
---|
| 405 | }
|
---|
| 406 | if (key == "UseItemBuffer")
|
---|
| 407 | {
|
---|
| 408 | mUseItemBuffer = (*static_cast<const bool *>(val));
|
---|
| 409 | return true;
|
---|
| 410 | }
|
---|
| 411 | if (key == "ExecuteVertexProgramForAllPasses")
|
---|
| 412 | {
|
---|
| 413 | mExecuteVertexProgramForAllPasses = (*static_cast<const bool *>(val));
|
---|
| 414 | return true;
|
---|
| 415 | }
|
---|
| 416 | if (key == "RenderTransparentsForItemBuffer")
|
---|
| 417 | {
|
---|
| 418 | mRenderTransparentsForItemBuffer = (*static_cast<const bool *>(val));
|
---|
| 419 | return true;
|
---|
| 420 | }
|
---|
| 421 |
|
---|
[74] | 422 | return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
|
---|
| 423 | setOption(key, val) || OctreeSceneManager::setOption(key, val);
|
---|
[59] | 424 | }
|
---|
| 425 | //-----------------------------------------------------------------------
|
---|
| 426 | bool VisibilityOctreeSceneManager::getOption(const String & key, void *val)
|
---|
| 427 | {
|
---|
[74] | 428 | if (key == "NumHierarchyNodes")
|
---|
| 429 | {
|
---|
| 430 | * static_cast<unsigned int *>(val) = (unsigned int)mNumOctreeNodes;
|
---|
| 431 | return true;
|
---|
| 432 | }
|
---|
| 433 |
|
---|
| 434 | return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
|
---|
| 435 | getOption(key, val) && OctreeSceneManager::getOption(key, val);
|
---|
[59] | 436 | }
|
---|
| 437 | //-----------------------------------------------------------------------
|
---|
| 438 | bool VisibilityOctreeSceneManager::getOptionValues(const String & key, StringVector &refValueList)
|
---|
| 439 | {
|
---|
| 440 | return OctreeSceneManager::getOptionValues( key, refValueList );
|
---|
| 441 | }
|
---|
| 442 | //-----------------------------------------------------------------------
|
---|
| 443 | bool VisibilityOctreeSceneManager::getOptionKeys(StringVector & refKeys)
|
---|
| 444 | {
|
---|
[74] | 445 | return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
|
---|
[103] | 446 | getOptionKeys (refKeys) || OctreeSceneManager::getOptionKeys(refKeys);
|
---|
[59] | 447 | }
|
---|
| 448 | //-----------------------------------------------------------------------
|
---|
| 449 | void VisibilityOctreeSceneManager::setVisibilityManager(GtpVisibility::VisibilityManager *visManager)
|
---|
| 450 | {
|
---|
| 451 | mVisibilityManager = visManager;
|
---|
| 452 | }
|
---|
| 453 | //-----------------------------------------------------------------------
|
---|
| 454 | GtpVisibility::VisibilityManager *VisibilityOctreeSceneManager::getVisibilityManager()
|
---|
| 455 | {
|
---|
| 456 | return mVisibilityManager;
|
---|
| 457 | }
|
---|
[93] | 458 | //-----------------------------------------------------------------------
|
---|
[92] | 459 | void VisibilityOctreeSceneManager::WriteLog()
|
---|
| 460 | {
|
---|
| 461 | std::stringstream d;
|
---|
[59] | 462 |
|
---|
[120] | 463 | d << "Depth pass: " << StringConverter::toString(mUseDepthPass) << ", "
|
---|
| 464 | << "Delay transparents: " << StringConverter::toString(mDelayRenderTransparents) << ", "
|
---|
[155] | 465 | << "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetTestGeometryForVisibleLeaves()) << ", "
|
---|
[120] | 466 | << "Algorithm type: " << mVisibilityManager->GetCullingManagerType() << "\n"
|
---|
[118] | 467 | << "Hierarchy nodes: " << mNumOctreeNodes << ", "
|
---|
| 468 | << "Traversed nodes: " << mHierarchyInterface->GetNumTraversedNodes() << ", "
|
---|
[92] | 469 | << "Rendered nodes: " << mHierarchyInterface->GetNumRenderedNodes() << ", "
|
---|
| 470 | << "Query culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumQueryCulledNodes() << ", "
|
---|
| 471 | << "Frustum culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumFrustumCulledNodes() << ", "
|
---|
| 472 | << "Queries issued: " << mVisibilityManager->GetCullingManager()->GetNumQueriesIssued() << "\n";
|
---|
[120] | 473 | /*<< "avg. FPS: " << mCurrentViewport->getTarget()->getAverageFPS() << ", "
|
---|
| 474 | << "best FPS: " << mCurrentViewport->getTarget()->getBestFPS() << ", "
|
---|
| 475 | << "worst FPS: " << mCurrentViewport->getTarget()->getWorstFPS() << ", "
|
---|
| 476 | << "best frame time: " << mCurrentViewport->getTarget()->getBestFrameTime() << ", "
|
---|
| 477 | << "worst frame time: " << mCurrentViewport->getTarget()->getWorstFrameTime() << "\n";*/
|
---|
[92] | 478 |
|
---|
| 479 | LogManager::getSingleton().logMessage(d.str());
|
---|
| 480 | }
|
---|
[118] | 481 | //-----------------------------------------------------------------------
|
---|
[159] | 482 | void VisibilityOctreeSceneManager::renderObjects(
|
---|
| 483 | const RenderPriorityGroup::TransparentRenderablePassList& objs,
|
---|
[118] | 484 | bool doLightIteration, const LightList* manualLightList)
|
---|
| 485 | {
|
---|
[159] | 486 | // for correct rendering, transparents must be rendered after hierarchical culling
|
---|
[118] | 487 | if (!mSkipTransparents)
|
---|
| 488 | {
|
---|
| 489 | OctreeSceneManager::renderObjects(objs, doLightIteration, manualLightList);
|
---|
| 490 | }
|
---|
| 491 | }
|
---|
[159] | 492 | //-----------------------------------------------------------------------
|
---|
| 493 | bool VisibilityOctreeSceneManager::validatePassForRendering(Pass* pass)
|
---|
| 494 | {
|
---|
| 495 | // skip all but first pass if we are doing the depth pass
|
---|
| 496 | if ((mRenderDepthPass || mRenderItemBuffer) && pass->getIndex() > 0)
|
---|
| 497 | {
|
---|
| 498 | return false;
|
---|
| 499 | }
|
---|
| 500 | return SceneManager::validatePassForRendering(pass);
|
---|
| 501 | }
|
---|
| 502 | //-----------------------------------------------------------------------
|
---|
| 503 | void VisibilityOctreeSceneManager::renderQueueGroupObjects(RenderQueueGroup* pGroup)
|
---|
| 504 | {
|
---|
| 505 | if (!mRenderItemBuffer)
|
---|
| 506 | {
|
---|
| 507 | OctreeSceneManager::renderQueueGroupObjects(pGroup);
|
---|
| 508 | return;
|
---|
| 509 | }
|
---|
[118] | 510 |
|
---|
[159] | 511 | // --- item buffer
|
---|
| 512 |
|
---|
| 513 | // Iterate through priorities
|
---|
| 514 | RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
|
---|
| 515 |
|
---|
| 516 | while (groupIt.hasMoreElements())
|
---|
| 517 | {
|
---|
| 518 | RenderItemBuffer(groupIt.getNext());
|
---|
| 519 | }
|
---|
| 520 | }
|
---|
| 521 | //-----------------------------------------------------------------------
|
---|
| 522 | void VisibilityOctreeSceneManager::RenderItemBuffer(RenderPriorityGroup* pGroup)
|
---|
| 523 | {
|
---|
| 524 | // Do solids
|
---|
| 525 | RenderPriorityGroup::SolidRenderablePassMap solidObjs = pGroup->_getSolidPasses();
|
---|
| 526 |
|
---|
| 527 | // ----- SOLIDS LOOP -----
|
---|
| 528 | RenderPriorityGroup::SolidRenderablePassMap::const_iterator ipass, ipassend;
|
---|
| 529 | ipassend = solidObjs.end();
|
---|
| 530 |
|
---|
| 531 | for (ipass = solidObjs.begin(); ipass != ipassend; ++ipass)
|
---|
| 532 | {
|
---|
| 533 | // Fast bypass if this group is now empty
|
---|
| 534 | if (ipass->second->empty())
|
---|
| 535 | continue;
|
---|
| 536 |
|
---|
| 537 | // Render only first pass
|
---|
| 538 | if (ipass->first->getIndex() > 0)
|
---|
| 539 | continue;
|
---|
| 540 |
|
---|
| 541 | RenderPriorityGroup::RenderableList* rendList = ipass->second;
|
---|
| 542 |
|
---|
| 543 | RenderPriorityGroup::RenderableList::const_iterator irend, irendend;
|
---|
| 544 | irendend = rendList->end();
|
---|
| 545 |
|
---|
| 546 | for (irend = rendList->begin(); irend != irendend; ++irend)
|
---|
| 547 | {
|
---|
| 548 | std::stringstream d; d << "itembuffer, pass name: " <<
|
---|
| 549 | ipass->first->getParent()->getParent()->getName();
|
---|
| 550 |
|
---|
| 551 | LogManager::getSingleton().logMessage(d.str());
|
---|
| 552 |
|
---|
| 553 | RenderSingleObjectForItemBuffer(*irend, ipass->first);
|
---|
| 554 | }
|
---|
| 555 | }
|
---|
| 556 |
|
---|
| 557 | // -- TRANSPARENT LOOP: must be handled differently
|
---|
| 558 |
|
---|
| 559 | // transparents are treated either as solids or completely discarded
|
---|
| 560 | if (mRenderTransparentsForItemBuffer)
|
---|
| 561 | {
|
---|
| 562 | RenderPriorityGroup::TransparentRenderablePassList transpObjs =
|
---|
| 563 | pGroup->_getTransparentPasses();
|
---|
| 564 | RenderPriorityGroup::TransparentRenderablePassList::const_iterator
|
---|
| 565 | itrans, itransend;
|
---|
| 566 |
|
---|
| 567 | itransend = transpObjs.end();
|
---|
| 568 | for (itrans = transpObjs.begin(); itrans != itransend; ++itrans)
|
---|
| 569 | {
|
---|
| 570 | // like for solids, render only first pass
|
---|
| 571 | if (itrans->pass->getIndex() == 0)
|
---|
| 572 | {
|
---|
| 573 | RenderSingleObjectForItemBuffer(itrans->renderable, itrans->pass);
|
---|
| 574 | }
|
---|
| 575 | }
|
---|
| 576 | }
|
---|
| 577 | }
|
---|
| 578 | //-----------------------------------------------------------------------
|
---|
| 579 | void VisibilityOctreeSceneManager::RenderSingleObjectForItemBuffer(Renderable *rend, Pass *pass)
|
---|
| 580 | {
|
---|
| 581 | static LightList nullLightList;
|
---|
| 582 |
|
---|
| 583 | int col[4];
|
---|
| 584 |
|
---|
| 585 | // -- create color code out of object id
|
---|
| 586 | col[0] = (rend->getId() >> 16) & 255;
|
---|
| 587 | col[1] = (rend->getId() >> 8) & 255;
|
---|
| 588 | col[2] = rend->getId() & 255;
|
---|
| 589 | // col[3] = 255;
|
---|
| 590 |
|
---|
| 591 | //mDestRenderSystem->setColour(col[0], col[1], col[2], col[3]);
|
---|
| 592 |
|
---|
| 593 | mItemBufferPass->setAmbient(ColourValue(col[0] / 255.0f,
|
---|
| 594 | col[1] / 255.0f,
|
---|
| 595 | col[2] / 255.0f, 1));
|
---|
| 596 |
|
---|
| 597 | // set vertex program of current pass
|
---|
| 598 | if (mExecuteVertexProgramForAllPasses && pass->hasVertexProgram())
|
---|
| 599 | {
|
---|
| 600 | mItemBufferPass->setVertexProgram(pass->getVertexProgramName());
|
---|
| 601 |
|
---|
| 602 | if (mItemBufferPass->hasVertexProgram())
|
---|
| 603 | {
|
---|
| 604 | const GpuProgramPtr& prg = mItemBufferPass->getVertexProgram();
|
---|
| 605 | // Load this program if not done already
|
---|
| 606 | if (!prg->isLoaded())
|
---|
| 607 | prg->load();
|
---|
| 608 | // Copy params
|
---|
| 609 | mItemBufferPass->setVertexProgramParameters(pass->getVertexProgramParameters());
|
---|
| 610 | }
|
---|
| 611 | }
|
---|
| 612 | else if (mItemBufferPass->hasVertexProgram())
|
---|
| 613 | {
|
---|
| 614 | mItemBufferPass->setVertexProgram("");
|
---|
| 615 | }
|
---|
| 616 |
|
---|
| 617 | Pass *usedPass = setPass(mItemBufferPass);
|
---|
| 618 |
|
---|
| 619 |
|
---|
| 620 | // Render a single object, this will set up auto params if required
|
---|
| 621 | renderSingleObject(rend, usedPass, false, &nullLightList);
|
---|
| 622 | }
|
---|
| 623 | //-----------------------------------------------------------------------
|
---|
| 624 | GtpVisibility::VisibilityManager *VisibilityOctreeSceneManager::GetVisibilityManager()
|
---|
| 625 | {
|
---|
| 626 | return mVisibilityManager;
|
---|
| 627 | }
|
---|
| 628 | //-----------------------------------------------------------------------
|
---|
| 629 | void VisibilityOctreeSceneManager::InitVisibilityCulling(Camera *cam)
|
---|
| 630 | {
|
---|
| 631 | InitDepthPass(); // create material for depth pass
|
---|
| 632 | InitItemBufferPass(); // create material for item buffer pass
|
---|
| 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 |
---|