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