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