[59] | 1 | #include "OgreVisibilityTerrainSceneManager.h"
|
---|
[74] | 2 | #include "OgreVisibilityOptionsManager.h"
|
---|
[59] | 3 | #include <OgreMath.h>
|
---|
| 4 | #include <OgreIteratorWrappers.h>
|
---|
| 5 | #include <OgreRenderSystem.h>
|
---|
| 6 | #include <OgreCamera.h>
|
---|
[93] | 7 | #include <OgreLogManager.h>
|
---|
[100] | 8 | #include <OgreStringConverter.h>
|
---|
[122] | 9 | #include <OgreEntity.h>
|
---|
| 10 | #include <OgreSubEntity.h>
|
---|
[59] | 11 |
|
---|
[156] | 12 |
|
---|
[59] | 13 | namespace Ogre {
|
---|
[87] | 14 |
|
---|
[59] | 15 | //-----------------------------------------------------------------------
|
---|
[153] | 16 | VisibilityTerrainSceneManager::VisibilityTerrainSceneManager(GtpVisibility::
|
---|
| 17 | VisibilityManager *visManager):
|
---|
[115] | 18 | mVisibilityManager(visManager),
|
---|
[103] | 19 | mShowVisualization(false),
|
---|
[112] | 20 | mRenderNodesForViz(false),
|
---|
[113] | 21 | mRenderNodesContentForViz(false),
|
---|
[114] | 22 | mVisualizeCulledNodes(false),
|
---|
[139] | 23 | mLeavePassesInQueue(0),
|
---|
[120] | 24 | mDelayRenderTransparents(true),
|
---|
[122] | 25 | mUseDepthPass(false),
|
---|
[153] | 26 | mRenderDepthPass(false),
|
---|
[154] | 27 | mUseItemBuffer(false),
|
---|
| 28 | //mUseItemBuffer(true),
|
---|
[153] | 29 | mRenderItemBuffer(false),
|
---|
[154] | 30 | mCurrentEntityId(1),
|
---|
[139] | 31 | mEnableDepthWrite(true),
|
---|
| 32 | mSkipTransparents(false),
|
---|
[159] | 33 | mSavedShadowTechnique(SHADOWTYPE_NONE),
|
---|
| 34 | mRenderTransparentsForItemBuffer(false),
|
---|
| 35 | mExecuteVertexProgramForAllPasses(false)
|
---|
[59] | 36 | {
|
---|
[120] | 37 | mHierarchyInterface = new OctreeHierarchyInterface(this, mDestRenderSystem);
|
---|
[139] | 38 |
|
---|
[164] | 39 | //mDisplayNodes = true;//mShowBoundingBoxes = true;//mShowBoxes = true;
|
---|
[103] | 40 |
|
---|
| 41 | // TODO: set maxdepth to reasonable value
|
---|
[96] | 42 | mMaxDepth = 50;
|
---|
[59] | 43 | }
|
---|
| 44 | //-----------------------------------------------------------------------
|
---|
[119] | 45 | void VisibilityTerrainSceneManager::InitDepthPass()
|
---|
[115] | 46 | {
|
---|
| 47 | MaterialPtr depthMat = MaterialManager::getSingleton().getByName("Visibility/DepthPass");
|
---|
| 48 |
|
---|
| 49 | if (depthMat.isNull())
|
---|
| 50 | {
|
---|
| 51 | depthMat = MaterialManager::getSingleton().create(
|
---|
| 52 | "Visibility/DepthPass",
|
---|
| 53 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
[159] | 54 |
|
---|
[115] | 55 | mDepthPass = depthMat->getTechnique(0)->getPass(0);
|
---|
| 56 | mDepthPass->setColourWriteEnabled(false);
|
---|
| 57 | mDepthPass->setDepthWriteEnabled(true);
|
---|
| 58 | mDepthPass->setLightingEnabled(false);
|
---|
| 59 | }
|
---|
| 60 | else
|
---|
| 61 | {
|
---|
| 62 | mDepthPass = depthMat->getTechnique(0)->getPass(0);
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 | //-----------------------------------------------------------------------
|
---|
[159] | 66 | VisibilityTerrainSceneManager::~VisibilityTerrainSceneManager()
|
---|
| 67 | {
|
---|
| 68 | if (mHierarchyInterface)
|
---|
| 69 | {
|
---|
| 70 | delete mHierarchyInterface;
|
---|
| 71 | mHierarchyInterface = NULL;
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 | //-----------------------------------------------------------------------
|
---|
[122] | 75 | void VisibilityTerrainSceneManager::InitItemBufferPass()
|
---|
| 76 | {
|
---|
| 77 | MaterialPtr itemBufferMat = MaterialManager::getSingleton().
|
---|
| 78 | getByName("Visibility/ItemBufferPass");
|
---|
| 79 |
|
---|
| 80 | if (itemBufferMat.isNull())
|
---|
| 81 | {
|
---|
| 82 | // Init
|
---|
| 83 | itemBufferMat = MaterialManager::getSingleton().create("Visibility/ItemBufferPass",
|
---|
| 84 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
| 85 |
|
---|
| 86 | mItemBufferPass = itemBufferMat->getTechnique(0)->getPass(0);
|
---|
| 87 | mItemBufferPass->setColourWriteEnabled(true);
|
---|
| 88 | mItemBufferPass->setDepthWriteEnabled(true);
|
---|
| 89 | mItemBufferPass->setLightingEnabled(true);
|
---|
[150] | 90 | //mItemBufferPass->setLightingEnabled(false);
|
---|
[122] | 91 | }
|
---|
| 92 | else
|
---|
| 93 | {
|
---|
| 94 | mItemBufferPass = itemBufferMat->getTechnique(0)->getPass(0);
|
---|
| 95 | }
|
---|
[150] | 96 | //mItemBufferPass->setAmbient(1, 1, 0);
|
---|
[122] | 97 | }
|
---|
| 98 | //-----------------------------------------------------------------------
|
---|
[139] | 99 | void VisibilityTerrainSceneManager::PrepareVisualization(Camera *cam)
|
---|
[115] | 100 | {
|
---|
| 101 | // add player camera for visualization purpose
|
---|
[121] | 102 | try
|
---|
| 103 | {
|
---|
[115] | 104 | Camera *c;
|
---|
| 105 | if ((c = getCamera("PlayerCam")) != NULL)
|
---|
| 106 | {
|
---|
| 107 | getRenderQueue()->addRenderable(c);
|
---|
| 108 | }
|
---|
| 109 | }
|
---|
[121] | 110 | catch (...)
|
---|
[115] | 111 | {
|
---|
| 112 | // ignore
|
---|
| 113 | }
|
---|
[118] | 114 | for (BoxList::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it)
|
---|
| 115 | {
|
---|
| 116 | getRenderQueue()->addRenderable(*it);
|
---|
| 117 | }
|
---|
[115] | 118 | if (mRenderNodesForViz || mRenderNodesContentForViz)
|
---|
| 119 | {
|
---|
[164] | 120 | // HACK: change node material so it is better suited for visualization
|
---|
[118] | 121 | MaterialPtr nodeMat = MaterialManager::getSingleton().getByName("Core/NodeMaterial");
|
---|
| 122 | nodeMat->setAmbient(1, 1, 0);
|
---|
| 123 | nodeMat->setLightingEnabled(true);
|
---|
| 124 | nodeMat->getTechnique(0)->getPass(0)->removeAllTextureUnitStates();
|
---|
| 125 |
|
---|
[115] | 126 | for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it)
|
---|
| 127 | {
|
---|
| 128 | if (mRenderNodesForViz)
|
---|
| 129 | {
|
---|
[164] | 130 | // render the leaf nodes
|
---|
| 131 | if (((*it)->numAttachedObjects() > 0) && ((*it)->numChildren() == 0) &&
|
---|
| 132 | (*it)->getAttachedObject(0)->getMovableType() == "Entity")
|
---|
| 133 | {
|
---|
| 134 | getRenderQueue()->addRenderable((*it));
|
---|
| 135 | }
|
---|
[121] | 136 |
|
---|
[115] | 137 | // addbounding boxes instead of node itself
|
---|
[139] | 138 | //(*it)->_addBoundingBoxToQueue(getRenderQueue());
|
---|
[115] | 139 | }
|
---|
| 140 | if (mRenderNodesContentForViz)
|
---|
| 141 | {
|
---|
[122] | 142 | (*it)->_addToRenderQueue(cam, getRenderQueue(), false);
|
---|
[115] | 143 | }
|
---|
| 144 | }
|
---|
[121] | 145 | }
|
---|
[103] | 146 | }
|
---|
| 147 | //-----------------------------------------------------------------------
|
---|
[120] | 148 | Pass *VisibilityTerrainSceneManager::setPass(Pass* pass)
|
---|
| 149 | {
|
---|
[139] | 150 | // TODO: setting vertex program is not efficient
|
---|
| 151 | //Pass *usedPass = ((mRenderDepthPass && !pass->hasVertexProgram()) ? mDepthPass : pass);
|
---|
[121] | 152 |
|
---|
[156] | 153 | // set depth fill pass if we currently do not make an aabb occlusion query
|
---|
[133] | 154 | Pass *usedPass = (mRenderDepthPass && !mHierarchyInterface->IsBoundingBoxQuery() ?
|
---|
| 155 | mDepthPass : pass);
|
---|
[121] | 156 |
|
---|
| 157 | IlluminationRenderStage savedStage = mIlluminationStage;
|
---|
[120] | 158 |
|
---|
[121] | 159 | // set illumination stage to NONE so no shadow material is used
|
---|
| 160 | // for depth pass or for occlusion query
|
---|
[122] | 161 | if (mRenderDepthPass || mHierarchyInterface->IsBoundingBoxQuery())
|
---|
[121] | 162 | {
|
---|
| 163 | mIlluminationStage = IRS_NONE;
|
---|
| 164 | }
|
---|
| 165 |
|
---|
[159] | 166 | // --- set vertex program of current pass in order to set correct depth
|
---|
| 167 | if (mExecuteVertexProgramForAllPasses && mRenderDepthPass && pass->hasVertexProgram())
|
---|
[120] | 168 | {
|
---|
[159] | 169 | // add vertex program of current pass to depth pass
|
---|
| 170 | mDepthPass->setVertexProgram(pass->getVertexProgramName());
|
---|
[120] | 171 |
|
---|
[159] | 172 | if (mDepthPass->hasVertexProgram())
|
---|
[120] | 173 | {
|
---|
[159] | 174 | const GpuProgramPtr& prg = mDepthPass->getVertexProgram();
|
---|
| 175 | // Load this program if not done already
|
---|
| 176 | if (!prg->isLoaded())
|
---|
| 177 | prg->load();
|
---|
| 178 | // Copy params
|
---|
| 179 | mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters());
|
---|
[120] | 180 | }
|
---|
| 181 | }
|
---|
[159] | 182 | else if (mDepthPass->hasVertexProgram())
|
---|
| 183 | {
|
---|
| 184 | mDepthPass->setVertexProgram("");
|
---|
| 185 | }
|
---|
| 186 |
|
---|
[133] | 187 |
|
---|
| 188 | bool IsDepthWrite = usedPass->getDepthWriteEnabled();
|
---|
[139] | 189 |
|
---|
[133] | 190 | // global option which enables / disables depth writes
|
---|
| 191 | if (!mEnableDepthWrite)
|
---|
| 192 | {
|
---|
| 193 | usedPass->setDepthWriteEnabled(false);
|
---|
| 194 | }
|
---|
[121] | 195 | //else if (mIsItemBufferPass) {usedPass = mItemBufferPass;}
|
---|
| 196 |
|
---|
| 197 | Pass *result = SceneManager::setPass(usedPass);
|
---|
[120] | 198 |
|
---|
[133] | 199 | // reset depth write
|
---|
| 200 | if (!mEnableDepthWrite)
|
---|
| 201 | {
|
---|
| 202 | usedPass->setDepthWriteEnabled(IsDepthWrite);
|
---|
| 203 | }
|
---|
| 204 |
|
---|
[121] | 205 | // reset illumination stage
|
---|
| 206 | mIlluminationStage = savedStage;
|
---|
| 207 |
|
---|
| 208 | return result;
|
---|
[120] | 209 | }
|
---|
| 210 | //-----------------------------------------------------------------------
|
---|
[115] | 211 | void VisibilityTerrainSceneManager::_findVisibleObjects(Camera* cam, bool onlyShadowCasters)
|
---|
[103] | 212 | {
|
---|
[115] | 213 | //-- show visible scene nodes and octree bounding boxes from last frame
|
---|
| 214 | if (mShowVisualization)
|
---|
| 215 | {
|
---|
[139] | 216 | PrepareVisualization(cam);
|
---|
[115] | 217 | }
|
---|
[155] | 218 | else
|
---|
[139] | 219 | {
|
---|
[148] | 220 | // for hierarchical culling, we interleave identification
|
---|
[147] | 221 | // and rendering of objects in _renderVisibibleObjects
|
---|
[148] | 222 |
|
---|
[155] | 223 | // for the shadow pass we use only standard rendering
|
---|
| 224 | // because of low occlusion
|
---|
[147] | 225 | if (mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE &&
|
---|
| 226 | mIlluminationStage == IRS_RENDER_TO_TEXTURE)
|
---|
| 227 | {
|
---|
| 228 | TerrainSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
|
---|
| 229 | }
|
---|
[139] | 230 | // only shadow casters will be rendered in shadow texture pass
|
---|
[155] | 231 | // mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters);
|
---|
[139] | 232 | }
|
---|
[122] | 233 |
|
---|
[159] | 234 |
|
---|
[156] | 235 | // -- delete lists stored for visualization
|
---|
[121] | 236 | mVisible.clear();
|
---|
| 237 | mBoxes.clear();
|
---|
[115] | 238 | }
|
---|
| 239 | //-----------------------------------------------------------------------
|
---|
| 240 | void VisibilityTerrainSceneManager::_renderVisibleObjects()
|
---|
| 241 | {
|
---|
[155] | 242 | // save ambient light to reset later
|
---|
[150] | 243 | ColourValue savedAmbient = mAmbientLight;
|
---|
| 244 |
|
---|
[159] | 245 | //-- apply standard rendering for some modes (e.g., visualization, shadow pass)
|
---|
[155] | 246 |
|
---|
[158] | 247 | if (mShowVisualization ||
|
---|
[156] | 248 | (mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE &&
|
---|
| 249 | mIlluminationStage == IRS_RENDER_TO_TEXTURE))
|
---|
[87] | 250 | {
|
---|
[139] | 251 | IlluminationRenderStage savedStage = mIlluminationStage;
|
---|
| 252 |
|
---|
[158] | 253 | if (mShowVisualization)
|
---|
| 254 | // disable illumination stage to prevent rendering shadows
|
---|
[148] | 255 | mIlluminationStage = IRS_NONE;
|
---|
| 256 |
|
---|
| 257 | // standard rendering for shadow maps because of performance
|
---|
[101] | 258 | TerrainSceneManager::_renderVisibleObjects();
|
---|
[147] | 259 |
|
---|
| 260 | mIlluminationStage = savedStage;
|
---|
[115] | 261 | }
|
---|
[159] | 262 | else //-- the hierarchical culling algorithm
|
---|
[147] | 263 | {
|
---|
[153] | 264 | // don't render backgrounds for item buffer
|
---|
| 265 | if (mUseItemBuffer)
|
---|
| 266 | {
|
---|
| 267 | clearSpecialCaseRenderQueues();
|
---|
| 268 | getRenderQueue()->clear();
|
---|
| 269 | }
|
---|
| 270 |
|
---|
[159] | 271 | //-- hierarchical culling
|
---|
[139] | 272 | // the objects of different layers (e.g., background, scene,
|
---|
| 273 | // overlay) must be identified and rendered one after another
|
---|
[115] | 274 |
|
---|
[139] | 275 | //-- render all early skies
|
---|
| 276 | clearSpecialCaseRenderQueues();
|
---|
| 277 | addSpecialCaseRenderQueue(RENDER_QUEUE_BACKGROUND);
|
---|
| 278 | addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_EARLY);
|
---|
| 279 | setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE);
|
---|
[122] | 280 |
|
---|
[139] | 281 | TerrainSceneManager::_renderVisibleObjects();
|
---|
[153] | 282 |
|
---|
[87] | 283 |
|
---|
[59] | 284 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
[159] | 285 | // delete previously rendered content
|
---|
[139] | 286 | _deleteRenderedQueueGroups();
|
---|
[59] | 287 | #endif
|
---|
| 288 |
|
---|
[139] | 289 | //-- prepare queue for visible objects (i.e., all but overlay and skies late)
|
---|
| 290 | clearSpecialCaseRenderQueues();
|
---|
| 291 | addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_LATE);
|
---|
| 292 | addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY);
|
---|
| 293 | setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
|
---|
[59] | 294 |
|
---|
[100] | 295 |
|
---|
[153] | 296 | // set all necessary parameters for
|
---|
| 297 | // hierarchical visibility culling and rendering
|
---|
[139] | 298 | InitVisibilityCulling(mCameraInProgress);
|
---|
[59] | 299 |
|
---|
[139] | 300 | /**
|
---|
| 301 | * the hierarchical culling algorithm
|
---|
[159] | 302 | * for depth pass: we just find objects and update depth buffer
|
---|
| 303 | * for "delayed" rendering: we render some passes afterwards
|
---|
| 304 | * e.g., transparents, because they need front-to-back sorting
|
---|
[139] | 305 | **/
|
---|
| 306 |
|
---|
| 307 | mVisibilityManager->ApplyVisibilityCulling();
|
---|
| 308 |
|
---|
| 309 | // delete remaining renderables from queue (all not in mLeavePassesInQueue)
|
---|
[135] | 310 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
[139] | 311 | _deleteRenderedQueueGroups(mLeavePassesInQueue);
|
---|
[135] | 312 | #endif
|
---|
[100] | 313 |
|
---|
[139] | 314 | //-- reset parameters
|
---|
| 315 | mRenderDepthPass = false;
|
---|
[153] | 316 | mRenderItemBuffer = false;
|
---|
[139] | 317 | mSkipTransparents = false;
|
---|
| 318 | mLeavePassesInQueue = 0;
|
---|
| 319 | mShadowTechnique = mSavedShadowTechnique;
|
---|
[153] | 320 |
|
---|
[139] | 321 |
|
---|
| 322 | // add visible nodes found by the visibility culling algorithm
|
---|
| 323 | if (mUseDepthPass)
|
---|
[115] | 324 | {
|
---|
[139] | 325 | for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it)
|
---|
| 326 | {
|
---|
| 327 | (*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false);
|
---|
| 328 | }
|
---|
[122] | 329 | }
|
---|
[139] | 330 |
|
---|
| 331 | //-- now we can render all remaining queue objects
|
---|
[159] | 332 | // used for depth pass, transparents, overlay
|
---|
[139] | 333 | clearSpecialCaseRenderQueues();
|
---|
| 334 | TerrainSceneManager::_renderVisibleObjects();
|
---|
[115] | 335 | }
|
---|
[139] | 336 |
|
---|
[159] | 337 | // set the new render level index
|
---|
| 338 | TerrainRenderable::NextRenderLevelIndex();
|
---|
| 339 |
|
---|
[150] | 340 | // reset ambient light
|
---|
| 341 | setAmbientLight(savedAmbient);
|
---|
[153] | 342 |
|
---|
[159] | 343 | getRenderQueue()->clear(); // finally clear render queue
|
---|
[99] | 344 | //WriteLog(); // write out stats
|
---|
[59] | 345 | }
|
---|
[122] | 346 |
|
---|
[59] | 347 | //-----------------------------------------------------------------------
|
---|
| 348 | void VisibilityTerrainSceneManager::_updateSceneGraph(Camera* cam)
|
---|
| 349 | {
|
---|
| 350 | mVisibilityManager->GetCullingManager()->SetHierarchyInterface(mHierarchyInterface);
|
---|
| 351 | mHierarchyInterface->SetRenderSystem(mDestRenderSystem);
|
---|
[74] | 352 |
|
---|
[59] | 353 | TerrainSceneManager::_updateSceneGraph(cam);
|
---|
| 354 | }
|
---|
| 355 | //-----------------------------------------------------------------------
|
---|
| 356 | bool VisibilityTerrainSceneManager::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")
|
---|
[99] | 364 | {
|
---|
| 365 | mShowVisualization = (*static_cast<const bool *>(val));
|
---|
| 366 | return true;
|
---|
| 367 | }
|
---|
[103] | 368 | if (key == "RenderNodesForViz")
|
---|
| 369 | {
|
---|
| 370 | mRenderNodesForViz = (*static_cast<const bool *>(val));
|
---|
| 371 | return true;
|
---|
| 372 | }
|
---|
[113] | 373 | if (key == "RenderNodesContentForViz")
|
---|
| 374 | {
|
---|
| 375 | mRenderNodesContentForViz = (*static_cast<const bool *>(val));
|
---|
| 376 | return true;
|
---|
| 377 | }
|
---|
[100] | 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 | }
|
---|
[112] | 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 |
|
---|
[134] | 404 | if (key == "DepthWrite")
|
---|
[133] | 405 | {
|
---|
| 406 | mEnableDepthWrite = (*static_cast<const bool *>(val));
|
---|
| 407 | return true;
|
---|
| 408 | }
|
---|
[153] | 409 | if (key == "UseItemBuffer")
|
---|
[150] | 410 | {
|
---|
[153] | 411 | mUseItemBuffer = (*static_cast<const bool *>(val));
|
---|
[150] | 412 | return true;
|
---|
| 413 | }
|
---|
[159] | 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) || TerrainSceneManager::setOption(key, val);
|
---|
[59] | 427 | }
|
---|
| 428 | //-----------------------------------------------------------------------
|
---|
| 429 | bool VisibilityTerrainSceneManager::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) && TerrainSceneManager::getOption(key, val);
|
---|
[59] | 439 | }
|
---|
| 440 | //-----------------------------------------------------------------------
|
---|
[153] | 441 | bool VisibilityTerrainSceneManager::getOptionValues(const String & key,
|
---|
| 442 | StringVector &refValueList)
|
---|
[59] | 443 | {
|
---|
[74] | 444 | return TerrainSceneManager::getOptionValues( key, refValueList);
|
---|
[59] | 445 | }
|
---|
| 446 | //-----------------------------------------------------------------------
|
---|
| 447 | bool VisibilityTerrainSceneManager::getOptionKeys(StringVector & refKeys)
|
---|
| 448 | {
|
---|
[74] | 449 | return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
|
---|
| 450 | getOptionKeys(refKeys) || TerrainSceneManager::getOptionKeys(refKeys);
|
---|
[59] | 451 | }
|
---|
| 452 | //-----------------------------------------------------------------------
|
---|
[153] | 453 | void VisibilityTerrainSceneManager::setVisibilityManager(GtpVisibility::
|
---|
| 454 | VisibilityManager *visManager)
|
---|
[59] | 455 | {
|
---|
| 456 | mVisibilityManager = visManager;
|
---|
| 457 | }
|
---|
| 458 | //-----------------------------------------------------------------------
|
---|
| 459 | GtpVisibility::VisibilityManager *VisibilityTerrainSceneManager::getVisibilityManager( void )
|
---|
| 460 | {
|
---|
| 461 | return mVisibilityManager;
|
---|
| 462 | }
|
---|
[93] | 463 | //-----------------------------------------------------------------------
|
---|
| 464 | void VisibilityTerrainSceneManager::WriteLog()
|
---|
| 465 | {
|
---|
| 466 | std::stringstream d;
|
---|
| 467 |
|
---|
[120] | 468 | d << "Depth pass: " << StringConverter::toString(mUseDepthPass) << ", "
|
---|
| 469 | << "Delay transparents: " << StringConverter::toString(mDelayRenderTransparents) << ", "
|
---|
[155] | 470 | << "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetTestGeometryForVisibleLeaves()) << ", "
|
---|
[120] | 471 | << "Algorithm type: " << mVisibilityManager->GetCullingManagerType() << ", "
|
---|
[101] | 472 | << "Hierarchy nodes: " << mNumOctreeNodes << ", "
|
---|
| 473 | << "Traversed nodes: " << mHierarchyInterface->GetNumTraversedNodes() << ", "
|
---|
[93] | 474 | << "Rendered nodes: " << mHierarchyInterface->GetNumRenderedNodes() << ", "
|
---|
| 475 | << "Query culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumQueryCulledNodes() << ", "
|
---|
| 476 | << "Frustum culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumFrustumCulledNodes() << ", "
|
---|
| 477 | << "Queries issued: " << mVisibilityManager->GetCullingManager()->GetNumQueriesIssued() << "\n";
|
---|
| 478 |
|
---|
| 479 | LogManager::getSingleton().logMessage(d.str());
|
---|
| 480 | }
|
---|
[114] | 481 | //-----------------------------------------------------------------------
|
---|
[139] | 482 | void VisibilityTerrainSceneManager::renderObjects(
|
---|
| 483 | const RenderPriorityGroup::TransparentRenderablePassList& objs,
|
---|
| 484 | bool doLightIteration, const LightList* manualLightList)
|
---|
[114] | 485 | {
|
---|
[121] | 486 | // for correct rendering, transparents must be rendered after hierarchical culling
|
---|
[115] | 487 | if (!mSkipTransparents)
|
---|
[114] | 488 | {
|
---|
| 489 | OctreeSceneManager::renderObjects(objs, doLightIteration, manualLightList);
|
---|
| 490 | }
|
---|
| 491 | }
|
---|
[121] | 492 | //-----------------------------------------------------------------------
|
---|
| 493 | bool VisibilityTerrainSceneManager::validatePassForRendering(Pass* pass)
|
---|
| 494 | {
|
---|
| 495 | // skip all but first pass if we are doing the depth pass
|
---|
[122] | 496 | if ((mRenderDepthPass || mRenderItemBuffer) && pass->getIndex() > 0)
|
---|
[121] | 497 | {
|
---|
| 498 | return false;
|
---|
| 499 | }
|
---|
| 500 | return SceneManager::validatePassForRendering(pass);
|
---|
| 501 | }
|
---|
[122] | 502 | //-----------------------------------------------------------------------
|
---|
| 503 | void VisibilityTerrainSceneManager::renderQueueGroupObjects(RenderQueueGroup* pGroup)
|
---|
| 504 | {
|
---|
| 505 | if (!mRenderItemBuffer)
|
---|
| 506 | {
|
---|
| 507 | TerrainSceneManager::renderQueueGroupObjects(pGroup);
|
---|
| 508 | return;
|
---|
| 509 | }
|
---|
[103] | 510 |
|
---|
[164] | 511 | //-- item buffer
|
---|
[156] | 512 |
|
---|
[122] | 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 VisibilityTerrainSceneManager::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 | {
|
---|
[129] | 548 | std::stringstream d; d << "itembuffer, pass name: " <<
|
---|
| 549 | ipass->first->getParent()->getParent()->getName();
|
---|
[139] | 550 |
|
---|
[129] | 551 | LogManager::getSingleton().logMessage(d.str());
|
---|
| 552 |
|
---|
[139] | 553 | RenderSingleObjectForItemBuffer(*irend, ipass->first);
|
---|
[122] | 554 | }
|
---|
| 555 | }
|
---|
| 556 |
|
---|
[159] | 557 | // -- TRANSPARENT LOOP: must be handled differently
|
---|
[122] | 558 |
|
---|
[159] | 559 | // transparents are treated either as solids or completely discarded
|
---|
| 560 | if (mRenderTransparentsForItemBuffer)
|
---|
[122] | 561 | {
|
---|
[159] | 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 | }
|
---|
[122] | 575 | }
|
---|
[159] | 576 | }
|
---|
[122] | 577 | }
|
---|
| 578 | //-----------------------------------------------------------------------
|
---|
[129] | 579 | void VisibilityTerrainSceneManager::RenderSingleObjectForItemBuffer(Renderable *rend, Pass *pass)
|
---|
[122] | 580 | {
|
---|
| 581 | static LightList nullLightList;
|
---|
[150] | 582 |
|
---|
| 583 | int col[4];
|
---|
| 584 |
|
---|
[154] | 585 | // -- create color code out of object id
|
---|
[150] | 586 | col[0] = (rend->getId() >> 16) & 255;
|
---|
| 587 | col[1] = (rend->getId() >> 8) & 255;
|
---|
| 588 | col[2] = rend->getId() & 255;
|
---|
[157] | 589 | // col[3] = 255;
|
---|
[129] | 590 |
|
---|
[150] | 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));
|
---|
[122] | 596 |
|
---|
[129] | 597 | // set vertex program of current pass
|
---|
[159] | 598 | if (mExecuteVertexProgramForAllPasses && pass->hasVertexProgram())
|
---|
[129] | 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 |
|
---|
[156] | 619 |
|
---|
[122] | 620 | // Render a single object, this will set up auto params if required
|
---|
[129] | 621 | renderSingleObject(rend, usedPass, false, &nullLightList);
|
---|
[122] | 622 | }
|
---|
| 623 | //-----------------------------------------------------------------------
|
---|
[130] | 624 | GtpVisibility::VisibilityManager *VisibilityTerrainSceneManager::GetVisibilityManager()
|
---|
[122] | 625 | {
|
---|
[130] | 626 | return mVisibilityManager;
|
---|
| 627 | }
|
---|
| 628 | //-----------------------------------------------------------------------
|
---|
[139] | 629 | void VisibilityTerrainSceneManager::InitVisibilityCulling(Camera *cam)
|
---|
| 630 | {
|
---|
| 631 | InitDepthPass(); // create material for depth pass
|
---|
| 632 | InitItemBufferPass(); // create material for item buffer pass
|
---|
[122] | 633 |
|
---|
[153] | 634 | // reset culling manager stats
|
---|
| 635 | mVisibilityManager->GetCullingManager()->InitFrame(mVisualizeCulledNodes);
|
---|
| 636 |
|
---|
[149] | 637 | // save shadow technique. It will be reset after hierarchical culling
|
---|
[139] | 638 | mSavedShadowTechnique = mShadowTechnique;
|
---|
| 639 |
|
---|
[153] | 640 | // render standard solids without shadows during hierarchical culling pass
|
---|
| 641 | if ((mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE) ||
|
---|
| 642 | (mShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE))
|
---|
[159] | 643 | {
|
---|
[153] | 644 | mShadowTechnique = SHADOWTYPE_NONE;
|
---|
| 645 | }
|
---|
[139] | 646 |
|
---|
[153] | 647 | // set depth pass flag before rendering
|
---|
| 648 | mRenderDepthPass = mUseDepthPass;
|
---|
| 649 |
|
---|
[150] | 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 |
|
---|
[159] | 658 | // set passes which are stored in render queue
|
---|
[153] | 659 | // for rendering AFTER hierarchical culling, i.e., passes which need
|
---|
| 660 | // a special rendering order
|
---|
| 661 | mLeavePassesInQueue = 0;
|
---|
[150] | 662 |
|
---|
[153] | 663 | if (!mUseDepthPass || !mUseItemBuffer)
|
---|
[139] | 664 | {
|
---|
[153] | 665 | if (mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE)
|
---|
[139] | 666 | {
|
---|
[153] | 667 | // TODO: remove this pass because it should be processed during hierarchical culling
|
---|
[139] | 668 | mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW;
|
---|
| 669 |
|
---|
| 670 | mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_DECAL;
|
---|
| 671 | mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_DIFFUSE_SPECULAR;
|
---|
| 672 | mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
|
---|
[153] | 673 |
|
---|
| 674 | // just render ambient stuff
|
---|
| 675 | mIlluminationStage = IRS_AMBIENT;
|
---|
[139] | 676 | }
|
---|
[153] | 677 |
|
---|
| 678 | if (mShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE)
|
---|
[139] | 679 | {
|
---|
| 680 | mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW;
|
---|
| 681 | mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
|
---|
| 682 | }
|
---|
[141] | 683 |
|
---|
[153] | 684 | // transparents should be rendered after hierarchical culling to
|
---|
| 685 | // provide front-to-back ordering
|
---|
| 686 | if (mDelayRenderTransparents)
|
---|
| 687 | {
|
---|
| 688 | mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
|
---|
| 689 | }
|
---|
[139] | 690 | }
|
---|
| 691 |
|
---|
[153] | 692 | // skip rendering transparents in the hierarchical culling
|
---|
| 693 | // (because they will be rendered afterwards)
|
---|
| 694 | mSkipTransparents = mUseDepthPass ||
|
---|
| 695 | (mLeavePassesInQueue & RenderPriorityGroup::TRANSPARENT_PASSES);
|
---|
| 696 |
|
---|
[155] | 697 | // -- initialise interface for rendering traversal of the hierarchy
|
---|
| 698 | mHierarchyInterface->SetHierarchyRoot(mOctree);
|
---|
| 699 |
|
---|
[139] | 700 | // possible two cameras (one for culling, one for rendering)
|
---|
[155] | 701 | mHierarchyInterface->InitTraversal(mCameraInProgress,
|
---|
| 702 | mCullCamera ? getCamera("CullCamera") : NULL,
|
---|
| 703 | mLeavePassesInQueue);
|
---|
[139] | 704 |
|
---|
[153] | 705 | //std::stringstream d; d << "leave passes in queue: " << mLeavePassesInQueue;LogManager::getSingleton().logMessage(d.str());
|
---|
[139] | 706 | }
|
---|
| 707 | //-----------------------------------------------------------------------
|
---|
[153] | 708 | OctreeHierarchyInterface *VisibilityTerrainSceneManager::GetHierarchyInterface()
|
---|
| 709 | {
|
---|
| 710 | return mHierarchyInterface;
|
---|
| 711 | }
|
---|
| 712 | //-----------------------------------------------------------------------
|
---|
[159] | 713 | void VisibilityTerrainSceneManager::endFrame()
|
---|
| 714 | {
|
---|
| 715 | TerrainRenderable::ResetRenderLevelIndex();
|
---|
| 716 | }
|
---|
| 717 | //-----------------------------------------------------------------------
|
---|
[139] | 718 | /*void VisibilityTerrainSceneManager::renderBasicQueueGroupObjects(RenderQueueGroup* pGroup)
|
---|
| 719 | {
|
---|
[153] | 720 | // Basic render loop: Iterate through priorities
|
---|
[139] | 721 | RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
|
---|
| 722 |
|
---|
| 723 | while (groupIt.hasMoreElements())
|
---|
| 724 | {
|
---|
| 725 | RenderPriorityGroup* pPriorityGrp = groupIt.getNext();
|
---|
| 726 |
|
---|
| 727 | // Sort the queue first
|
---|
| 728 | pPriorityGrp->sort(mCameraInProgress);
|
---|
| 729 |
|
---|
[153] | 730 | // Do solids
|
---|
| 731 | // TODO: render other solid passes for shadows
|
---|
[139] | 732 | renderObjects(pPriorityGrp->_getSolidPassesNoShadows(), true);
|
---|
| 733 |
|
---|
| 734 | // do solid passes no shadows if addititive stencil shadows
|
---|
| 735 | if (mSavedShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE)
|
---|
| 736 | renderObjects(pPriorityGrp->_getSolidPassesNoShadows(), true);
|
---|
| 737 |
|
---|
| 738 | // Do transparents
|
---|
| 739 | renderObjects(pPriorityGrp->_getTransparentPasses(), true);
|
---|
| 740 |
|
---|
| 741 |
|
---|
| 742 | }// for each priority
|
---|
| 743 | }
|
---|
| 744 | */
|
---|
[159] | 745 | //-----------------------------------------------------------------------
|
---|
| 746 | Entity* VisibilityTerrainSceneManager::createEntity(const String& entityName,
|
---|
| 747 | const String& meshName)
|
---|
| 748 | {
|
---|
| 749 | Entity *ent = SceneManager::createEntity(entityName, meshName);
|
---|
| 750 |
|
---|
| 751 | for (int i = 0; i < (int)ent->getNumSubEntities(); ++i)
|
---|
| 752 | {
|
---|
| 753 | ent->getSubEntity(i)->setId(mCurrentEntityId);
|
---|
[166] | 754 | //ent->getSubEntity(i)->setId((41 << 16) + (4 << 8) + 60);
|
---|
[164] | 755 | //ent->getSubEntity(i)->setId((2 << 16) + (4 << 8) + 60);
|
---|
[159] | 756 | }
|
---|
| 757 |
|
---|
| 758 | // increase counter of entity id values
|
---|
| 759 | ++ mCurrentEntityId;
|
---|
| 760 |
|
---|
| 761 | return ent;
|
---|
| 762 | }
|
---|
[59] | 763 | } // namespace Ogre
|
---|