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