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 | #include <OgreMaterialManager.h>
|
---|
12 | #include <OgreIteratorWrappers.h>
|
---|
13 | #include <OgreHeightmapTerrainPageSource.h>
|
---|
14 | #include "ViewCellsManager.h"
|
---|
15 | #include <OgreConfigFile.h>
|
---|
16 | #include "OgreTypeConverter.h"
|
---|
17 | #include "OgreMeshInstance.h"
|
---|
18 | #include "OgreBoundingBoxConverter.h"
|
---|
19 | #include <OgreManualObject.h>
|
---|
20 | #include "IntersectableWrapper.h"
|
---|
21 | #include "IVReader.h"
|
---|
22 | #include "ObjReader.h"
|
---|
23 | #include "OgreOcclusionQueriesQueryManager.h"
|
---|
24 | #include "VisibilityInfo.h"
|
---|
25 | #include "Preprocessor.h"
|
---|
26 |
|
---|
27 |
|
---|
28 | namespace Ogre {
|
---|
29 |
|
---|
30 | //-----------------------------------------------------------------------
|
---|
31 | OcclusionCullingSceneManager::OcclusionCullingSceneManager(
|
---|
32 | const String& name,
|
---|
33 | GtpVisibility::VisibilityManager *visManager):
|
---|
34 | TerrainSceneManager(name),
|
---|
35 | mVisibilityManager(visManager),
|
---|
36 | mShowVisualization(false),
|
---|
37 | mRenderNodesForViz(false),
|
---|
38 | mRenderNodesContentForViz(false),
|
---|
39 | mVisualizeCulledNodes(false),
|
---|
40 | mLeavePassesInQueue(0),
|
---|
41 | mDelayRenderTransparents(true),
|
---|
42 | mUseDepthPass(false),
|
---|
43 | mIsDepthPassPhase(false),
|
---|
44 | mUseItemBuffer(false),
|
---|
45 | mIsItemBufferPhase(false),
|
---|
46 | mCurrentEntityId(1),
|
---|
47 | mEnableDepthWrite(true),
|
---|
48 | mSkipTransparents(false),
|
---|
49 | mRenderTransparentsForItemBuffer(true),
|
---|
50 | mExecuteVertexProgramForAllPasses(false),
|
---|
51 | mIsHierarchicalCulling(false),
|
---|
52 | mViewCellsLoaded(false),
|
---|
53 | mUseViewCells(false),
|
---|
54 | mCurrentViewCell(NULL),
|
---|
55 | mDeleteQueueAfterRendering(true),
|
---|
56 | mNormalExecution(false),
|
---|
57 | mShowViewCells(false),
|
---|
58 | mViewCellsGeometryLoaded(false),
|
---|
59 | mShowTerrain(false),
|
---|
60 | mViewCellsFilename(""),
|
---|
61 | mFilename("terrain"),
|
---|
62 | mFlushRate(10),
|
---|
63 | mCurrentFrame(0),
|
---|
64 | mUseVisibilityQueries(true),
|
---|
65 | mUseFromPointQueries(false),
|
---|
66 | mQueryMode(NODE_QUERIES),
|
---|
67 | mResetMaterialForQueries(false),
|
---|
68 | mRenderPvsForViz(false)
|
---|
69 | {
|
---|
70 | Ogre::LogManager::getSingleton().
|
---|
71 | logMessage("creating occlusion culling scene manager");
|
---|
72 |
|
---|
73 | mHierarchyInterface = new OctreeHierarchyInterface(this, mDestRenderSystem);
|
---|
74 |
|
---|
75 | if (0)
|
---|
76 | {
|
---|
77 | mDisplayNodes = true;
|
---|
78 | mShowBoundingBoxes = true;
|
---|
79 | mShowBoxes = true;
|
---|
80 | }
|
---|
81 |
|
---|
82 | // set maxdepth to reasonable value
|
---|
83 | mMaxDepth = 50;
|
---|
84 |
|
---|
85 | mObjReader = new ObjReader(this);
|
---|
86 | }
|
---|
87 | //-----------------------------------------------------------------------
|
---|
88 | void OcclusionCullingSceneManager::InitDepthPass()
|
---|
89 | {
|
---|
90 | MaterialPtr depthMat =
|
---|
91 | MaterialManager::getSingleton().getByName("Visibility/DepthPass");
|
---|
92 |
|
---|
93 | if (depthMat.isNull())
|
---|
94 | {
|
---|
95 | depthMat = MaterialManager::getSingleton().create(
|
---|
96 | "Visibility/DepthPass",
|
---|
97 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
98 |
|
---|
99 | mDepthPass = depthMat->getTechnique(0)->getPass(0);
|
---|
100 | mDepthPass->setColourWriteEnabled(false);
|
---|
101 | mDepthPass->setDepthWriteEnabled(true);
|
---|
102 | mDepthPass->setLightingEnabled(false);
|
---|
103 | }
|
---|
104 | else
|
---|
105 | {
|
---|
106 | mDepthPass = depthMat->getTechnique(0)->getPass(0);
|
---|
107 | }
|
---|
108 | }
|
---|
109 | //-----------------------------------------------------------------------
|
---|
110 | OcclusionCullingSceneManager::~OcclusionCullingSceneManager()
|
---|
111 | {
|
---|
112 | CLEAR_CONTAINER(mObjects);
|
---|
113 | OGRE_DELETE(mHierarchyInterface);
|
---|
114 | OGRE_DELETE(mObjReader);
|
---|
115 | }
|
---|
116 | //-----------------------------------------------------------------------
|
---|
117 | void OcclusionCullingSceneManager::InitItemBufferPass()
|
---|
118 | {
|
---|
119 | MaterialPtr itemBufferMat = MaterialManager::getSingleton().
|
---|
120 | getByName("Visibility/ItemBufferPass");
|
---|
121 |
|
---|
122 | if (itemBufferMat.isNull())
|
---|
123 | {
|
---|
124 | // Init
|
---|
125 | itemBufferMat =
|
---|
126 | MaterialManager::getSingleton().create("Visibility/ItemBufferPass",
|
---|
127 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
128 |
|
---|
129 | mItemBufferPass = itemBufferMat->getTechnique(0)->getPass(0);
|
---|
130 | mItemBufferPass->setColourWriteEnabled(true);
|
---|
131 | mItemBufferPass->setDepthWriteEnabled(true);
|
---|
132 | mItemBufferPass->setLightingEnabled(true);
|
---|
133 | //mItemBufferPass->setLightingEnabled(false);
|
---|
134 | }
|
---|
135 | else
|
---|
136 | {
|
---|
137 | mItemBufferPass = itemBufferMat->getTechnique(0)->getPass(0);
|
---|
138 | }
|
---|
139 | //mItemBufferPass->setAmbient(1, 1, 0);
|
---|
140 | }
|
---|
141 | //-------------------------------------------------------------------------
|
---|
142 | #if 1
|
---|
143 | void OcclusionCullingSceneManager::setWorldGeometry(DataStreamPtr& stream,
|
---|
144 | const String& typeName)
|
---|
145 | {
|
---|
146 | // Clear out any existing world resources (if not default)
|
---|
147 | if (ResourceGroupManager::getSingleton().getWorldResourceGroupName() !=
|
---|
148 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME)
|
---|
149 | {
|
---|
150 | ResourceGroupManager::getSingleton().clearResourceGroup(
|
---|
151 | ResourceGroupManager::getSingleton().getWorldResourceGroupName());
|
---|
152 | }
|
---|
153 |
|
---|
154 | destroyLevelIndexes();
|
---|
155 | mTerrainPages.clear();
|
---|
156 |
|
---|
157 | // Load the configuration
|
---|
158 | loadConfig(stream);
|
---|
159 |
|
---|
160 | //////////////
|
---|
161 | // file loading
|
---|
162 |
|
---|
163 | // load the scene
|
---|
164 | LoadScene(mFilename, mViewCellsFilename);
|
---|
165 |
|
---|
166 | if (mShowTerrain)
|
---|
167 | {
|
---|
168 | initLevelIndexes();
|
---|
169 |
|
---|
170 | // Resize the octree, allow for 1 page for now
|
---|
171 | float max_x = mOptions.scale.x * mOptions.pageSize;
|
---|
172 | float max_y = mOptions.scale.y;// * mOptions.pageSize;
|
---|
173 | float max_z = mOptions.scale.z * mOptions.pageSize;
|
---|
174 |
|
---|
175 | if (1)
|
---|
176 | {
|
---|
177 | // keep octree equal at all sides so nodes adapt better to small objects
|
---|
178 | float maxAxis = std::max(max_x, max_y);
|
---|
179 | maxAxis = std::max(maxAxis, max_z);
|
---|
180 | resize(AxisAlignedBox( 0, 0, 0, maxAxis, maxAxis, maxAxis));
|
---|
181 | }
|
---|
182 | else
|
---|
183 | {
|
---|
184 | resize(AxisAlignedBox( 0, 0, 0, max_x, max_y, max_z));
|
---|
185 | }
|
---|
186 |
|
---|
187 | setupTerrainMaterial();
|
---|
188 | setupTerrainPages();
|
---|
189 | }
|
---|
190 | }
|
---|
191 | #endif
|
---|
192 |
|
---|
193 | //-------------------------------------------------------------------------
|
---|
194 | void OcclusionCullingSceneManager::loadConfig(DataStreamPtr& stream)
|
---|
195 | {
|
---|
196 | // Set up the options
|
---|
197 | ConfigFile config;
|
---|
198 | String val;
|
---|
199 |
|
---|
200 | config.load(stream);
|
---|
201 |
|
---|
202 | LogManager::getSingleton().logMessage("****** OcclusionCullingSceneManager Options ********");
|
---|
203 |
|
---|
204 | val = config.getSetting("DepthPass");
|
---|
205 |
|
---|
206 | if (!val.empty())
|
---|
207 | {
|
---|
208 | if ( val == "yes" )
|
---|
209 | mUseDepthPass = true;
|
---|
210 | else
|
---|
211 | mUseDepthPass = false;
|
---|
212 | }
|
---|
213 |
|
---|
214 | val = config.getSetting("ExecuteVertexProgramForDepth");
|
---|
215 |
|
---|
216 | if (!val.empty())
|
---|
217 | {
|
---|
218 | if ( val == "yes" )
|
---|
219 | mExecuteVertexProgramForAllPasses = true;
|
---|
220 | else
|
---|
221 | mExecuteVertexProgramForAllPasses = false;
|
---|
222 | }
|
---|
223 |
|
---|
224 | val = config.getSetting("UseVisibilityQueries");
|
---|
225 |
|
---|
226 | if (!val.empty())
|
---|
227 | {
|
---|
228 | if ( val == "yes" )
|
---|
229 | mUseVisibilityQueries = true;
|
---|
230 | else
|
---|
231 | mUseVisibilityQueries = false;
|
---|
232 | }
|
---|
233 |
|
---|
234 | val = config.getSetting("UseFromPointQueries");
|
---|
235 |
|
---|
236 | if (!val.empty())
|
---|
237 | {
|
---|
238 | if (val == "yes")
|
---|
239 | mUseFromPointQueries = true;
|
---|
240 | else
|
---|
241 | mUseFromPointQueries = false;
|
---|
242 | }
|
---|
243 |
|
---|
244 | val = config.getSetting("QueryObjectsMode");
|
---|
245 |
|
---|
246 | if (!val.empty())
|
---|
247 | {
|
---|
248 | if (val == "EXACT")
|
---|
249 | mQueryMode = EXACT_QUERIES;
|
---|
250 | else if (val == "NODE")
|
---|
251 | mQueryMode = NODE_QUERIES;
|
---|
252 | else
|
---|
253 | mQueryMode = APPROXIMATE_QUERIES;
|
---|
254 | }
|
---|
255 |
|
---|
256 | val = config.getSetting("ResetMaterialForQueries");
|
---|
257 |
|
---|
258 | if (!val.empty())
|
---|
259 | {
|
---|
260 | if (val == "yes")
|
---|
261 | mResetMaterialForQueries = true;
|
---|
262 | else
|
---|
263 | mResetMaterialForQueries = false;
|
---|
264 | }
|
---|
265 |
|
---|
266 | val = config.getSetting("FlushQueue");
|
---|
267 |
|
---|
268 | if (!val.empty())
|
---|
269 | {
|
---|
270 | if ( val == "yes" )
|
---|
271 | mDeleteQueueAfterRendering = true;
|
---|
272 | else
|
---|
273 | mDeleteQueueAfterRendering = false;
|
---|
274 | }
|
---|
275 |
|
---|
276 | val = config.getSetting("Scene");
|
---|
277 |
|
---|
278 | if (!val.empty())
|
---|
279 | {
|
---|
280 | mFilename = val.c_str();
|
---|
281 |
|
---|
282 | // load terrain instead of scene
|
---|
283 | if (mFilename == "terrain")
|
---|
284 | {
|
---|
285 | mShowTerrain = true;
|
---|
286 | LogManager::getSingleton().logMessage("scene: loading terrain");
|
---|
287 | }
|
---|
288 | else
|
---|
289 | {
|
---|
290 | mShowTerrain = false;
|
---|
291 | LogManager::getSingleton().logMessage("scene: loading geometry");
|
---|
292 | }
|
---|
293 | }
|
---|
294 |
|
---|
295 | if (!mShowTerrain)
|
---|
296 | {
|
---|
297 | val = config.getSetting("ViewCells");
|
---|
298 |
|
---|
299 | if (!val.empty())
|
---|
300 | {
|
---|
301 | mViewCellsFilename = val;
|
---|
302 | }
|
---|
303 | }
|
---|
304 |
|
---|
305 | /////////////
|
---|
306 | val = config.getSetting("OnlineCullingAlgorithm");
|
---|
307 |
|
---|
308 | if (!val.empty())
|
---|
309 | {
|
---|
310 | GtpVisibility::VisibilityEnvironment::CullingManagerType algorithm;
|
---|
311 |
|
---|
312 | if (val == "CHC")
|
---|
313 | {
|
---|
314 | algorithm =
|
---|
315 | GtpVisibility::VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING;
|
---|
316 | LogManager::getSingleton().logMessage("Using chc algorithm");
|
---|
317 | }
|
---|
318 | else if (val == "SWC")
|
---|
319 | {
|
---|
320 | algorithm =
|
---|
321 | GtpVisibility::VisibilityEnvironment::STOP_AND_WAIT_CULLING;
|
---|
322 |
|
---|
323 | LogManager::getSingleton().logMessage("Using stop and wait algorithm");
|
---|
324 | }
|
---|
325 | else if (val == "RUC")
|
---|
326 | {
|
---|
327 | algorithm =
|
---|
328 | GtpVisibility::VisibilityEnvironment::RANDOM_UPDATE_CULLING;
|
---|
329 |
|
---|
330 | LogManager::getSingleton().logMessage("Using random update culling");
|
---|
331 | }
|
---|
332 | else if (val == "VFC")
|
---|
333 | {
|
---|
334 | algorithm =
|
---|
335 | GtpVisibility::VisibilityEnvironment::FRUSTUM_CULLING;
|
---|
336 |
|
---|
337 | LogManager::getSingleton().logMessage("Using frustum culling algorithm");
|
---|
338 | }
|
---|
339 | else // default rendering
|
---|
340 | {
|
---|
341 | algorithm =
|
---|
342 | GtpVisibility::VisibilityEnvironment::NUM_CULLING_MANAGERS;
|
---|
343 |
|
---|
344 | mNormalExecution = true;
|
---|
345 | LogManager::getSingleton().logMessage("Using default octree scene manager rendering");
|
---|
346 | }
|
---|
347 |
|
---|
348 | mVisibilityManager->SetCullingManager(algorithm);
|
---|
349 | }
|
---|
350 |
|
---|
351 | /////////////
|
---|
352 | val = config.getSetting("TestGeometryForVisibleLeaves");
|
---|
353 |
|
---|
354 | if (!val.empty())
|
---|
355 | {
|
---|
356 | if (val == "yes")
|
---|
357 | mVisibilityManager->SetTestGeometryForVisibleLeaves(true);
|
---|
358 | else
|
---|
359 | mVisibilityManager->SetTestGeometryForVisibleLeaves(false);
|
---|
360 | }
|
---|
361 |
|
---|
362 | /////////////
|
---|
363 | val = config.getSetting("TestGeometryBounds");
|
---|
364 |
|
---|
365 | if (!val.empty())
|
---|
366 | {
|
---|
367 | if (val == "yes")
|
---|
368 | mHierarchyInterface->SetTestGeometryBounds(true);
|
---|
369 | else
|
---|
370 | mHierarchyInterface->SetTestGeometryBounds(false);
|
---|
371 | }
|
---|
372 |
|
---|
373 | /////////////
|
---|
374 | val = config.getSetting("AssumedVisibleFrames");
|
---|
375 |
|
---|
376 | if (!val.empty())
|
---|
377 | {
|
---|
378 | mVisibilityManager->SetAssumedVisibilityForChc(atoi(val.c_str()));
|
---|
379 | }
|
---|
380 |
|
---|
381 |
|
---|
382 | /////////////
|
---|
383 | val = config.getSetting("RandomUpdateCandidates");
|
---|
384 |
|
---|
385 | if (!val.empty())
|
---|
386 | {
|
---|
387 | mVisibilityManager->SetRandomUpdateCandidatesForRuc(atoi(val.c_str()));
|
---|
388 | }
|
---|
389 |
|
---|
390 |
|
---|
391 | /////////////
|
---|
392 | // output
|
---|
393 |
|
---|
394 | if (mUseDepthPass)
|
---|
395 | LogManager::getSingleton().logMessage("using depth pass");
|
---|
396 | else
|
---|
397 | LogManager::getSingleton().logMessage("not using depth pass");
|
---|
398 |
|
---|
399 | if (mExecuteVertexProgramForAllPasses)
|
---|
400 | LogManager::getSingleton().logMessage("executing vertex program for passes");
|
---|
401 | else
|
---|
402 | LogManager::getSingleton().logMessage("not executing vertex program for passes");
|
---|
403 |
|
---|
404 | if (mUseVisibilityQueries)
|
---|
405 | LogManager::getSingleton().logMessage("using visibility queries");
|
---|
406 | else
|
---|
407 | LogManager::getSingleton().logMessage("not using visibility queries");
|
---|
408 |
|
---|
409 | if (mUseFromPointQueries)
|
---|
410 | LogManager::getSingleton().logMessage("using from point queries");
|
---|
411 | else
|
---|
412 | LogManager::getSingleton().logMessage("not using from point queries");
|
---|
413 |
|
---|
414 | if (mQueryMode == EXACT_QUERIES)
|
---|
415 | LogManager::getSingleton().logMessage("using exact queries");
|
---|
416 | else if (mQueryMode == NODE_QUERIES)
|
---|
417 | LogManager::getSingleton().logMessage("using node queries");
|
---|
418 | else if (mQueryMode == APPROXIMATE_QUERIES)
|
---|
419 | LogManager::getSingleton().logMessage("using approximate queries");
|
---|
420 |
|
---|
421 | if (mResetMaterialForQueries)
|
---|
422 | LogManager::getSingleton().logMessage("resetting material for queries");
|
---|
423 | else
|
---|
424 | LogManager::getSingleton().logMessage("resetting material for queries");
|
---|
425 |
|
---|
426 | if (mDeleteQueueAfterRendering)
|
---|
427 | LogManager::getSingleton().logMessage("flushing queue after some frames");
|
---|
428 | else
|
---|
429 | LogManager::getSingleton().logMessage("not flushing queue after some frames");
|
---|
430 |
|
---|
431 | if (mVisibilityManager->GetTestGeometryForVisibleLeaves())
|
---|
432 | LogManager::getSingleton().logMessage("test geometry for visible leaves");
|
---|
433 | else
|
---|
434 | LogManager::getSingleton().logMessage("not testing geometry for visible leaves");
|
---|
435 |
|
---|
436 | if (mHierarchyInterface->GetTestGeometryBounds())
|
---|
437 | LogManager::getSingleton().logMessage("test geometry bounds instead of bounding box");
|
---|
438 | else
|
---|
439 | LogManager::getSingleton().logMessage("not testing geometry bounds instead of bounding box");
|
---|
440 |
|
---|
441 |
|
---|
442 | /////////////
|
---|
443 | // terrain options
|
---|
444 |
|
---|
445 | if (!mShowTerrain)
|
---|
446 | return;
|
---|
447 |
|
---|
448 | val = config.getSetting("DetailTile");
|
---|
449 | if (!val.empty())
|
---|
450 | setDetailTextureRepeat(atoi(val.c_str()));
|
---|
451 |
|
---|
452 | val = config.getSetting("MaxMipMapLevel");
|
---|
453 | if (!val.empty())
|
---|
454 | setMaxGeoMipMapLevel(atoi(val.c_str()));
|
---|
455 |
|
---|
456 |
|
---|
457 | val = config.getSetting("PageSize");
|
---|
458 | if (!val.empty())
|
---|
459 | setPageSize(atoi(val.c_str()));
|
---|
460 | else
|
---|
461 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Missing option 'PageSize'",
|
---|
462 | "TerrainSceneManager::loadConfig");
|
---|
463 |
|
---|
464 |
|
---|
465 | val = config.getSetting("TileSize");
|
---|
466 | if (!val.empty())
|
---|
467 | setTileSize(atoi(val.c_str()));
|
---|
468 | else
|
---|
469 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Missing option 'TileSize'",
|
---|
470 | "TerrainSceneManager::loadConfig");
|
---|
471 |
|
---|
472 | Vector3 v = Vector3::UNIT_SCALE;
|
---|
473 |
|
---|
474 | val = config.getSetting( "PageWorldX" );
|
---|
475 | if ( !val.empty() )
|
---|
476 | v.x = atof( val.c_str() );
|
---|
477 |
|
---|
478 | val = config.getSetting( "MaxHeight" );
|
---|
479 | if ( !val.empty() )
|
---|
480 | v.y = atof( val.c_str() );
|
---|
481 |
|
---|
482 | val = config.getSetting( "PageWorldZ" );
|
---|
483 | if ( !val.empty() )
|
---|
484 | v.z = atof( val.c_str() );
|
---|
485 |
|
---|
486 | // Scale x/z relative to pagesize
|
---|
487 | v.x /= mOptions.pageSize;
|
---|
488 | v.z /= mOptions.pageSize;
|
---|
489 | setScale(v);
|
---|
490 |
|
---|
491 | val = config.getSetting( "MaxPixelError" );
|
---|
492 | if ( !val.empty() )
|
---|
493 | setMaxPixelError(atoi( val.c_str() ));
|
---|
494 |
|
---|
495 | mDetailTextureName = config.getSetting( "DetailTexture" );
|
---|
496 |
|
---|
497 | mWorldTextureName = config.getSetting( "WorldTexture" );
|
---|
498 |
|
---|
499 | if ( config.getSetting( "VertexColours" ) == "yes" )
|
---|
500 | mOptions.coloured = true;
|
---|
501 |
|
---|
502 | if ( config.getSetting( "VertexNormals" ) == "yes" )
|
---|
503 | mOptions.lit = true;
|
---|
504 |
|
---|
505 | if ( config.getSetting( "UseTriStrips" ) == "yes" )
|
---|
506 | setUseTriStrips(true);
|
---|
507 |
|
---|
508 | if ( config.getSetting( "VertexProgramMorph" ) == "yes" )
|
---|
509 | setUseLODMorph(true);
|
---|
510 |
|
---|
511 | val = config.getSetting( "LODMorphStart");
|
---|
512 | if ( !val.empty() )
|
---|
513 | setLODMorphStart(atof(val.c_str()));
|
---|
514 |
|
---|
515 | val = config.getSetting( "CustomMaterialName" );
|
---|
516 | if ( !val.empty() )
|
---|
517 | setCustomMaterial(val);
|
---|
518 |
|
---|
519 | val = config.getSetting( "MorphLODFactorParamName" );
|
---|
520 | if ( !val.empty() )
|
---|
521 | setCustomMaterialMorphFactorParam(val);
|
---|
522 |
|
---|
523 | val = config.getSetting( "MorphLODFactorParamIndex" );
|
---|
524 | if ( !val.empty() )
|
---|
525 | setCustomMaterialMorphFactorParam(atoi(val.c_str()));
|
---|
526 |
|
---|
527 | // Now scan through the remaining settings, looking for any PageSource
|
---|
528 | // prefixed items
|
---|
529 | String pageSourceName = config.getSetting("PageSource");
|
---|
530 | if (pageSourceName == "")
|
---|
531 | {
|
---|
532 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Missing option 'PageSource'",
|
---|
533 | "TerrainSceneManager::loadConfig");
|
---|
534 | }
|
---|
535 |
|
---|
536 | TerrainPageSourceOptionList optlist;
|
---|
537 | ConfigFile::SettingsIterator setIt = config.getSettingsIterator();
|
---|
538 | while (setIt.hasMoreElements())
|
---|
539 | {
|
---|
540 | String name = setIt.peekNextKey();
|
---|
541 | String value = setIt.getNext();
|
---|
542 | if (StringUtil::startsWith(name, pageSourceName, false))
|
---|
543 | {
|
---|
544 | optlist.push_back(TerrainPageSourceOption(name, value));
|
---|
545 | }
|
---|
546 | }
|
---|
547 |
|
---|
548 | // set the page source
|
---|
549 | selectPageSource(pageSourceName, optlist);
|
---|
550 |
|
---|
551 |
|
---|
552 | LogManager::getSingleton().logMessage("****** OcclusionCullingSceneManager Options Finished ********");
|
---|
553 | }
|
---|
554 | //-----------------------------------------------------------------------
|
---|
555 | void OcclusionCullingSceneManager::MailPvsObjects()
|
---|
556 | {
|
---|
557 | GtpVisibilityPreprocessor::ObjectPvsIterator pit =
|
---|
558 | mCurrentViewCell->GetPvs().GetIterator();
|
---|
559 |
|
---|
560 | while (pit.HasMoreEntries())
|
---|
561 | {
|
---|
562 | GtpVisibilityPreprocessor::Intersectable *obj = pit.Next();
|
---|
563 |
|
---|
564 | if (obj->Type() !=
|
---|
565 | GtpVisibilityPreprocessor::Intersectable::ENGINE_INTERSECTABLE)
|
---|
566 | continue;
|
---|
567 |
|
---|
568 | EngineIntersectable *oi = static_cast<EngineIntersectable *>(obj);
|
---|
569 |
|
---|
570 | EntityContainer *entries = oi->GetItem();
|
---|
571 | EntityContainer::const_iterator eit, eit_end = entries->end();
|
---|
572 |
|
---|
573 | for (eit = entries->begin(); eit != eit_end; ++ eit)
|
---|
574 | {
|
---|
575 | (*eit)->setUserAny(Any((int)0));
|
---|
576 | }
|
---|
577 | }
|
---|
578 | }
|
---|
579 | //-----------------------------------------------------------------------
|
---|
580 | void OcclusionCullingSceneManager::ShowViewCellsGeometry()
|
---|
581 | {
|
---|
582 | #if TODO
|
---|
583 | // show only current view cell
|
---|
584 | if (!mShowViewCells)
|
---|
585 | {
|
---|
586 | const int id = mCurrentViewCell->GetId();
|
---|
587 |
|
---|
588 | MovableMap::iterator fit = mViewCellsGeometry.find(id);
|
---|
589 |
|
---|
590 | if ((fit != mViewCellsGeometry.end()) && (*fit).second)
|
---|
591 | (*fit).second->_updateRenderQueue(getRenderQueue());
|
---|
592 | }
|
---|
593 | else
|
---|
594 | {
|
---|
595 | MovableMap::const_iterator mit, mit_end = mViewCellsGeometry.end();
|
---|
596 |
|
---|
597 | for (mit = mViewCellsGeometry.begin(); mit != mit_end; ++ mit)
|
---|
598 | {
|
---|
599 | if ((*mit).second)
|
---|
600 | (*mit).second->_updateRenderQueue(getRenderQueue());
|
---|
601 | }
|
---|
602 | }
|
---|
603 | #endif
|
---|
604 | }
|
---|
605 | //-----------------------------------------------------------------------
|
---|
606 | void OcclusionCullingSceneManager::RenderPvsEntry(GtpVisibilityPreprocessor::Intersectable *obj)
|
---|
607 | {
|
---|
608 | switch (obj->Type())
|
---|
609 | {
|
---|
610 | case GtpVisibilityPreprocessor::Intersectable::OGRE_MESH_INSTANCE:
|
---|
611 | {
|
---|
612 | OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(obj);
|
---|
613 | omi->GetEntity()->_updateRenderQueue(getRenderQueue());
|
---|
614 | }
|
---|
615 | break;
|
---|
616 |
|
---|
617 | case GtpVisibilityPreprocessor::Intersectable::ENGINE_INTERSECTABLE:
|
---|
618 | {
|
---|
619 | EngineIntersectable *oi = static_cast<EngineIntersectable *>(obj);
|
---|
620 |
|
---|
621 | EntityContainer *entries = oi->GetItem();
|
---|
622 | EntityContainer::const_iterator eit, eit_end = entries->end();
|
---|
623 |
|
---|
624 | for (eit = entries->begin(); eit != eit_end; ++ eit)
|
---|
625 | {
|
---|
626 | Entity *ent = *eit;
|
---|
627 | // mailing hack
|
---|
628 | Any newAny = ent->getUserAny();
|
---|
629 | int flt = any_cast<int>(newAny);
|
---|
630 |
|
---|
631 | if (any_cast<int>(newAny) == 0)
|
---|
632 | {
|
---|
633 | ent->setUserAny(Any((int)1));
|
---|
634 | ent->_updateRenderQueue(getRenderQueue());
|
---|
635 | }
|
---|
636 | }
|
---|
637 | }
|
---|
638 | break;
|
---|
639 | default:
|
---|
640 | break;
|
---|
641 | }
|
---|
642 | }
|
---|
643 | //-----------------------------------------------------------------------
|
---|
644 | void OcclusionCullingSceneManager::SetObjectVisible(GtpVisibilityPreprocessor::Intersectable *entry,
|
---|
645 | const bool visible)
|
---|
646 | {
|
---|
647 | switch (entry->Type())
|
---|
648 | {
|
---|
649 | case GtpVisibilityPreprocessor::Intersectable::OGRE_MESH_INSTANCE:
|
---|
650 | {
|
---|
651 | OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(entry);
|
---|
652 | omi->GetEntity()->setVisible(visible);
|
---|
653 | //GtpVisibilityPreprocessor::Debug << "assigned id " << omi->GetId() << endl;
|
---|
654 | }
|
---|
655 | break;
|
---|
656 | case GtpVisibilityPreprocessor::Intersectable::ENGINE_INTERSECTABLE:
|
---|
657 | {
|
---|
658 | EngineIntersectable *oi = static_cast<EngineIntersectable *>(entry);
|
---|
659 |
|
---|
660 | EntityContainer *entries = oi->GetItem();
|
---|
661 | EntityContainer::const_iterator eit, eit_end = entries->end();
|
---|
662 | for (eit = entries->begin(); eit != eit_end; ++ eit)
|
---|
663 | {
|
---|
664 | Entity *ent = *eit;
|
---|
665 | ent->setVisible(visible);
|
---|
666 | }
|
---|
667 | }
|
---|
668 | break;
|
---|
669 | default:
|
---|
670 | break;
|
---|
671 | }
|
---|
672 | }
|
---|
673 | //-----------------------------------------------------------------------
|
---|
674 | void OcclusionCullingSceneManager::PrepareVisualization(Camera *cam)
|
---|
675 | {
|
---|
676 | // add player camera for visualization purpose
|
---|
677 | try
|
---|
678 | {
|
---|
679 | Camera *c;
|
---|
680 | if ((c = getCamera("PlayerCam")) != NULL)
|
---|
681 | {
|
---|
682 | getRenderQueue()->addRenderable(c);
|
---|
683 | }
|
---|
684 | }
|
---|
685 | catch (...)
|
---|
686 | {
|
---|
687 | // ignore
|
---|
688 | }
|
---|
689 |
|
---|
690 | if (mRenderPvsForViz)
|
---|
691 | {
|
---|
692 | // show current view cell geometry
|
---|
693 | if (mCurrentViewCell)
|
---|
694 | {
|
---|
695 | //const bool showSingleViewCell = true;
|
---|
696 | if (mViewCellsGeometryLoaded)
|
---|
697 | {
|
---|
698 | ShowViewCellsGeometry();
|
---|
699 | }
|
---|
700 |
|
---|
701 | //////////
|
---|
702 | //-- set PVS of view cell visible
|
---|
703 |
|
---|
704 | GtpVisibilityPreprocessor::ObjectPvsIterator pit =
|
---|
705 | mCurrentViewCell->GetPvs().GetIterator();
|
---|
706 |
|
---|
707 | MailPvsObjects();
|
---|
708 |
|
---|
709 | while (pit.HasMoreEntries())
|
---|
710 | {
|
---|
711 | RenderPvsEntry(pit.Next());
|
---|
712 | }
|
---|
713 | }
|
---|
714 | }
|
---|
715 | else
|
---|
716 | {
|
---|
717 | // add bounding boxes of rendered objects
|
---|
718 | if (1)
|
---|
719 | {
|
---|
720 | for (BoxList::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it)
|
---|
721 | {
|
---|
722 | getRenderQueue()->addRenderable(*it);
|
---|
723 | }
|
---|
724 | }
|
---|
725 | if (mRenderNodesForViz || mRenderNodesContentForViz)
|
---|
726 | {
|
---|
727 | // HACK: change node material so it is better suited for visualization
|
---|
728 | MaterialPtr nodeMat = MaterialManager::getSingleton().getByName("Core/NodeMaterial");
|
---|
729 | nodeMat->setAmbient(1, 1, 0);
|
---|
730 | nodeMat->setLightingEnabled(true);
|
---|
731 | nodeMat->getTechnique(0)->getPass(0)->removeAllTextureUnitStates();
|
---|
732 |
|
---|
733 | for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it)
|
---|
734 | {
|
---|
735 | if (mRenderNodesForViz)
|
---|
736 | {
|
---|
737 | // render the visible leaf nodes
|
---|
738 | if ((*it)->numAttachedObjects() &&
|
---|
739 | !(*it)->numChildren() &&
|
---|
740 | ((*it)->getAttachedObject(0)->getMovableType() == "Entity") &&
|
---|
741 | (*it)->getAttachedObject(0)->isVisible())
|
---|
742 | {
|
---|
743 | getRenderQueue()->addRenderable((*it));
|
---|
744 | //(*it)->_addToRenderQueue(cam, getRenderQueue(), false);
|
---|
745 | }
|
---|
746 |
|
---|
747 | // render bounding boxes of nodes
|
---|
748 | if (0) (*it)->_addBoundingBoxToQueue(getRenderQueue());
|
---|
749 | }
|
---|
750 |
|
---|
751 | // add renderables itself
|
---|
752 | if (mRenderNodesContentForViz)
|
---|
753 | {
|
---|
754 | (*it)->_addToRenderQueue(cam, getRenderQueue(), false);
|
---|
755 | }
|
---|
756 | }
|
---|
757 | }
|
---|
758 | }
|
---|
759 | }
|
---|
760 | //-----------------------------------------------------------------------
|
---|
761 | const Pass *OcclusionCullingSceneManager::_setPass(const Pass* pass, bool evenIfSuppressed)
|
---|
762 | {
|
---|
763 | if (mNormalExecution)
|
---|
764 | {
|
---|
765 | return TerrainSceneManager::_setPass(pass, evenIfSuppressed);
|
---|
766 | }
|
---|
767 |
|
---|
768 | // problem: setting vertex program is not efficient
|
---|
769 | //Pass *usedPass = ((mIsDepthPassPhase && !pass->hasVertexProgram()) ? mDepthPass : pass);
|
---|
770 |
|
---|
771 | // set depth fill pass if we currently do not make an aabb occlusion query
|
---|
772 | const bool useDepthPass =
|
---|
773 | mUseDepthPass && mIsDepthPassPhase && !mHierarchyInterface->IsBoundingBoxQuery();
|
---|
774 |
|
---|
775 | const IlluminationRenderStage savedStage = mIlluminationStage;
|
---|
776 |
|
---|
777 | if (useDepthPass)
|
---|
778 | {
|
---|
779 | // set illumination stage to NONE so no shadow material is used
|
---|
780 | // for depth pass or for occlusion query
|
---|
781 | if (mIsDepthPassPhase || mHierarchyInterface->IsBoundingBoxQuery())
|
---|
782 | {
|
---|
783 | mIlluminationStage = IRS_NONE;
|
---|
784 | }
|
---|
785 |
|
---|
786 | //////////////////
|
---|
787 | //-- set vertex program of current pass in order to set correct depth
|
---|
788 | if (mExecuteVertexProgramForAllPasses &&
|
---|
789 | mIsDepthPassPhase &&
|
---|
790 | pass->hasVertexProgram())
|
---|
791 | {
|
---|
792 | // add vertex program of current pass to depth pass
|
---|
793 | mDepthPass->setVertexProgram(pass->getVertexProgramName());
|
---|
794 |
|
---|
795 | if (mDepthPass->hasVertexProgram())
|
---|
796 | {
|
---|
797 | const GpuProgramPtr& prg = mDepthPass->getVertexProgram();
|
---|
798 | // Load this program if not done already
|
---|
799 | if (!prg->isLoaded())
|
---|
800 | prg->load();
|
---|
801 | // Copy params
|
---|
802 | mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters());
|
---|
803 | }
|
---|
804 | }
|
---|
805 | else if (mDepthPass->hasVertexProgram())
|
---|
806 | { // reset vertex program
|
---|
807 | mDepthPass->setVertexProgram("");
|
---|
808 | }
|
---|
809 | }
|
---|
810 |
|
---|
811 | // using depth pass instead
|
---|
812 | const Pass *usedPass = useDepthPass ? mDepthPass : pass;
|
---|
813 |
|
---|
814 | #if 0 // tmp matt: pass is now const
|
---|
815 | // save old depth write: needed for item buffer
|
---|
816 | const bool isDepthWrite = usedPass->getDepthWriteEnabled();
|
---|
817 |
|
---|
818 | // global option which enables / disables depth writes
|
---|
819 | if (!mEnableDepthWrite)
|
---|
820 | usedPass->setDepthWriteEnabled(false);
|
---|
821 | #endif
|
---|
822 |
|
---|
823 | ///////////////
|
---|
824 | //-- set actual pass here
|
---|
825 |
|
---|
826 | const Pass *result = SceneManager::_setPass(usedPass, evenIfSuppressed);
|
---|
827 |
|
---|
828 |
|
---|
829 | // reset depth write
|
---|
830 | #if 0 // tmp matt: this is now a const function
|
---|
831 | if (!mEnableDepthWrite)
|
---|
832 | usedPass->setDepthWriteEnabled(isDepthWrite);
|
---|
833 | #endif
|
---|
834 | // reset illumination stage
|
---|
835 | mIlluminationStage = savedStage;
|
---|
836 |
|
---|
837 | return result;
|
---|
838 | }
|
---|
839 | //-----------------------------------------------------------------------
|
---|
840 | void OcclusionCullingSceneManager::myFindVisibleObjects(Camera* cam,
|
---|
841 | bool onlyShadowCasters)
|
---|
842 | {
|
---|
843 | if (mShowVisualization)
|
---|
844 | {
|
---|
845 | //////////////
|
---|
846 | //-- show visible scene nodes and octree bounding boxes from last frame
|
---|
847 |
|
---|
848 | PrepareVisualization(cam);
|
---|
849 |
|
---|
850 | // lists only used for visualization
|
---|
851 | mVisible.clear();
|
---|
852 | mBoxes.clear();
|
---|
853 |
|
---|
854 | return;
|
---|
855 | }
|
---|
856 |
|
---|
857 | ///////////
|
---|
858 | //-- set visibility according to pvs of current view cell
|
---|
859 |
|
---|
860 | UpdatePvs(cam);
|
---|
861 |
|
---|
862 | // standard rendering in first pass
|
---|
863 | // hierarchical culling interleaves identification
|
---|
864 | // and rendering of objects in _renderVisibibleObjects
|
---|
865 |
|
---|
866 | // for the shadow pass we use only standard rendering
|
---|
867 | // because shadows have low occlusion anyway
|
---|
868 | if ((mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE &&
|
---|
869 | mIlluminationStage == IRS_RENDER_TO_TEXTURE) ||
|
---|
870 | mNormalExecution)
|
---|
871 | {
|
---|
872 | TerrainSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
|
---|
873 | }
|
---|
874 | else if (mUseDepthPass)
|
---|
875 | {
|
---|
876 | mVisible.clear();
|
---|
877 | mBoxes.clear();
|
---|
878 | // clear render queue before depth pass
|
---|
879 | getRenderQueue()->clear();
|
---|
880 |
|
---|
881 | // render scene once in order to fill depth buffer
|
---|
882 | RenderHierarchicalCulling();
|
---|
883 | }
|
---|
884 | }
|
---|
885 | //-----------------------------------------------------------------------
|
---|
886 | void OcclusionCullingSceneManager::_renderVisibleObjects()
|
---|
887 | {
|
---|
888 | if (mNormalExecution)
|
---|
889 | {
|
---|
890 | // the standard octree rendering mode
|
---|
891 | TerrainSceneManager::_renderVisibleObjects();
|
---|
892 | //getRenderQueue()->clear(flushQueue);
|
---|
893 | return;
|
---|
894 | }
|
---|
895 |
|
---|
896 | // clear render queue
|
---|
897 | // fully reset it after some frames
|
---|
898 | const bool flushQueue =
|
---|
899 | mDeleteQueueAfterRendering && ((mCurrentFrame % mFlushRate) == 0);
|
---|
900 |
|
---|
901 | ++ mCurrentFrame;
|
---|
902 |
|
---|
903 | // create material for item buffer pass
|
---|
904 | InitItemBufferPass();
|
---|
905 |
|
---|
906 | // save ambient light to reset later
|
---|
907 | ColourValue savedAmbient = mAmbientLight;
|
---|
908 |
|
---|
909 | ////////////////////
|
---|
910 | //-- apply standard rendering for some modes
|
---|
911 | //-- (e.g., the visualization mode, the shadow pass)
|
---|
912 |
|
---|
913 | // also go here if find visible object is disabled
|
---|
914 | // (then the render queue is already filled)
|
---|
915 | if (!mFindVisibleObjects ||
|
---|
916 | mUseDepthPass || mShowVisualization ||
|
---|
917 | (mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE &&
|
---|
918 | mIlluminationStage == IRS_RENDER_TO_TEXTURE))
|
---|
919 | {
|
---|
920 | IlluminationRenderStage savedStage = mIlluminationStage;
|
---|
921 |
|
---|
922 | if (mShowVisualization)
|
---|
923 | // disable illumination stage to prevent rendering shadows
|
---|
924 | mIlluminationStage = IRS_NONE;
|
---|
925 |
|
---|
926 | // standard rendering for shadow maps because of performance
|
---|
927 | TerrainSceneManager::_renderVisibleObjects();
|
---|
928 |
|
---|
929 | mIlluminationStage = savedStage;
|
---|
930 | }
|
---|
931 | else //-- the hierarchical culling algorithm
|
---|
932 | {
|
---|
933 | // note matt: this is also called in TerrainSceneManager: really necessary?
|
---|
934 | mDestRenderSystem->setLightingEnabled(false);
|
---|
935 |
|
---|
936 | if (mUseItemBuffer)
|
---|
937 | {
|
---|
938 | // don't render backgrounds for item buffer
|
---|
939 | clearSpecialCaseRenderQueues();
|
---|
940 | getRenderQueue()->clear();
|
---|
941 | }
|
---|
942 |
|
---|
943 | ////////////////////
|
---|
944 | //-- hierarchical culling
|
---|
945 |
|
---|
946 | // the objects of different layers (e.g., background, scene,
|
---|
947 | // overlay) must be identified and rendered one after another
|
---|
948 |
|
---|
949 | // first render all early skies
|
---|
950 | clearSpecialCaseRenderQueues();
|
---|
951 | addSpecialCaseRenderQueue(RENDER_QUEUE_BACKGROUND);
|
---|
952 | addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_EARLY);
|
---|
953 | setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE);
|
---|
954 |
|
---|
955 | TerrainSceneManager::_renderVisibleObjects();
|
---|
956 |
|
---|
957 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
958 | // delete previously rendered content
|
---|
959 | _deleteRenderedQueueGroups();
|
---|
960 | #endif
|
---|
961 |
|
---|
962 | ///////////////////
|
---|
963 | //-- prepare queue for visible objects (i.e., all but overlay and skies late)
|
---|
964 |
|
---|
965 | clearSpecialCaseRenderQueues();
|
---|
966 | addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_LATE);
|
---|
967 | addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY);
|
---|
968 |
|
---|
969 | // exclude these queues from hierarchical rendering
|
---|
970 | setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
|
---|
971 |
|
---|
972 | // set all necessary parameters for
|
---|
973 | // hierarchical visibility culling and rendering
|
---|
974 | InitVisibilityCulling(mCameraInProgress);
|
---|
975 |
|
---|
976 |
|
---|
977 | /**
|
---|
978 | * the hierarchical culling algorithm
|
---|
979 | * for depth pass: we just find objects and update depth buffer
|
---|
980 | * for "delayed" rendering: we render some passes afterwards
|
---|
981 | * e.g., transparents, because they need front-to-back sorting
|
---|
982 | **/
|
---|
983 |
|
---|
984 | mVisibilityManager->ApplyVisibilityCulling();
|
---|
985 |
|
---|
986 | // delete remaining renderables from queue:
|
---|
987 | // all which are not in mLeavePassesInQueue)
|
---|
988 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
989 | _deleteRenderedQueueGroups(mLeavePassesInQueue);
|
---|
990 | #endif
|
---|
991 |
|
---|
992 | /////////////
|
---|
993 | //-- reset parameters needed during hierarchical rendering
|
---|
994 |
|
---|
995 | mIsItemBufferPhase = false;
|
---|
996 | mSkipTransparents = false;
|
---|
997 | mIsHierarchicalCulling = false;
|
---|
998 |
|
---|
999 | mLeavePassesInQueue = 0;
|
---|
1000 |
|
---|
1001 | /////////////
|
---|
1002 | //-- now we can render all remaining queue objects
|
---|
1003 | //-- used for depth pass, transparents, overlay
|
---|
1004 |
|
---|
1005 | clearSpecialCaseRenderQueues();
|
---|
1006 |
|
---|
1007 | TerrainSceneManager::_renderVisibleObjects();
|
---|
1008 | } // end hierarchical culling
|
---|
1009 |
|
---|
1010 | // HACK: set the new render level index, important to avoid cracks
|
---|
1011 | // in terrain caused by LOD
|
---|
1012 | TerrainRenderable::NextRenderLevelIndex();
|
---|
1013 |
|
---|
1014 | // reset ambient light
|
---|
1015 | setAmbientLight(savedAmbient);
|
---|
1016 |
|
---|
1017 | // remove rest from queue
|
---|
1018 | getRenderQueue()->clear(flushQueue);
|
---|
1019 |
|
---|
1020 | if (0) WriteLog(); // write out stats
|
---|
1021 | }
|
---|
1022 | //-----------------------------------------------------------------------
|
---|
1023 | void OcclusionCullingSceneManager::_updateSceneGraph(Camera* cam)
|
---|
1024 | {
|
---|
1025 | if (!mNormalExecution)
|
---|
1026 | {
|
---|
1027 | mVisibilityManager->GetCullingManager()->SetHierarchyInterface(mHierarchyInterface);
|
---|
1028 | mHierarchyInterface->SetRenderSystem(mDestRenderSystem);
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 | TerrainSceneManager::_updateSceneGraph(cam);
|
---|
1032 | }
|
---|
1033 | //-----------------------------------------------------------------------
|
---|
1034 | bool OcclusionCullingSceneManager::setOption(const String & key, const void * val)
|
---|
1035 | {
|
---|
1036 | if (key == "UseDepthPass")
|
---|
1037 | {
|
---|
1038 | mUseDepthPass = (*static_cast<const bool *>(val));
|
---|
1039 | return true;
|
---|
1040 | }
|
---|
1041 | if (key == "PrepareVisualization")
|
---|
1042 | {
|
---|
1043 | mShowVisualization = (*static_cast<const bool *>(val));
|
---|
1044 | return true;
|
---|
1045 | }
|
---|
1046 | if (key == "RenderNodesForViz")
|
---|
1047 | {
|
---|
1048 | mRenderNodesForViz = (*static_cast<const bool *>(val));
|
---|
1049 | return true;
|
---|
1050 | }
|
---|
1051 | if (key == "RenderNodesContentForViz")
|
---|
1052 | {
|
---|
1053 | mRenderNodesContentForViz = (*static_cast<const bool *>(val));
|
---|
1054 | return true;
|
---|
1055 | }
|
---|
1056 | if (key == "RenderPvsForViz")
|
---|
1057 | {
|
---|
1058 | mRenderPvsForViz = (*static_cast<const bool *>(val));
|
---|
1059 | return true;
|
---|
1060 | }
|
---|
1061 | if (key == "SkyBoxEnabled")
|
---|
1062 | {
|
---|
1063 | mSkyBoxEnabled = (*static_cast<const bool *>(val));
|
---|
1064 | return true;
|
---|
1065 | }
|
---|
1066 | if (key == "SkyPlaneEnabled")
|
---|
1067 | {
|
---|
1068 | mSkyPlaneEnabled = (*static_cast<const bool *>(val));
|
---|
1069 | return true;
|
---|
1070 | }
|
---|
1071 | if (key == "SkyDomeEnabled")
|
---|
1072 | {
|
---|
1073 | mSkyDomeEnabled = (*static_cast<const bool *>(val));
|
---|
1074 | return true;
|
---|
1075 | }
|
---|
1076 | if (key == "VisualizeCulledNodes")
|
---|
1077 | {
|
---|
1078 | mVisualizeCulledNodes = (*static_cast<const bool *>(val));
|
---|
1079 | return true;
|
---|
1080 | }
|
---|
1081 | if (key == "DelayRenderTransparents")
|
---|
1082 | {
|
---|
1083 | mDelayRenderTransparents = (*static_cast<const bool *>(val));
|
---|
1084 | return true;
|
---|
1085 | }
|
---|
1086 | if (key == "DepthWrite")
|
---|
1087 | {
|
---|
1088 | mEnableDepthWrite = (*static_cast<const bool *>(val));
|
---|
1089 | return true;
|
---|
1090 | }
|
---|
1091 | if (key == "UseItemBuffer")
|
---|
1092 | {
|
---|
1093 | mUseItemBuffer = (*static_cast<const bool *>(val));
|
---|
1094 | return true;
|
---|
1095 | }
|
---|
1096 | if (key == "ExecuteVertexProgramForAllPasses")
|
---|
1097 | {
|
---|
1098 | mExecuteVertexProgramForAllPasses = (*static_cast<const bool *>(val));
|
---|
1099 | return true;
|
---|
1100 | }
|
---|
1101 | if (key == "RenderTransparentsForItemBuffer")
|
---|
1102 | {
|
---|
1103 | mRenderTransparentsForItemBuffer = (*static_cast<const bool *>(val));
|
---|
1104 | return true;
|
---|
1105 | }
|
---|
1106 | else if (key == "FlushQueue")
|
---|
1107 | {
|
---|
1108 | mDeleteQueueAfterRendering = (*static_cast<const bool *>(val));
|
---|
1109 | return true;
|
---|
1110 | }
|
---|
1111 | if (key == "NodeVizScale")
|
---|
1112 | {
|
---|
1113 | OctreeNode::setVizScale(*static_cast<const float *>(val));
|
---|
1114 | return true;
|
---|
1115 | }
|
---|
1116 | if (key == "UseViewCells")
|
---|
1117 | {
|
---|
1118 | bool useViewCells = *static_cast<const bool *>(val);
|
---|
1119 |
|
---|
1120 | if (useViewCells && !mViewCellsLoaded)
|
---|
1121 | {
|
---|
1122 | // try to load view cells
|
---|
1123 | mViewCellsLoaded = LoadViewCells(mViewCellsFilename);
|
---|
1124 |
|
---|
1125 | if (!mViewCellsLoaded)
|
---|
1126 | // something went wrong => bail out
|
---|
1127 | return false;
|
---|
1128 | }
|
---|
1129 |
|
---|
1130 | // only use this option if view cells are available
|
---|
1131 | mUseViewCells = useViewCells;
|
---|
1132 |
|
---|
1133 | // reset current view cell
|
---|
1134 | mCurrentViewCell = NULL;
|
---|
1135 |
|
---|
1136 | // if we don't use the view cells, all objects are set to invisible per default
|
---|
1137 | //SetObjectsVisible(!mUseViewCells);
|
---|
1138 |
|
---|
1139 | // note: this sets the objects invisible which are not in the pvs ...
|
---|
1140 | MovableObjectIterator movit = getMovableObjectIterator("Entity");
|
---|
1141 | while (movit.hasMoreElements())
|
---|
1142 | {
|
---|
1143 | Entity *ent = static_cast<Entity *>(movit.getNext());
|
---|
1144 | ent->setVisible(!mUseViewCells);
|
---|
1145 | }
|
---|
1146 |
|
---|
1147 | return true;
|
---|
1148 | }
|
---|
1149 | if (key == "ShowViewCells")
|
---|
1150 | {
|
---|
1151 | // only use this option if view cells are available
|
---|
1152 | if (mViewCellsLoaded)
|
---|
1153 | {
|
---|
1154 | mShowViewCells = *static_cast<const bool *>(val);
|
---|
1155 | // if we decide use view cells
|
---|
1156 | // all objects are set to invisible per default
|
---|
1157 | VisualizeViewCells(mShowViewCells);
|
---|
1158 | }
|
---|
1159 |
|
---|
1160 | return true;
|
---|
1161 | }
|
---|
1162 | if (key == "NormalExecution")
|
---|
1163 | {
|
---|
1164 | mNormalExecution = *static_cast<const bool *>(val);
|
---|
1165 | return true;
|
---|
1166 | }
|
---|
1167 | if (key == "ShowTerrain")
|
---|
1168 | {
|
---|
1169 | mShowTerrain = *static_cast<const bool *>(val);
|
---|
1170 | return true;
|
---|
1171 | }
|
---|
1172 | if (key == "UseVisibilityQueries")
|
---|
1173 | {
|
---|
1174 | mUseVisibilityQueries = *static_cast<const bool *>(val);
|
---|
1175 | return true;
|
---|
1176 | }
|
---|
1177 | if (key == "UseFromPointQueries")
|
---|
1178 | {
|
---|
1179 | mUseFromPointQueries = *static_cast<const bool *>(val);
|
---|
1180 | return true;
|
---|
1181 | }
|
---|
1182 | if (key == "QueryMode")
|
---|
1183 | {
|
---|
1184 | mQueryMode = *static_cast<const int *>(val);
|
---|
1185 | return true;
|
---|
1186 | }
|
---|
1187 | if (key == "ResetMaterialForQueries")
|
---|
1188 | {
|
---|
1189 | mResetMaterialForQueries = *static_cast<const bool *>(val);
|
---|
1190 | }
|
---|
1191 | if (key == "UseFromPointQueries")
|
---|
1192 | {
|
---|
1193 | mUseFromPointQueries = *static_cast<const bool *>(val);
|
---|
1194 | return true;
|
---|
1195 | }
|
---|
1196 |
|
---|
1197 | return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
|
---|
1198 | setOption(key, val) || TerrainSceneManager::setOption(key, val);
|
---|
1199 | }
|
---|
1200 | //-----------------------------------------------------------------------
|
---|
1201 | bool OcclusionCullingSceneManager::getOption(const String &key, void *val)
|
---|
1202 | {
|
---|
1203 | if (key == "NumHierarchyNodes")
|
---|
1204 | {
|
---|
1205 | * static_cast<unsigned int *>(val) = (unsigned int)mNumOctants;
|
---|
1206 | return true;
|
---|
1207 | }
|
---|
1208 | if (key == "VisibilityManager")
|
---|
1209 | {
|
---|
1210 | * static_cast<GtpVisibility::VisibilityManager **>(val) = mVisibilityManager;
|
---|
1211 | return true;
|
---|
1212 | }
|
---|
1213 | if (key == "HierarchyInterface")
|
---|
1214 | {
|
---|
1215 | * static_cast<PlatformHierarchyInterface **>(val) = mHierarchyInterface;
|
---|
1216 | return true;
|
---|
1217 | }
|
---|
1218 | if (key == "ShowTerrain")
|
---|
1219 | {
|
---|
1220 | * static_cast<bool *>(val) = mShowTerrain;
|
---|
1221 | return true;
|
---|
1222 | }
|
---|
1223 | if (key == "UseDepthPass")
|
---|
1224 | {
|
---|
1225 | * static_cast<bool *>(val) = mUseDepthPass;
|
---|
1226 | return true;
|
---|
1227 | }
|
---|
1228 | if (key == "FlushQueue")
|
---|
1229 | {
|
---|
1230 | * static_cast<bool *>(val) = mDeleteQueueAfterRendering;
|
---|
1231 | return true;
|
---|
1232 | }
|
---|
1233 | if (key == "NormalExecution")
|
---|
1234 | {
|
---|
1235 | * static_cast<bool *>(val) = mNormalExecution;
|
---|
1236 | return true;
|
---|
1237 | }
|
---|
1238 | if (key == "Algorithm")
|
---|
1239 | {
|
---|
1240 | GtpVisibility::VisibilityEnvironment::CullingManagerType algorithm =
|
---|
1241 | mVisibilityManager->GetCullingManagerType();
|
---|
1242 |
|
---|
1243 | * static_cast<unsigned int *>(val) = (unsigned int)algorithm;
|
---|
1244 |
|
---|
1245 | return true;
|
---|
1246 | }
|
---|
1247 |
|
---|
1248 | if (key == "VisibleObjects")
|
---|
1249 | {
|
---|
1250 | if (mNormalExecution)
|
---|
1251 | return false;
|
---|
1252 |
|
---|
1253 | const bool fromPoint = false;
|
---|
1254 | const bool nodeVisibility = true;
|
---|
1255 |
|
---|
1256 | * static_cast<unsigned int *>(val) =
|
---|
1257 | (unsigned int)QueryVisibleObjectsExact(mCameraInProgress,
|
---|
1258 | mCurrentViewport,
|
---|
1259 | fromPoint,
|
---|
1260 | nodeVisibility);
|
---|
1261 | return true;
|
---|
1262 | }
|
---|
1263 |
|
---|
1264 | return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
|
---|
1265 | getOption(key, val) && TerrainSceneManager::getOption(key, val);
|
---|
1266 | }
|
---|
1267 | //-----------------------------------------------------------------------
|
---|
1268 | bool OcclusionCullingSceneManager::getOptionValues(const String & key,
|
---|
1269 | StringVector &refValueList)
|
---|
1270 | {
|
---|
1271 | return TerrainSceneManager::getOptionValues( key, refValueList);
|
---|
1272 | }
|
---|
1273 | //-----------------------------------------------------------------------
|
---|
1274 | bool OcclusionCullingSceneManager::getOptionKeys(StringVector & refKeys)
|
---|
1275 | {
|
---|
1276 | return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
|
---|
1277 | getOptionKeys(refKeys) || TerrainSceneManager::getOptionKeys(refKeys);
|
---|
1278 | }
|
---|
1279 | //-----------------------------------------------------------------------
|
---|
1280 | void OcclusionCullingSceneManager::setVisibilityManager(GtpVisibility::
|
---|
1281 | VisibilityManager *visManager)
|
---|
1282 | {
|
---|
1283 | mVisibilityManager = visManager;
|
---|
1284 | }
|
---|
1285 | //-----------------------------------------------------------------------
|
---|
1286 | GtpVisibility::VisibilityManager *OcclusionCullingSceneManager::getVisibilityManager( void )
|
---|
1287 | {
|
---|
1288 | return mVisibilityManager;
|
---|
1289 | }
|
---|
1290 | //-----------------------------------------------------------------------
|
---|
1291 | void OcclusionCullingSceneManager::WriteLog()
|
---|
1292 | {
|
---|
1293 | std::stringstream d;
|
---|
1294 |
|
---|
1295 | d << "Depth pass: " << StringConverter::toString(mUseDepthPass) << ", "
|
---|
1296 | << "Delay transparents: " << StringConverter::toString(mDelayRenderTransparents) << ", "
|
---|
1297 | // << "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetTestGeometryForVisibleLeaves()) << ", "
|
---|
1298 | << "Algorithm type: " << mVisibilityManager->GetCullingManagerType() << ", "
|
---|
1299 | << "Hierarchy nodes: " << mNumOctants << ", "
|
---|
1300 | << "Traversed nodes: " << mHierarchyInterface->GetNumTraversedNodes() << ", "
|
---|
1301 | << "Rendered nodes: " << mHierarchyInterface->GetNumRenderedNodes() << ", "
|
---|
1302 | << "Query culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumQueryCulledNodes() << ", "
|
---|
1303 | << "Frustum culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumFrustumCulledNodes() << ", "
|
---|
1304 | << "Queries issued: " << mVisibilityManager->GetCullingManager()->GetNumQueriesIssued() << ", "
|
---|
1305 | << "Found objects: " << (int)mVisible.size() << "\n";
|
---|
1306 |
|
---|
1307 | LogManager::getSingleton().logMessage(d.str());
|
---|
1308 | }
|
---|
1309 | //-----------------------------------------------------------------------
|
---|
1310 | void OcclusionCullingSceneManager::renderBasicQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
1311 | QueuedRenderableCollection::OrganisationMode om)
|
---|
1312 | {
|
---|
1313 | if (mNormalExecution)
|
---|
1314 | {
|
---|
1315 | return TerrainSceneManager::renderBasicQueueGroupObjects(pGroup, om);
|
---|
1316 | }
|
---|
1317 |
|
---|
1318 | // Basic render loop
|
---|
1319 | // Iterate through priorities
|
---|
1320 | RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
|
---|
1321 |
|
---|
1322 | while (groupIt.hasMoreElements())
|
---|
1323 | {
|
---|
1324 | RenderPriorityGroup* pPriorityGrp = groupIt.getNext();
|
---|
1325 |
|
---|
1326 | // Sort the queue first
|
---|
1327 | pPriorityGrp->sort(mCameraInProgress);
|
---|
1328 |
|
---|
1329 | // Do solids
|
---|
1330 | renderObjects(pPriorityGrp->getSolidsBasic(), om, true);
|
---|
1331 |
|
---|
1332 | // for correct rendering, transparents must be rendered
|
---|
1333 | // after hierarchical culling => don't render them now
|
---|
1334 |
|
---|
1335 | if (!mSkipTransparents)
|
---|
1336 | {
|
---|
1337 | // Do transparents (always descending)
|
---|
1338 | renderObjects(pPriorityGrp->getTransparents(),
|
---|
1339 | QueuedRenderableCollection::OM_SORT_DESCENDING, true);
|
---|
1340 | }
|
---|
1341 | } // for each priority
|
---|
1342 | }
|
---|
1343 | //-----------------------------------------------------------------------
|
---|
1344 | bool OcclusionCullingSceneManager::validatePassForRendering(Pass* pass)
|
---|
1345 | {
|
---|
1346 | if (mNormalExecution)
|
---|
1347 | {
|
---|
1348 | return TerrainSceneManager::validatePassForRendering(pass);
|
---|
1349 | }
|
---|
1350 |
|
---|
1351 | // skip all but first pass if we are doing the depth pass
|
---|
1352 | if ((mIsDepthPassPhase || mIsItemBufferPhase) &&
|
---|
1353 | (pass->getIndex() > 0))
|
---|
1354 | {
|
---|
1355 | return false;
|
---|
1356 | }
|
---|
1357 | // all but first pass
|
---|
1358 | /*else if ((!mIsDepthPassPhase || mIsItemBufferPhase) && (pass->getIndex() != 0))
|
---|
1359 | {
|
---|
1360 | return false;
|
---|
1361 | }*/
|
---|
1362 |
|
---|
1363 | return SceneManager::validatePassForRendering(pass);
|
---|
1364 | }
|
---|
1365 | //-----------------------------------------------------------------------
|
---|
1366 | void OcclusionCullingSceneManager::_renderQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
1367 | QueuedRenderableCollection::OrganisationMode om)
|
---|
1368 | {
|
---|
1369 | if (mNormalExecution || !mIsItemBufferPhase)
|
---|
1370 | {
|
---|
1371 | TerrainSceneManager::_renderQueueGroupObjects(pGroup, om);
|
---|
1372 | return;
|
---|
1373 | }
|
---|
1374 |
|
---|
1375 | #ifdef ITEM_BUFFER
|
---|
1376 |
|
---|
1377 | ///////////////////
|
---|
1378 | //-- item buffer: render objects using false colors
|
---|
1379 |
|
---|
1380 | // Iterate through priorities
|
---|
1381 | RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
|
---|
1382 |
|
---|
1383 | while (groupIt.hasMoreElements())
|
---|
1384 | {
|
---|
1385 | RenderItemBuffer(groupIt.getNext());
|
---|
1386 | }
|
---|
1387 | #endif // ITEM_BUFFER
|
---|
1388 | }
|
---|
1389 | #ifdef ITEM_BUFFER
|
---|
1390 | //-----------------------------------------------------------------------
|
---|
1391 | void OcclusionCullingSceneManager::RenderItemBuffer(RenderPriorityGroup* pGroup)
|
---|
1392 | {
|
---|
1393 | // Do solids
|
---|
1394 | QueuedRenderableCollection solidObjs = pGroup->getSolidsBasic();//msz
|
---|
1395 |
|
---|
1396 | // ----- SOLIDS LOOP -----
|
---|
1397 | RenderPriorityGroup::SolidRenderablePassMap::const_iterator ipass, ipassend;
|
---|
1398 | ipassend = solidObjs.end();
|
---|
1399 |
|
---|
1400 | for (ipass = solidObjs.begin(); ipass != ipassend; ++ipass)
|
---|
1401 | {
|
---|
1402 | // Fast bypass if this group is now empty
|
---|
1403 | if (ipass->second->empty())
|
---|
1404 | continue;
|
---|
1405 |
|
---|
1406 | // Render only first pass of renderable as false color
|
---|
1407 | if (ipass->first->getIndex() > 0)
|
---|
1408 | continue;
|
---|
1409 |
|
---|
1410 | RenderPriorityGroup::RenderableList* rendList = ipass->second;
|
---|
1411 |
|
---|
1412 | RenderPriorityGroup::RenderableList::const_iterator irend, irendend;
|
---|
1413 | irendend = rendList->end();
|
---|
1414 |
|
---|
1415 | for (irend = rendList->begin(); irend != irendend; ++irend)
|
---|
1416 | {
|
---|
1417 | if (0)
|
---|
1418 | {
|
---|
1419 | std::stringstream d; d << "itembuffer, pass name: " <<
|
---|
1420 | ipass->first->getParent()->getParent()->getName();
|
---|
1421 |
|
---|
1422 | LogManager::getSingleton().logMessage(d.str());
|
---|
1423 | }
|
---|
1424 |
|
---|
1425 | RenderSingleObjectForItemBuffer(*irend, ipass->first);
|
---|
1426 | }
|
---|
1427 | }
|
---|
1428 |
|
---|
1429 | ///////////
|
---|
1430 | //-- TRANSPARENT LOOP: must be handled differently from solids
|
---|
1431 |
|
---|
1432 | // transparents are treated either as solids or completely discarded
|
---|
1433 | if (mRenderTransparentsForItemBuffer)
|
---|
1434 | {
|
---|
1435 | QueuedRenderableCollection transpObjs = pGroup->getTransparents(); //msz
|
---|
1436 | RenderPriorityGroup::TransparentRenderablePassList::const_iterator
|
---|
1437 | itrans, itransend;
|
---|
1438 |
|
---|
1439 | itransend = transpObjs.end();
|
---|
1440 | for (itrans = transpObjs.begin(); itrans != itransend; ++itrans)
|
---|
1441 | {
|
---|
1442 | // like for solids, render only first pass
|
---|
1443 | if (itrans->pass->getIndex() == 0)
|
---|
1444 | {
|
---|
1445 | RenderSingleObjectForItemBuffer(itrans->renderable, itrans->pass);
|
---|
1446 | }
|
---|
1447 | }
|
---|
1448 | }
|
---|
1449 | }
|
---|
1450 | //-----------------------------------------------------------------------
|
---|
1451 | void OcclusionCullingSceneManager::RenderSingleObjectForItemBuffer(Renderable *rend, Pass *pass)
|
---|
1452 | {
|
---|
1453 | static LightList nullLightList;
|
---|
1454 |
|
---|
1455 | int col[4];
|
---|
1456 |
|
---|
1457 | // -- create color code out of object id
|
---|
1458 | col[0] = (rend->getId() >> 16) & 255;
|
---|
1459 | col[1] = (rend->getId() >> 8) & 255;
|
---|
1460 | col[2] = rend->getId() & 255;
|
---|
1461 | // col[3] = 255;
|
---|
1462 |
|
---|
1463 | //mDestRenderSystem->setColour(col[0], col[1], col[2], col[3]);
|
---|
1464 |
|
---|
1465 | mItemBufferPass->setAmbient(ColourValue(col[0] / 255.0f,
|
---|
1466 | col[1] / 255.0f,
|
---|
1467 | col[2] / 255.0f, 1));
|
---|
1468 |
|
---|
1469 | // set vertex program of current pass
|
---|
1470 | if (mExecuteVertexProgramForAllPasses && pass->hasVertexProgram())
|
---|
1471 | {
|
---|
1472 | mItemBufferPass->setVertexProgram(pass->getVertexProgramName());
|
---|
1473 |
|
---|
1474 | if (mItemBufferPass->hasVertexProgram())
|
---|
1475 | {
|
---|
1476 | const GpuProgramPtr& prg = mItemBufferPass->getVertexProgram();
|
---|
1477 | // Load this program if not done already
|
---|
1478 | if (!prg->isLoaded())
|
---|
1479 | prg->load();
|
---|
1480 | // Copy params
|
---|
1481 | mItemBufferPass->setVertexProgramParameters(pass->getVertexProgramParameters());
|
---|
1482 | }
|
---|
1483 | }
|
---|
1484 | else if (mItemBufferPass->hasVertexProgram())
|
---|
1485 | {
|
---|
1486 | mItemBufferPass->setVertexProgram("");
|
---|
1487 | }
|
---|
1488 |
|
---|
1489 | const Pass *usedPass = _setPass(mItemBufferPass);
|
---|
1490 |
|
---|
1491 |
|
---|
1492 | // render a single object, this will set up auto params if required
|
---|
1493 | renderSingleObject(rend, usedPass, false, &nullLightList);
|
---|
1494 | }
|
---|
1495 | #endif // ITEM_BUFFER
|
---|
1496 | //-----------------------------------------------------------------------
|
---|
1497 | GtpVisibility::VisibilityManager *OcclusionCullingSceneManager::GetVisibilityManager()
|
---|
1498 | {
|
---|
1499 | return mVisibilityManager;
|
---|
1500 | }
|
---|
1501 | //-----------------------------------------------------------------------
|
---|
1502 | void OcclusionCullingSceneManager::InitVisibilityCulling(Camera *cam)
|
---|
1503 | {
|
---|
1504 | // reset culling manager stats
|
---|
1505 | mVisibilityManager->GetCullingManager()->InitFrame(mVisualizeCulledNodes);
|
---|
1506 |
|
---|
1507 | // set depth pass flag before rendering
|
---|
1508 | mIsDepthPassPhase = mUseDepthPass;
|
---|
1509 |
|
---|
1510 | // indicates that we use hierarchical culling from now on
|
---|
1511 | mIsHierarchicalCulling = true;
|
---|
1512 |
|
---|
1513 | // item buffer needs full ambient lighting to use item colors as unique id
|
---|
1514 | if (mUseItemBuffer)
|
---|
1515 | {
|
---|
1516 | mIsItemBufferPhase = true;
|
---|
1517 | setAmbientLight(ColourValue(1,1,1,1));
|
---|
1518 | }
|
---|
1519 |
|
---|
1520 |
|
---|
1521 | // set passes which are stored in render queue
|
---|
1522 | // for rendering AFTER hierarchical culling, i.e., passes which need
|
---|
1523 | // a special rendering order
|
---|
1524 |
|
---|
1525 | mLeavePassesInQueue = 0;
|
---|
1526 |
|
---|
1527 | // if we have the depth pass or use an item buffer, we leave no passes in the queue
|
---|
1528 | if (!mUseDepthPass && !mUseItemBuffer)
|
---|
1529 | {
|
---|
1530 | if (mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE)
|
---|
1531 | {
|
---|
1532 | // TODO: remove this pass because it should be processed during hierarchical culling
|
---|
1533 | //mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW;
|
---|
1534 |
|
---|
1535 | mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_DECAL;
|
---|
1536 | mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_DIFFUSE_SPECULAR;
|
---|
1537 | mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
|
---|
1538 |
|
---|
1539 | // just render ambient passes
|
---|
1540 | /*** msz: no more IRS_AMBIENT, see OgreSceneManager.h ***/
|
---|
1541 | // mIlluminationStage = IRS_AMBIENT;
|
---|
1542 | //getRenderQueue()->setSplitPassesByLightingType(true);
|
---|
1543 | }
|
---|
1544 |
|
---|
1545 | if (mShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE)
|
---|
1546 | {
|
---|
1547 | mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW;
|
---|
1548 | mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
|
---|
1549 | }
|
---|
1550 |
|
---|
1551 | // transparents should be rendered after hierarchical culling to
|
---|
1552 | // provide front-to-back ordering
|
---|
1553 | if (mDelayRenderTransparents)
|
---|
1554 | {
|
---|
1555 | mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
|
---|
1556 | }
|
---|
1557 | }
|
---|
1558 |
|
---|
1559 | // skip rendering transparents during the hierarchical culling
|
---|
1560 | // (because they will be rendered afterwards)
|
---|
1561 | mSkipTransparents =
|
---|
1562 | (mIsDepthPassPhase || (mLeavePassesInQueue & RenderPriorityGroup::TRANSPARENT_PASSES));
|
---|
1563 |
|
---|
1564 | // -- initialise interface for rendering traversal of the hierarchy
|
---|
1565 | mHierarchyInterface->SetHierarchyRoot(mOctree);
|
---|
1566 |
|
---|
1567 | // possible two cameras (one for culling, one for rendering)
|
---|
1568 | mHierarchyInterface->InitTraversal(cam,
|
---|
1569 | mCullCamera ? getCamera("CullCamera") : NULL,
|
---|
1570 | mLeavePassesInQueue);
|
---|
1571 |
|
---|
1572 | }
|
---|
1573 | //-----------------------------------------------------------------------
|
---|
1574 | OctreeHierarchyInterface *OcclusionCullingSceneManager::GetHierarchyInterface()
|
---|
1575 | {
|
---|
1576 | return mHierarchyInterface;
|
---|
1577 | }
|
---|
1578 | //-----------------------------------------------------------------------
|
---|
1579 | void OcclusionCullingSceneManager::endFrame()
|
---|
1580 | {
|
---|
1581 | TerrainRenderable::ResetRenderLevelIndex();
|
---|
1582 | }
|
---|
1583 | //-----------------------------------------------------------------------
|
---|
1584 | Entity* OcclusionCullingSceneManager::createEntity(const String& entityName,
|
---|
1585 | const String& meshName)
|
---|
1586 | {
|
---|
1587 | Entity *ent = SceneManager::createEntity(entityName, meshName);
|
---|
1588 |
|
---|
1589 | for (int i = 0; i < (int)ent->getNumSubEntities(); ++i)
|
---|
1590 | {
|
---|
1591 | ent->getSubEntity(i)->setId(mCurrentEntityId);
|
---|
1592 | }
|
---|
1593 |
|
---|
1594 | // increase counter of entity id values
|
---|
1595 | ++ mCurrentEntityId;
|
---|
1596 |
|
---|
1597 | return ent;
|
---|
1598 | }
|
---|
1599 | //-----------------------------------------------------------------------
|
---|
1600 | void OcclusionCullingSceneManager::renderAdditiveStencilShadowedQueueGroupObjects(
|
---|
1601 | RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om)
|
---|
1602 | {
|
---|
1603 | if (mNormalExecution || !mIsHierarchicalCulling)
|
---|
1604 | {
|
---|
1605 | // render the rest of the passes
|
---|
1606 | TerrainSceneManager::renderAdditiveStencilShadowedQueueGroupObjects(pGroup, om);
|
---|
1607 | return;
|
---|
1608 | }
|
---|
1609 |
|
---|
1610 | // only render solid passes during hierarchical culling
|
---|
1611 | RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
|
---|
1612 | LightList lightList;
|
---|
1613 |
|
---|
1614 | while (groupIt.hasMoreElements())
|
---|
1615 | {
|
---|
1616 | RenderPriorityGroup* pPriorityGrp = groupIt.getNext();
|
---|
1617 |
|
---|
1618 | // Sort the queue first
|
---|
1619 | pPriorityGrp->sort(mCameraInProgress);
|
---|
1620 |
|
---|
1621 | // Clear light list
|
---|
1622 | lightList.clear();
|
---|
1623 |
|
---|
1624 | // Render all the ambient passes first, no light iteration, no lights
|
---|
1625 | /*** msz: no more IRS_AMBIENT, see OgreSceneManager.h ***/
|
---|
1626 | // mIlluminationStage = IRS_AMBIENT;
|
---|
1627 |
|
---|
1628 | OctreeSceneManager::renderObjects(pPriorityGrp->getSolidsBasic(), om, false, &lightList);
|
---|
1629 | // Also render any objects which have receive shadows disabled
|
---|
1630 | OctreeSceneManager::renderObjects(pPriorityGrp->getSolidsNoShadowReceive(), om, true);
|
---|
1631 | #if 0
|
---|
1632 | std::stringstream d;
|
---|
1633 | d << " solid size: " << (int)pPriorityGrp->_getSolidPasses().size()
|
---|
1634 | << " solid no shadow size: " << (int)pPriorityGrp->_getSolidPassesNoShadow().size()
|
---|
1635 | << "difspec size: " << (int)pPriorityGrp->_getSolidPassesDiffuseSpecular().size()
|
---|
1636 | << " decal size: " << (int)pPriorityGrp->_getSolidPassesDecal().size();
|
---|
1637 | LogManager::getSingleton().logMessage(d.str());
|
---|
1638 | #endif
|
---|
1639 | }
|
---|
1640 | }
|
---|
1641 | //-----------------------------------------------------------------------
|
---|
1642 | void OcclusionCullingSceneManager::renderModulativeStencilShadowedQueueGroupObjects(
|
---|
1643 | RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om)
|
---|
1644 | {
|
---|
1645 | if (mNormalExecution || !mIsHierarchicalCulling)
|
---|
1646 | {
|
---|
1647 | TerrainSceneManager::renderModulativeStencilShadowedQueueGroupObjects(pGroup, om);
|
---|
1648 | return;
|
---|
1649 | }
|
---|
1650 |
|
---|
1651 | // Iterate through priorities
|
---|
1652 | RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
|
---|
1653 |
|
---|
1654 | while (groupIt.hasMoreElements())
|
---|
1655 | {
|
---|
1656 | RenderPriorityGroup* pPriorityGrp = groupIt.getNext();
|
---|
1657 |
|
---|
1658 | // Sort the queue first
|
---|
1659 | pPriorityGrp->sort(mCameraInProgress);
|
---|
1660 | // Do (shadowable) solids
|
---|
1661 | OctreeSceneManager::renderObjects(pPriorityGrp->getSolidsBasic(), om, true);
|
---|
1662 | }
|
---|
1663 | }
|
---|
1664 | //-------------------------------------------------------------------------
|
---|
1665 | void OcclusionCullingSceneManager::SetObjectsVisible(const bool visible)
|
---|
1666 | {
|
---|
1667 | GtpVisibilityPreprocessor::ObjectContainer::iterator it, it_end = mObjects.end();
|
---|
1668 | for (it = mObjects.begin(); it != it_end; ++ it)
|
---|
1669 | SetObjectVisible(*it, visible);
|
---|
1670 | }
|
---|
1671 | //-----------------------------------------------------------------------
|
---|
1672 | bool OcclusionCullingSceneManager::LoadViewCells(const String &filename)
|
---|
1673 | {
|
---|
1674 | // no filename specified
|
---|
1675 | if (filename == "")
|
---|
1676 | return false;
|
---|
1677 |
|
---|
1678 | // view cells already loaded
|
---|
1679 | if (mViewCellsLoaded)
|
---|
1680 | return true;
|
---|
1681 |
|
---|
1682 | // converter between view cell ids and Ogre entites
|
---|
1683 | OctreeBoundingBoxConverter bconverter(this);
|
---|
1684 |
|
---|
1685 | // load the view cells assigning the found objects to the pvss
|
---|
1686 | const bool finalizeViewCells = false;
|
---|
1687 |
|
---|
1688 | // load the view cells assigning the found objects to the pvss
|
---|
1689 | mViewCellsManager =
|
---|
1690 | GtpVisibilityPreprocessor::ViewCellsManager::
|
---|
1691 | LoadViewCells(filename, mObjects, finalizeViewCells, &bconverter);
|
---|
1692 |
|
---|
1693 | LogManager::getSingleton().logMessage("******** view cells loaded *********");
|
---|
1694 |
|
---|
1695 | // objects are set to invisible initially
|
---|
1696 | //SetObjectsVisible(false);
|
---|
1697 |
|
---|
1698 | if (finalizeViewCells)
|
---|
1699 | CreateViewCellsGeometry();
|
---|
1700 |
|
---|
1701 | return (mViewCellsManager != NULL);
|
---|
1702 | }
|
---|
1703 | //-------------------------------------------------------------------------
|
---|
1704 | void OcclusionCullingSceneManager::ApplyViewCellPvs(GtpVisibilityPreprocessor::ViewCell *vc,
|
---|
1705 | const bool loadObjects)
|
---|
1706 | {
|
---|
1707 | // rather apply view cell representing unbounded space then
|
---|
1708 | if (!vc)
|
---|
1709 | {
|
---|
1710 | LogManager::getSingleton().logMessage("no view cell or outside of view space, setting everything to invisible");
|
---|
1711 | // question: if no view cell, set everything visible?
|
---|
1712 | SetObjectsVisible(false);
|
---|
1713 | return;
|
---|
1714 | }
|
---|
1715 |
|
---|
1716 | ////////////
|
---|
1717 | //-- set view cell PVS to visible
|
---|
1718 |
|
---|
1719 | GtpVisibilityPreprocessor::ObjectPvsIterator pit = vc->GetPvs().GetIterator();
|
---|
1720 |
|
---|
1721 | while (pit.HasMoreEntries())
|
---|
1722 | {
|
---|
1723 | GtpVisibilityPreprocessor::Intersectable *obj = pit.Next();
|
---|
1724 | // no associated geometry found
|
---|
1725 | if (!obj) continue;
|
---|
1726 | SetObjectVisible(obj, loadObjects);
|
---|
1727 | }
|
---|
1728 | }
|
---|
1729 | //-------------------------------------------------------------------------
|
---|
1730 | void OcclusionCullingSceneManager::UpdatePvs(Camera *cam)
|
---|
1731 | {
|
---|
1732 | if (!(mViewCellsLoaded && mUseViewCells))
|
---|
1733 | return;
|
---|
1734 |
|
---|
1735 | const GtpVisibilityPreprocessor::Vector3 viewPoint =
|
---|
1736 | OgreTypeConverter::ConvertFromOgre(cam->getDerivedPosition());
|
---|
1737 |
|
---|
1738 | GtpVisibilityPreprocessor::ViewCell *viewCell =
|
---|
1739 | mViewCellsManager->GetViewCell(viewPoint);
|
---|
1740 |
|
---|
1741 | // view cell did not change => don't change pvs
|
---|
1742 | if (mCurrentViewCell == viewCell)
|
---|
1743 | return;
|
---|
1744 |
|
---|
1745 |
|
---|
1746 | //////////////
|
---|
1747 | //-- unload old pvs and load new pvs
|
---|
1748 |
|
---|
1749 | ApplyViewCellPvs(mCurrentViewCell, false);
|
---|
1750 |
|
---|
1751 | mCurrentViewCell = viewCell;
|
---|
1752 | ApplyViewCellPvs(mCurrentViewCell, true);
|
---|
1753 | }
|
---|
1754 | //-------------------------------------------------------------------------
|
---|
1755 | void OcclusionCullingSceneManager::CreateViewCellsGeometry()
|
---|
1756 | {
|
---|
1757 | //LogManager::getSingleton().logMessage("creating view cells geometry");
|
---|
1758 | if (mViewCellsGeometryLoaded) return;
|
---|
1759 |
|
---|
1760 | GtpVisibilityPreprocessor::ViewCellContainer viewCells =
|
---|
1761 | mViewCellsManager->GetViewCells();
|
---|
1762 |
|
---|
1763 | GtpVisibilityPreprocessor::ViewCellContainer::const_iterator it, it_end = viewCells.end();
|
---|
1764 | for (it = viewCells.begin(); it != it_end; ++ it)
|
---|
1765 | {
|
---|
1766 | GtpVisibilityPreprocessor::ViewCell *viewCell = *it;
|
---|
1767 |
|
---|
1768 | ManualObject *manual =
|
---|
1769 | OgreTypeConverter::ConvertToOgre(viewCell->GetMesh(), this);
|
---|
1770 |
|
---|
1771 | if (manual)
|
---|
1772 | {
|
---|
1773 | mViewCellsGeometry[viewCell->GetId()] = manual;
|
---|
1774 |
|
---|
1775 | // attach to scene node
|
---|
1776 | getRootSceneNode()->createChildSceneNode()->attachObject(manual);
|
---|
1777 | manual->setQueryFlags(0); // returned by no query
|
---|
1778 |
|
---|
1779 | // initialy set to invisible
|
---|
1780 | manual->setVisible(false);
|
---|
1781 | }
|
---|
1782 | }
|
---|
1783 |
|
---|
1784 | mViewCellsGeometryLoaded = true;
|
---|
1785 | }
|
---|
1786 | //-------------------------------------------------------------------------
|
---|
1787 | void OcclusionCullingSceneManager::VisualizeViewCells(const bool visualize)
|
---|
1788 | {
|
---|
1789 | MovableMap::const_iterator mit, mit_end = mViewCellsGeometry.end();
|
---|
1790 |
|
---|
1791 | for (mit = mViewCellsGeometry.begin(); mit != mit_end; ++ mit)
|
---|
1792 | {
|
---|
1793 | if ((*mit).second)
|
---|
1794 | (*mit).second->setVisible(visualize);
|
---|
1795 | }
|
---|
1796 | }
|
---|
1797 | #if 0
|
---|
1798 | //-------------------------------------------------------------------------
|
---|
1799 | void OcclusionCullingSceneManager::TestVisible(SceneNode *node)
|
---|
1800 | {
|
---|
1801 | // first test for scene node, then for octant (part of the hierarchy)
|
---|
1802 | if (!node->mVisibleChildren)
|
---|
1803 | {
|
---|
1804 | node->setVisible(false);
|
---|
1805 | }
|
---|
1806 |
|
---|
1807 | node->getOctant()->mVisibleChildren --;
|
---|
1808 | }
|
---|
1809 | //-------------------------------------------------------------------------
|
---|
1810 | void OcclusionCullingSceneManager::TestVisible(Octree *octant)
|
---|
1811 | {
|
---|
1812 | // first test for scene node, then for octant (part of the hierarchy)
|
---|
1813 | if (!octant->mVisibleChildren)
|
---|
1814 | {
|
---|
1815 | octant->setVisible(false);
|
---|
1816 | }
|
---|
1817 | }
|
---|
1818 |
|
---|
1819 | //-------------------------------------------------------------------------
|
---|
1820 | void OcclusionCullingSceneManager::UpdateVisibility(Entity *ent)
|
---|
1821 | {
|
---|
1822 | if (!ent->isVisible())
|
---|
1823 | {
|
---|
1824 | bool visible = TestVisible(ent->getParentNode());
|
---|
1825 |
|
---|
1826 | if (!visible)
|
---|
1827 | visible = TestVisible(octant->getParentNode());
|
---|
1828 |
|
---|
1829 | if (!visible)
|
---|
1830 | mHierarchyInterface->pullupVisibility();
|
---|
1831 | }
|
---|
1832 | }
|
---|
1833 | #endif
|
---|
1834 | // splits strings containing multiple file names
|
---|
1835 | static int SplitFilenames(const std::string str,
|
---|
1836 | std::vector<std::string> &filenames)
|
---|
1837 | {
|
---|
1838 | int pos = 0;
|
---|
1839 |
|
---|
1840 | while(1)
|
---|
1841 | {
|
---|
1842 | int npos = (int)str.find(';', pos);
|
---|
1843 |
|
---|
1844 | if (npos < 0 || npos - pos < 1)
|
---|
1845 | break;
|
---|
1846 | filenames.push_back(std::string(str, pos, npos - pos));
|
---|
1847 | pos = npos + 1;
|
---|
1848 | }
|
---|
1849 |
|
---|
1850 | filenames.push_back(std::string(str, pos, str.size() - pos));
|
---|
1851 | return (int)filenames.size();
|
---|
1852 | }
|
---|
1853 | //-----------------------------------------------------------------------
|
---|
1854 | bool OcclusionCullingSceneManager::LoadScene(const String &filename,
|
---|
1855 | const String &viewCellsFilename)
|
---|
1856 | {
|
---|
1857 | using namespace std;
|
---|
1858 |
|
---|
1859 | // use leaf nodes of the original spatial hierarchy as occludees
|
---|
1860 | vector<string> filenames;
|
---|
1861 | const int files = SplitFilenames(filename, filenames);
|
---|
1862 |
|
---|
1863 | stringstream d;
|
---|
1864 | d << "number of input files: " << files << "\n";
|
---|
1865 | LogManager::getSingleton().logMessage(d.str());
|
---|
1866 |
|
---|
1867 | bool result = false;
|
---|
1868 | vector<string>::const_iterator fit, fit_end = filenames.end();
|
---|
1869 | int i = 0;
|
---|
1870 |
|
---|
1871 | if (filename == "terrain" || filename == "")
|
---|
1872 | {
|
---|
1873 | LogManager::getSingleton().logMessage("not loading scene");
|
---|
1874 |
|
---|
1875 | // terrain hack
|
---|
1876 | return false;
|
---|
1877 | }
|
---|
1878 |
|
---|
1879 | for (fit = filenames.begin(); fit != fit_end; ++ fit, ++ i)
|
---|
1880 | {
|
---|
1881 | const string fn = *fit;
|
---|
1882 |
|
---|
1883 | if (strstr(fn.c_str(), ".obj"))
|
---|
1884 | {
|
---|
1885 | // load iv files
|
---|
1886 | if (!LoadSceneObj(filename, viewCellsFilename, getRootSceneNode()))
|
---|
1887 | {
|
---|
1888 | LogManager::getSingleton().logMessage("error loading file");
|
---|
1889 | return false;
|
---|
1890 | }
|
---|
1891 | }
|
---|
1892 | else if (strstr(fn.c_str(), ".iv") || strstr(fn.c_str(), ".wrl"))
|
---|
1893 | {
|
---|
1894 | // load iv files
|
---|
1895 | if (!LoadSceneIV(fn, getRootSceneNode(), i))
|
---|
1896 | {
|
---|
1897 | // terrain hack
|
---|
1898 | LogManager::getSingleton().logMessage("error loading file");
|
---|
1899 | }
|
---|
1900 | }
|
---|
1901 |
|
---|
1902 | // at least one piece of geometry loaded
|
---|
1903 | result = true;
|
---|
1904 | }
|
---|
1905 |
|
---|
1906 | return result;
|
---|
1907 | }
|
---|
1908 | //-----------------------------------------------------------------------
|
---|
1909 | bool OcclusionCullingSceneManager::LoadSceneIV(const String &filename,
|
---|
1910 | SceneNode *root,
|
---|
1911 | const int index)
|
---|
1912 | {
|
---|
1913 | IVReader ivReader;
|
---|
1914 |
|
---|
1915 | Timer *timer = PlatformManager::getSingleton().createTimer();
|
---|
1916 | timer->reset();
|
---|
1917 |
|
---|
1918 | if (1)
|
---|
1919 | {
|
---|
1920 | std::string logFilename = "IVLog" + Ogre::StringConverter().toString(index) + ".log";
|
---|
1921 |
|
---|
1922 | Log *log = LogManager::getSingleton().createLog(logFilename);
|
---|
1923 | ivReader.setLog(log);
|
---|
1924 | }
|
---|
1925 |
|
---|
1926 | if (ivReader.loadFile(filename.c_str()))
|
---|
1927 | {
|
---|
1928 | SceneNode *node = root->createChildSceneNode("IVSceneNode" + index);
|
---|
1929 |
|
---|
1930 | ivReader.buildTree(this, node);
|
---|
1931 | ivReader.collapse();
|
---|
1932 |
|
---|
1933 | std::stringstream d;
|
---|
1934 | d << "loaded " << filename << " in " << timer->getMilliseconds() * 1e-3 << " secs";
|
---|
1935 | LogManager::getSingleton().logMessage(d.str());
|
---|
1936 |
|
---|
1937 | PlatformManager::getSingleton().destroyTimer(timer);
|
---|
1938 |
|
---|
1939 | /*if (USE_STATIC_GEOMETRY)
|
---|
1940 | {
|
---|
1941 | //-- bake into static geometry
|
---|
1942 | BakeSceneIntoStaticGeometry("staticVienna", "Vienna");
|
---|
1943 | }*/
|
---|
1944 |
|
---|
1945 | return true;
|
---|
1946 | }
|
---|
1947 |
|
---|
1948 | return false;
|
---|
1949 | }
|
---|
1950 | //-----------------------------------------------------------------------
|
---|
1951 | void OcclusionCullingSceneManager::RenderHierarchicalCulling(const bool fillRenderQueue)
|
---|
1952 | {
|
---|
1953 | // create material for depth pass
|
---|
1954 | InitDepthPass();
|
---|
1955 |
|
---|
1956 | ////////////////////
|
---|
1957 | //-- hierarchical culling
|
---|
1958 |
|
---|
1959 | // set all necessary parameters for
|
---|
1960 | // hierarchical visibility culling and rendering
|
---|
1961 | InitVisibilityCulling(mCameraInProgress);
|
---|
1962 |
|
---|
1963 |
|
---|
1964 | /**
|
---|
1965 | * the hierarchical culling algorithm
|
---|
1966 | * for depth pass: we just find objects and update depth buffer
|
---|
1967 | * for "delayed" rendering: we render some passes afterwards
|
---|
1968 | * e.g., transparents, because they need front-to-back sorting
|
---|
1969 | **/
|
---|
1970 |
|
---|
1971 | mVisibilityManager->ApplyVisibilityCulling();
|
---|
1972 |
|
---|
1973 | // delete remaining renderables from queue:
|
---|
1974 | // all which are not in mLeavePassesInQueue)
|
---|
1975 | _deleteRenderedQueueGroups(mLeavePassesInQueue);
|
---|
1976 |
|
---|
1977 | /////////////
|
---|
1978 | //-- reset parameters needed for special rendering
|
---|
1979 |
|
---|
1980 | mIsDepthPassPhase = false;
|
---|
1981 | mIsItemBufferPhase = false;
|
---|
1982 | mSkipTransparents = false;
|
---|
1983 | mIsHierarchicalCulling = false;
|
---|
1984 | mLeavePassesInQueue = 0;
|
---|
1985 |
|
---|
1986 | if (fillRenderQueue)
|
---|
1987 | {
|
---|
1988 | // the shaded geometry is rendered in a second pass
|
---|
1989 | // add visible nodes found by the visibility culling algorithm
|
---|
1990 | NodeList::const_iterator it, it_end = mVisible.end();
|
---|
1991 | for (it = mVisible.begin(); it != it_end; ++ it)
|
---|
1992 | {
|
---|
1993 | (*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false);
|
---|
1994 | }
|
---|
1995 | }
|
---|
1996 | }
|
---|
1997 | //-----------------------------------------------------------------------
|
---|
1998 | bool OcclusionCullingSceneManager::LoadSceneObj(const String &filename,
|
---|
1999 | const String &viewCellsFile,
|
---|
2000 | SceneNode *root)
|
---|
2001 | {
|
---|
2002 | Timer *timer = PlatformManager::getSingleton().createTimer();
|
---|
2003 | timer->reset();
|
---|
2004 |
|
---|
2005 | if (!mObjReader->LoadFile(filename.c_str(), viewCellsFile, root))
|
---|
2006 | {
|
---|
2007 | PlatformManager::getSingleton().destroyTimer(timer);
|
---|
2008 | return false;
|
---|
2009 | }
|
---|
2010 |
|
---|
2011 | std::stringstream d;
|
---|
2012 | d << "loaded " << filename << " in " << timer->getMilliseconds() * 1e-3 << " secs";
|
---|
2013 | LogManager::getSingleton().logMessage(d.str());
|
---|
2014 |
|
---|
2015 | PlatformManager::getSingleton().destroyTimer(timer);
|
---|
2016 |
|
---|
2017 | return true;
|
---|
2018 | }
|
---|
2019 |
|
---|
2020 | //-----------------------------------------------------------------------
|
---|
2021 | void OcclusionCullingSceneManager::_renderScene(Camera* camera,
|
---|
2022 | Viewport* vp,
|
---|
2023 | bool includeOverlays)
|
---|
2024 | {
|
---|
2025 | if (0 && mNormalExecution)
|
---|
2026 | {
|
---|
2027 | TerrainSceneManager::_renderScene(camera, vp, includeOverlays);
|
---|
2028 | return;
|
---|
2029 | }
|
---|
2030 |
|
---|
2031 | Root::getSingleton()._setCurrentSceneManager(this);
|
---|
2032 | mActiveQueuedRenderableVisitor->targetSceneMgr = this;
|
---|
2033 |
|
---|
2034 | if (isShadowTechniqueInUse())
|
---|
2035 | {
|
---|
2036 | // Prepare shadow materials
|
---|
2037 | initShadowVolumeMaterials();
|
---|
2038 | }
|
---|
2039 |
|
---|
2040 | // Perform a quick pre-check to see whether we should override far distance
|
---|
2041 | // When using stencil volumes we have to use infinite far distance
|
---|
2042 | // to prevent dark caps getting clipped
|
---|
2043 | if (isShadowTechniqueStencilBased() &&
|
---|
2044 | camera->getProjectionType() == PT_PERSPECTIVE &&
|
---|
2045 | camera->getFarClipDistance() != 0 &&
|
---|
2046 | mDestRenderSystem->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE) &&
|
---|
2047 | mShadowUseInfiniteFarPlane)
|
---|
2048 | {
|
---|
2049 | // infinite far distance
|
---|
2050 | camera->setFarClipDistance(0);
|
---|
2051 | }
|
---|
2052 |
|
---|
2053 | mCameraInProgress = camera;
|
---|
2054 |
|
---|
2055 |
|
---|
2056 | // Update controllers
|
---|
2057 | ControllerManager::getSingleton().updateAllControllers();
|
---|
2058 |
|
---|
2059 | // Update the scene, only do this once per frame
|
---|
2060 | unsigned long thisFrameNumber = Root::getSingleton().getCurrentFrameNumber();
|
---|
2061 | if (thisFrameNumber != mLastFrameNumber)
|
---|
2062 | {
|
---|
2063 | // Update animations
|
---|
2064 | _applySceneAnimations();
|
---|
2065 | mLastFrameNumber = thisFrameNumber;
|
---|
2066 | }
|
---|
2067 |
|
---|
2068 | // Update scene graph for this camera (can happen multiple times per frame)
|
---|
2069 | _updateSceneGraph(camera);
|
---|
2070 |
|
---|
2071 | // Auto-track nodes
|
---|
2072 | AutoTrackingSceneNodes::iterator atsni, atsniend;
|
---|
2073 | atsniend = mAutoTrackingSceneNodes.end();
|
---|
2074 | for (atsni = mAutoTrackingSceneNodes.begin(); atsni != atsniend; ++atsni)
|
---|
2075 | {
|
---|
2076 | (*atsni)->_autoTrack();
|
---|
2077 | }
|
---|
2078 | // Auto-track camera if required
|
---|
2079 | camera->_autoTrack();
|
---|
2080 |
|
---|
2081 |
|
---|
2082 | // Are we using any shadows at all?
|
---|
2083 | if (isShadowTechniqueInUse() &&
|
---|
2084 | mIlluminationStage != IRS_RENDER_TO_TEXTURE &&
|
---|
2085 | vp->getShadowsEnabled() &&
|
---|
2086 | mFindVisibleObjects)
|
---|
2087 | {
|
---|
2088 | // Locate any lights which could be affecting the frustum
|
---|
2089 | findLightsAffectingFrustum(camera);
|
---|
2090 | if (isShadowTechniqueTextureBased())
|
---|
2091 | {
|
---|
2092 | // *******
|
---|
2093 | // WARNING
|
---|
2094 | // *******
|
---|
2095 | // This call will result in re-entrant calls to this method
|
---|
2096 | // therefore anything which comes before this is NOT
|
---|
2097 | // guaranteed persistent. Make sure that anything which
|
---|
2098 | // MUST be specific to this camera / target is done
|
---|
2099 | // AFTER THIS POINT
|
---|
2100 | prepareShadowTextures(camera, vp);
|
---|
2101 | // reset the cameras because of the re-entrant call
|
---|
2102 | mCameraInProgress = camera;
|
---|
2103 | }
|
---|
2104 | }
|
---|
2105 |
|
---|
2106 | // Invert vertex winding?
|
---|
2107 | if (camera->isReflected())
|
---|
2108 | {
|
---|
2109 | mDestRenderSystem->setInvertVertexWinding(true);
|
---|
2110 | }
|
---|
2111 | else
|
---|
2112 | {
|
---|
2113 | mDestRenderSystem->setInvertVertexWinding(false);
|
---|
2114 | }
|
---|
2115 |
|
---|
2116 | // Tell params about viewport
|
---|
2117 | mAutoParamDataSource.setCurrentViewport(vp);
|
---|
2118 | // Set the viewport
|
---|
2119 | setViewport(vp);
|
---|
2120 |
|
---|
2121 | // Tell params about camera
|
---|
2122 | mAutoParamDataSource.setCurrentCamera(camera);
|
---|
2123 | // Set autoparams for finite dir light extrusion
|
---|
2124 | mAutoParamDataSource.setShadowDirLightExtrusionDistance(mShadowDirLightExtrudeDist);
|
---|
2125 |
|
---|
2126 | // Tell params about current ambient light
|
---|
2127 | mAutoParamDataSource.setAmbientLightColour(mAmbientLight);
|
---|
2128 | // Tell rendersystem
|
---|
2129 | mDestRenderSystem->setAmbientLight(mAmbientLight.r, mAmbientLight.g, mAmbientLight.b);
|
---|
2130 |
|
---|
2131 | // Tell params about render target
|
---|
2132 | mAutoParamDataSource.setCurrentRenderTarget(vp->getTarget());
|
---|
2133 |
|
---|
2134 |
|
---|
2135 | // Set camera window clipping planes (if any)
|
---|
2136 | if (mDestRenderSystem->getCapabilities()->hasCapability(RSC_USER_CLIP_PLANES))
|
---|
2137 | {
|
---|
2138 | if (camera->isWindowSet())
|
---|
2139 | {
|
---|
2140 | const std::vector<Plane>& planeList =
|
---|
2141 | camera->getWindowPlanes();
|
---|
2142 | for (ushort i = 0; i < 4; ++i)
|
---|
2143 | {
|
---|
2144 | mDestRenderSystem->enableClipPlane(i, true);
|
---|
2145 | mDestRenderSystem->setClipPlane(i, planeList[i]);
|
---|
2146 | }
|
---|
2147 | }
|
---|
2148 | else
|
---|
2149 | {
|
---|
2150 | for (ushort i = 0; i < 4; ++i)
|
---|
2151 | {
|
---|
2152 | mDestRenderSystem->enableClipPlane(i, false);
|
---|
2153 | }
|
---|
2154 | }
|
---|
2155 | }
|
---|
2156 |
|
---|
2157 | mDestRenderSystem->_beginGeometryCount();
|
---|
2158 | // Begin the frame
|
---|
2159 | mDestRenderSystem->_beginFrame();
|
---|
2160 |
|
---|
2161 | // Set rasterisation mode
|
---|
2162 | mDestRenderSystem->_setPolygonMode(camera->getPolygonMode());
|
---|
2163 |
|
---|
2164 | // Set initial camera state
|
---|
2165 | mDestRenderSystem->_setProjectionMatrix(mCameraInProgress->getProjectionMatrixRS());
|
---|
2166 | mDestRenderSystem->_setViewMatrix(mCameraInProgress->getViewMatrix(true));
|
---|
2167 |
|
---|
2168 | // Prepare render queue for receiving new objects
|
---|
2169 | #ifdef GAMETOOLS_ILLUMINATION_MODULE
|
---|
2170 | if (mFindVisibleObjects)
|
---|
2171 | prepareRenderQueue();
|
---|
2172 | #else
|
---|
2173 | prepareRenderQueue();
|
---|
2174 | #endif
|
---|
2175 |
|
---|
2176 | if (mFindVisibleObjects)
|
---|
2177 | {
|
---|
2178 | // Parse the scene and tag visibles
|
---|
2179 | myFindVisibleObjects(camera,
|
---|
2180 | mIlluminationStage == IRS_RENDER_TO_TEXTURE? true : false);
|
---|
2181 | }
|
---|
2182 | // Add overlays, if viewport deems it
|
---|
2183 | if (vp->getOverlaysEnabled() && mIlluminationStage != IRS_RENDER_TO_TEXTURE)
|
---|
2184 | {
|
---|
2185 | OverlayManager::getSingleton()._queueOverlaysForRendering(camera, getRenderQueue(), vp);
|
---|
2186 | }
|
---|
2187 | // Queue skies, if viewport seems it
|
---|
2188 | if (vp->getSkiesEnabled() && mFindVisibleObjects && mIlluminationStage != IRS_RENDER_TO_TEXTURE)
|
---|
2189 | {
|
---|
2190 | _queueSkiesForRendering(camera);
|
---|
2191 | }
|
---|
2192 |
|
---|
2193 | // Render scene content
|
---|
2194 | _renderVisibleObjects();
|
---|
2195 |
|
---|
2196 | // End frame
|
---|
2197 | mDestRenderSystem->_endFrame();
|
---|
2198 |
|
---|
2199 | // Notify camera or vis faces
|
---|
2200 | camera->_notifyRenderedFaces(mDestRenderSystem->_getFaceCount());
|
---|
2201 | }
|
---|
2202 | //-----------------------------------------------------------------------
|
---|
2203 | int OcclusionCullingSceneManager::QueryVisibleObjectsExact(Camera *camera,
|
---|
2204 | Viewport* vp,
|
---|
2205 | const bool fromPoint,
|
---|
2206 | const bool nodeVisibility)
|
---|
2207 | {
|
---|
2208 | const bool relativeVisibility = false;
|
---|
2209 | const bool approximateVisibility = false;
|
---|
2210 |
|
---|
2211 | int queryModes = 0;
|
---|
2212 |
|
---|
2213 | if (nodeVisibility)
|
---|
2214 | queryModes |= GtpVisibility::QueryManager::NODE_VISIBILITY;
|
---|
2215 | else
|
---|
2216 | queryModes |= GtpVisibility::QueryManager::GEOMETRY_VISIBILITY;
|
---|
2217 |
|
---|
2218 | OcclusionQueriesQueryManager *queryManager =
|
---|
2219 | new OcclusionQueriesQueryManager(mHierarchyInterface,
|
---|
2220 | vp,
|
---|
2221 | queryModes);
|
---|
2222 |
|
---|
2223 | mVisibilityManager->SetQueryManager(queryManager);
|
---|
2224 |
|
---|
2225 | NodeInfoContainer visibleNodes;
|
---|
2226 | MeshInfoContainer visibleGeometry;
|
---|
2227 | PatchInfoContainer visiblePatches;
|
---|
2228 |
|
---|
2229 | if (fromPoint)
|
---|
2230 | {
|
---|
2231 | queryManager->ComputeFromPointVisibility(camera->getDerivedPosition(),
|
---|
2232 | &visibleNodes,
|
---|
2233 | &visibleGeometry,
|
---|
2234 | &visiblePatches,
|
---|
2235 | relativeVisibility,
|
---|
2236 | approximateVisibility);
|
---|
2237 | }
|
---|
2238 | else
|
---|
2239 | {
|
---|
2240 | queryManager->ComputeCameraVisibility(*camera,
|
---|
2241 | &visibleNodes,
|
---|
2242 | &visibleGeometry,
|
---|
2243 | &visiblePatches,
|
---|
2244 | relativeVisibility,
|
---|
2245 | approximateVisibility);
|
---|
2246 | }
|
---|
2247 |
|
---|
2248 | if (0)
|
---|
2249 | {
|
---|
2250 | std::stringstream d;
|
---|
2251 | d << "Query mode: " << queryModes
|
---|
2252 | << ", visible nodes: " << (int)visibleNodes.size()
|
---|
2253 | << ", visible geometry: " << (int)visibleGeometry.size();
|
---|
2254 |
|
---|
2255 | LogManager::getSingleton().logMessage(d.str());
|
---|
2256 | }
|
---|
2257 |
|
---|
2258 | ///////////////////////
|
---|
2259 | //-- put items in render queue
|
---|
2260 |
|
---|
2261 | getRenderQueue()->clear();
|
---|
2262 |
|
---|
2263 | if (!nodeVisibility)
|
---|
2264 | {
|
---|
2265 | //////////////////
|
---|
2266 | //-- apply queries on geometry level
|
---|
2267 |
|
---|
2268 | MeshInfoContainer::iterator geomIt, geomIt_end = visibleGeometry.end();
|
---|
2269 |
|
---|
2270 | for (geomIt = visibleGeometry.begin(); geomIt != geomIt_end; ++geomIt)
|
---|
2271 | {
|
---|
2272 | MovableObject *mo = (*geomIt).GetSource();
|
---|
2273 |
|
---|
2274 | // add if not 0
|
---|
2275 | if (!(*geomIt).GetVisiblePixels())
|
---|
2276 | continue;
|
---|
2277 |
|
---|
2278 | mo->_notifyCurrentCamera(camera);
|
---|
2279 |
|
---|
2280 | if (mo->isVisible())
|
---|
2281 | {
|
---|
2282 | mo->_updateRenderQueue(getRenderQueue());
|
---|
2283 | }
|
---|
2284 | }
|
---|
2285 | }
|
---|
2286 | else
|
---|
2287 | {
|
---|
2288 | ////////////////
|
---|
2289 | //-- apply queries on node level
|
---|
2290 |
|
---|
2291 | NodeInfoContainer::iterator nodesIt, nodesIt_end = visibleNodes.end();
|
---|
2292 |
|
---|
2293 | for (nodesIt = visibleNodes.begin(); nodesIt != nodesIt_end; ++ nodesIt)
|
---|
2294 | {
|
---|
2295 | if (!(*nodesIt).GetVisiblePixels())
|
---|
2296 | continue;
|
---|
2297 |
|
---|
2298 | Octree *octree = static_cast<Octree *>((*nodesIt).GetSource());
|
---|
2299 |
|
---|
2300 | NodeList::iterator nIt, nIt_end = octree->mNodes.end();
|
---|
2301 |
|
---|
2302 | for (nIt = octree->mNodes.begin(); nIt != nIt_end; ++ nIt)
|
---|
2303 | {
|
---|
2304 | (*nIt)->_addToRenderQueue(camera, getRenderQueue(), false);
|
---|
2305 | }
|
---|
2306 | }
|
---|
2307 | }
|
---|
2308 |
|
---|
2309 | delete queryManager;
|
---|
2310 |
|
---|
2311 | if (nodeVisibility)
|
---|
2312 | return (int)visibleNodes.size();
|
---|
2313 | else
|
---|
2314 | return (int)visibleGeometry.size();
|
---|
2315 | }
|
---|
2316 | //-----------------------------------------------------------------------
|
---|
2317 | void OcclusionCullingSceneManager::RenderDepthForQuery(Camera* camera,
|
---|
2318 | Viewport* vp)
|
---|
2319 | {
|
---|
2320 | Root::getSingleton()._setCurrentSceneManager(this);
|
---|
2321 | mActiveQueuedRenderableVisitor->targetSceneMgr = this;
|
---|
2322 |
|
---|
2323 | mCameraInProgress = camera;
|
---|
2324 |
|
---|
2325 | // Update scene graph for this camera (can happen multiple times per frame)
|
---|
2326 | _updateSceneGraph(camera);
|
---|
2327 |
|
---|
2328 | // Invert vertex winding?
|
---|
2329 | if (camera->isReflected())
|
---|
2330 | {
|
---|
2331 | mDestRenderSystem->setInvertVertexWinding(true);
|
---|
2332 | }
|
---|
2333 | else
|
---|
2334 | {
|
---|
2335 | mDestRenderSystem->setInvertVertexWinding(false);
|
---|
2336 | }
|
---|
2337 |
|
---|
2338 | // Tell params about viewport
|
---|
2339 | mAutoParamDataSource.setCurrentViewport(vp);
|
---|
2340 | // Set the viewport
|
---|
2341 | setViewport(vp);
|
---|
2342 |
|
---|
2343 | // Tell params about camera
|
---|
2344 | mAutoParamDataSource.setCurrentCamera(camera);
|
---|
2345 | // Set autoparams for finite dir light extrusion
|
---|
2346 | mAutoParamDataSource.setShadowDirLightExtrusionDistance(mShadowDirLightExtrudeDist);
|
---|
2347 |
|
---|
2348 | // Tell params about current ambient light
|
---|
2349 | mAutoParamDataSource.setAmbientLightColour(mAmbientLight);
|
---|
2350 | // Tell rendersystem
|
---|
2351 | mDestRenderSystem->setAmbientLight(mAmbientLight.r, mAmbientLight.g, mAmbientLight.b);
|
---|
2352 |
|
---|
2353 | // Tell params about render target
|
---|
2354 | mAutoParamDataSource.setCurrentRenderTarget(vp->getTarget());
|
---|
2355 |
|
---|
2356 |
|
---|
2357 | // Set camera window clipping planes (if any)
|
---|
2358 | if (mDestRenderSystem->getCapabilities()->hasCapability(RSC_USER_CLIP_PLANES))
|
---|
2359 | {
|
---|
2360 | if (camera->isWindowSet())
|
---|
2361 | {
|
---|
2362 | const std::vector<Plane>& planeList = camera->getWindowPlanes();
|
---|
2363 |
|
---|
2364 | for (ushort i = 0; i < 4; ++ i)
|
---|
2365 | {
|
---|
2366 | mDestRenderSystem->enableClipPlane(i, true);
|
---|
2367 | mDestRenderSystem->setClipPlane(i, planeList[i]);
|
---|
2368 | }
|
---|
2369 | }
|
---|
2370 | else
|
---|
2371 | {
|
---|
2372 | for (ushort i = 0; i < 4; ++i)
|
---|
2373 | {
|
---|
2374 | mDestRenderSystem->enableClipPlane(i, false);
|
---|
2375 | }
|
---|
2376 | }
|
---|
2377 | }
|
---|
2378 |
|
---|
2379 | // Prepare render queue for receiving new objects
|
---|
2380 | prepareRenderQueue();
|
---|
2381 |
|
---|
2382 | // Begin the frame
|
---|
2383 | mDestRenderSystem->_beginFrame();
|
---|
2384 |
|
---|
2385 | // Set rasterisation mode
|
---|
2386 | mDestRenderSystem->_setPolygonMode(camera->getPolygonMode());
|
---|
2387 |
|
---|
2388 | // Set initial camera state
|
---|
2389 | mDestRenderSystem->_setProjectionMatrix(mCameraInProgress->getProjectionMatrixRS());
|
---|
2390 | mDestRenderSystem->_setViewMatrix(mCameraInProgress->getViewMatrix(true));
|
---|
2391 |
|
---|
2392 | //////////////
|
---|
2393 | //-- Render scene in order fill depth buffer
|
---|
2394 |
|
---|
2395 | // don't have to fill queue, just render depth
|
---|
2396 | const bool fillQueue = false;
|
---|
2397 | RenderHierarchicalCulling(fillQueue);
|
---|
2398 |
|
---|
2399 | // End frame
|
---|
2400 | mDestRenderSystem->_endFrame();
|
---|
2401 | }
|
---|
2402 | //-----------------------------------------------------------------------
|
---|
2403 | const String OcclusionCullingSceneManagerFactory::FACTORY_TYPE_NAME = "OcclusionCullingSceneManager";
|
---|
2404 | //-----------------------------------------------------------------------
|
---|
2405 | void OcclusionCullingSceneManagerFactory::initMetaData(void) const
|
---|
2406 | {
|
---|
2407 | mMetaData.typeName = FACTORY_TYPE_NAME;
|
---|
2408 | mMetaData.description = "Scene manager organising the scene on the basis of an octree with advanced occlusion culling (TM).";
|
---|
2409 | mMetaData.sceneTypeMask = 0xFFFF; // support all types
|
---|
2410 | mMetaData.worldGeometrySupported = false;
|
---|
2411 | }
|
---|
2412 | //-----------------------------------------------------------------------
|
---|
2413 | SceneManager *OcclusionCullingSceneManagerFactory::createInstance(
|
---|
2414 | const String& instanceName)
|
---|
2415 | {
|
---|
2416 | OcclusionCullingSceneManager* tsm =
|
---|
2417 | new OcclusionCullingSceneManager(instanceName, visManager);
|
---|
2418 |
|
---|
2419 | // Create & register default sources (one per manager)
|
---|
2420 | HeightmapTerrainPageSource* ps = new HeightmapTerrainPageSource();
|
---|
2421 | mTerrainPageSources.push_back(ps);
|
---|
2422 | tsm->registerPageSource("Heightmap", ps);
|
---|
2423 |
|
---|
2424 | return tsm;
|
---|
2425 | }
|
---|
2426 | //-----------------------------------------------------------------------
|
---|
2427 | void OcclusionCullingSceneManager::AddVisibleMeshGeometryToQueue(
|
---|
2428 | const MeshInfoContainer &visibleGeometry,
|
---|
2429 | Camera *cam)
|
---|
2430 | {
|
---|
2431 | MeshInfoContainer::const_iterator geomIt, geomIt_end = visibleGeometry.end();
|
---|
2432 |
|
---|
2433 | for (geomIt = visibleGeometry.begin(); geomIt != geomIt_end; ++geomIt)
|
---|
2434 | {
|
---|
2435 | MovableObject *mo = (*geomIt).GetSource();
|
---|
2436 |
|
---|
2437 | // add if not 0
|
---|
2438 | if (!(*geomIt).GetVisiblePixels())
|
---|
2439 | continue;
|
---|
2440 |
|
---|
2441 | mo->_notifyCurrentCamera(cam);
|
---|
2442 |
|
---|
2443 | if (mo->isVisible())
|
---|
2444 | {
|
---|
2445 | mo->_updateRenderQueue(getRenderQueue());
|
---|
2446 | }
|
---|
2447 | }
|
---|
2448 | }
|
---|
2449 | //-----------------------------------------------------------------------
|
---|
2450 | void OcclusionCullingSceneManager::AddVisibleNodeGeometryToQueue(
|
---|
2451 | const NodeInfoContainer &visibleNodes,
|
---|
2452 | Camera *cam)
|
---|
2453 | {
|
---|
2454 | ////////////////
|
---|
2455 | //-- apply queries on node level
|
---|
2456 |
|
---|
2457 | NodeInfoContainer::const_iterator nodesIt, nodesIt_end = visibleNodes.end();
|
---|
2458 |
|
---|
2459 | for (nodesIt = visibleNodes.begin(); nodesIt != nodesIt_end; ++ nodesIt)
|
---|
2460 | {
|
---|
2461 | if (!(*nodesIt).GetVisiblePixels())
|
---|
2462 | continue;
|
---|
2463 |
|
---|
2464 | Octree *octree = static_cast<Octree *>((*nodesIt).GetSource());
|
---|
2465 |
|
---|
2466 | NodeList::iterator nIt, nIt_end = octree->mNodes.end();
|
---|
2467 |
|
---|
2468 | for (nIt = octree->mNodes.begin(); nIt != nIt_end; ++ nIt)
|
---|
2469 | {
|
---|
2470 | (*nIt)->_addToRenderQueue(cam, getRenderQueue(), false);
|
---|
2471 | }
|
---|
2472 | }
|
---|
2473 | }
|
---|
2474 | //-----------------------------------------------------------------------
|
---|
2475 | void OcclusionCullingSceneManager::_findVisibleObjects(Camera* cam,
|
---|
2476 | bool onlyShadowCasters)
|
---|
2477 | {
|
---|
2478 | if (mNormalExecution || !mUseVisibilityQueries)
|
---|
2479 | {
|
---|
2480 | TerrainSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
|
---|
2481 | return;
|
---|
2482 | }
|
---|
2483 |
|
---|
2484 | // don't need shading, render only depth
|
---|
2485 | // note:have to disable deph write for nodes!
|
---|
2486 | bool savedUseDepthPass = mUseDepthPass;
|
---|
2487 | if (mResetMaterialForQueries) mUseDepthPass = true;
|
---|
2488 |
|
---|
2489 | // lists only used for visualization
|
---|
2490 | getRenderQueue()->clear();
|
---|
2491 | mVisible.clear();
|
---|
2492 | mBoxes.clear();
|
---|
2493 |
|
---|
2494 | const bool relativeVisibility = false;
|
---|
2495 | bool approximateVisibility = false;
|
---|
2496 |
|
---|
2497 | int queryModes = 0;
|
---|
2498 |
|
---|
2499 | if (mQueryMode != EXACT_QUERIES)
|
---|
2500 | {
|
---|
2501 | queryModes |= GtpVisibility::QueryManager::NODE_VISIBILITY;
|
---|
2502 |
|
---|
2503 | // approximate visibility not for exact queries
|
---|
2504 | if (mQueryMode == APPROXIMATE_QUERIES)
|
---|
2505 | approximateVisibility = true;
|
---|
2506 | }
|
---|
2507 | else
|
---|
2508 | {
|
---|
2509 | queryModes |= GtpVisibility::QueryManager::GEOMETRY_VISIBILITY;
|
---|
2510 | }
|
---|
2511 |
|
---|
2512 |
|
---|
2513 | OcclusionQueriesQueryManager *queryManager =
|
---|
2514 | new OcclusionQueriesQueryManager(mHierarchyInterface,
|
---|
2515 | cam->getViewport(),
|
---|
2516 | queryModes);
|
---|
2517 |
|
---|
2518 | mVisibilityManager->SetQueryManager(queryManager);
|
---|
2519 |
|
---|
2520 | NodeInfoContainer visibleNodes;
|
---|
2521 | MeshInfoContainer visibleGeometry;
|
---|
2522 | PatchInfoContainer visiblePatches;
|
---|
2523 |
|
---|
2524 | if (mUseFromPointQueries)
|
---|
2525 | {
|
---|
2526 | queryManager->ComputeFromPointVisibility(cam->getDerivedPosition(),
|
---|
2527 | &visibleNodes,
|
---|
2528 | &visibleGeometry,
|
---|
2529 | &visiblePatches,
|
---|
2530 | relativeVisibility,
|
---|
2531 | approximateVisibility);
|
---|
2532 | }
|
---|
2533 | else
|
---|
2534 | {
|
---|
2535 | queryManager->ComputeCameraVisibility(*cam,
|
---|
2536 | &visibleNodes,
|
---|
2537 | &visibleGeometry,
|
---|
2538 | &visiblePatches,
|
---|
2539 | relativeVisibility,
|
---|
2540 | approximateVisibility);
|
---|
2541 | }
|
---|
2542 |
|
---|
2543 | if (0)
|
---|
2544 | {
|
---|
2545 | std::stringstream d;
|
---|
2546 | d << "Query mode: " << queryModes
|
---|
2547 | << " visible nodes: " << (int)visibleNodes.size()
|
---|
2548 | << " visible geometry: " << (int)visibleGeometry.size();
|
---|
2549 |
|
---|
2550 | LogManager::getSingleton().logMessage(d.str());
|
---|
2551 | }
|
---|
2552 |
|
---|
2553 | ///////////////////////
|
---|
2554 | //-- put items in render queue
|
---|
2555 |
|
---|
2556 | if (mQueryMode != EXACT_QUERIES)
|
---|
2557 | {
|
---|
2558 | ////////////
|
---|
2559 | //-- apply queries on geometry level
|
---|
2560 | AddVisibleNodeGeometryToQueue(visibleNodes, cam);
|
---|
2561 | }
|
---|
2562 | else
|
---|
2563 | {
|
---|
2564 | AddVisibleMeshGeometryToQueue(visibleGeometry, cam);
|
---|
2565 | }
|
---|
2566 |
|
---|
2567 | // reset depth pass
|
---|
2568 | mUseDepthPass = savedUseDepthPass;
|
---|
2569 |
|
---|
2570 | delete queryManager;
|
---|
2571 | }
|
---|
2572 |
|
---|
2573 | //-----------------------------------------------------------------------
|
---|
2574 | void OcclusionCullingSceneManagerFactory::destroyInstance(SceneManager* instance)
|
---|
2575 | {
|
---|
2576 | delete instance;
|
---|
2577 | }
|
---|
2578 |
|
---|
2579 | } // namespace Ogre
|
---|