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