1 | #include "OgreIlluminationManager.h"
|
---|
2 | #include "OgreParticleSystemRenderer.h"
|
---|
3 | #include "OgreBillboardParticleRenderer.h"
|
---|
4 | #include "SpriteParticleRenderer.h"
|
---|
5 | #include "OgrePMEntryPointMapRenderingRun.h"
|
---|
6 | #include "OgrePMWeightComputeRenderingRun.h"
|
---|
7 |
|
---|
8 | OgreIlluminationManager* OgreIlluminationManager::instance = NULL;
|
---|
9 |
|
---|
10 | Vector3 sortfrom;
|
---|
11 | RenderingRunType sortType;
|
---|
12 |
|
---|
13 | class sortFromVector
|
---|
14 | {
|
---|
15 | public:
|
---|
16 | bool operator()(OgreSharedRuns* a, OgreSharedRuns* b)
|
---|
17 | {
|
---|
18 | float dist1 = (a->getRootPosition() - sortfrom).length();
|
---|
19 | float dist2 = (b->getRootPosition() - sortfrom).length();
|
---|
20 |
|
---|
21 | return dist1 > dist2;
|
---|
22 | }
|
---|
23 | };
|
---|
24 |
|
---|
25 | class sortFromVectorWithRunType
|
---|
26 | {
|
---|
27 | public:
|
---|
28 | bool operator()(OgreSharedRuns* a, OgreSharedRuns* b)
|
---|
29 | {
|
---|
30 | float dist1 = (a->getRootPosition(sortType) - sortfrom).length();
|
---|
31 | float dist2 = (b->getRootPosition(sortType) - sortfrom).length();
|
---|
32 |
|
---|
33 | return dist1 > dist2;
|
---|
34 | }
|
---|
35 | };
|
---|
36 |
|
---|
37 |
|
---|
38 | class VisibleFinderVisitor : public QueuedRenderableVisitor
|
---|
39 | {
|
---|
40 | private:
|
---|
41 | std::vector<const Renderable*>* visibleObjects;
|
---|
42 | public:
|
---|
43 |
|
---|
44 | VisibleFinderVisitor(std::vector<const Renderable*>* visibleObjectsVector)
|
---|
45 | {
|
---|
46 | this->visibleObjects = visibleObjectsVector;
|
---|
47 | }
|
---|
48 |
|
---|
49 | void visit(const Renderable* r)
|
---|
50 | {
|
---|
51 | OgreTechniqueGroup* tg = (OgreTechniqueGroup*) r->getRenderTechniqueGroup();
|
---|
52 |
|
---|
53 | if(tg != 0)
|
---|
54 | {
|
---|
55 | tg->validateSharedRuns();
|
---|
56 | visibleObjects->push_back(r);
|
---|
57 | }
|
---|
58 | }
|
---|
59 | bool visit(const Pass* p)
|
---|
60 | {
|
---|
61 | return true;
|
---|
62 | }
|
---|
63 | void visit(const RenderablePass* rp)
|
---|
64 | {
|
---|
65 | Renderable* r = rp->renderable;
|
---|
66 |
|
---|
67 | OgreTechniqueGroup* tg = (OgreTechniqueGroup*) r->getRenderTechniqueGroup();
|
---|
68 |
|
---|
69 | if(tg != 0)
|
---|
70 | {
|
---|
71 | tg->validateSharedRuns();
|
---|
72 | visibleObjects->push_back(r);
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | };
|
---|
77 |
|
---|
78 | OgreIlluminationManager::OgreIlluminationManager()
|
---|
79 | {
|
---|
80 | visitor = new VisibleFinderVisitor(&visibleObjects);
|
---|
81 | joinRuns = true;
|
---|
82 | maxRad = 400;
|
---|
83 | focusingMapSize = 32;
|
---|
84 | phaseTextureSize = 256;
|
---|
85 | shadowMapSizeDirectional = shadowMapSizePoint = shadowMapSizeSpot = 512;
|
---|
86 | useLISPSMDirectional = useLISPSMPoint = useLISPSMSpot = false;
|
---|
87 | blurSMDirectional = blurSMPoint = blurSMSpot = false;
|
---|
88 | focusingSMDirectional = focusingSMPoint = focusingSMSpot = true;
|
---|
89 | shadowMapMaterialNameDirectional = "GTP/Basic/Depth or GTP/Basic/DepthCCW";
|
---|
90 | shadowMapMaterialNamePoint = "GTP/Basic/Distance_NormalizedCCW";
|
---|
91 | shadowMapMaterialNameSpot = "GTP/Basic/Distance_NormalizedCCW";
|
---|
92 | areaLightRadius = 0.1;
|
---|
93 |
|
---|
94 | for(int i = 0; i < RUN_TYPE_COUNT; i++)
|
---|
95 | {
|
---|
96 | maxRads[(RenderingRunType)i] = (float) maxRad;
|
---|
97 | }
|
---|
98 |
|
---|
99 | //register rendertechnique factories
|
---|
100 | OgreColorCubeMapRenderTechniqueFactory* colorcube = new OgreColorCubeMapRenderTechniqueFactory();
|
---|
101 | addRenderTechniqueFactory(colorcube);
|
---|
102 | OgreDistanceCubeMapRenderTechniqueFactory* distcube = new OgreDistanceCubeMapRenderTechniqueFactory();
|
---|
103 | addRenderTechniqueFactory(distcube);
|
---|
104 | OgreConvoledCubeMapRenderTechniqueFactory* convcube = new OgreConvoledCubeMapRenderTechniqueFactory();
|
---|
105 | addRenderTechniqueFactory(convcube);
|
---|
106 | OgreCausticCasterRenderTechniqueFactory* caucast = new OgreCausticCasterRenderTechniqueFactory();
|
---|
107 | addRenderTechniqueFactory(caucast);
|
---|
108 | OgreCausticReceiverRenderTechniqueFactory* caurec = new OgreCausticReceiverRenderTechniqueFactory();
|
---|
109 | addRenderTechniqueFactory(caurec);
|
---|
110 | OgreDepthShadowReceiverRenderTechniqueFactory* dsrec = new OgreDepthShadowReceiverRenderTechniqueFactory();
|
---|
111 | addRenderTechniqueFactory(dsrec);
|
---|
112 | OgreSBBRenderTechniqueFactory* sbb = new OgreSBBRenderTechniqueFactory();
|
---|
113 | addRenderTechniqueFactory(sbb);
|
---|
114 | OgreFireRenderTechniqueFactory* fire = new OgreFireRenderTechniqueFactory();
|
---|
115 | addRenderTechniqueFactory(fire);
|
---|
116 | OgreHierarchicalParticleSystemTechniqueFactory* HPSF = new OgreHierarchicalParticleSystemTechniqueFactory();
|
---|
117 | addRenderTechniqueFactory(HPSF);
|
---|
118 | OgreIllumVolumeRenderTechniqueFactory* illumVolume = new OgreIllumVolumeRenderTechniqueFactory();
|
---|
119 | addRenderTechniqueFactory(illumVolume);
|
---|
120 | OgrePathMapRenderTechniqueFactory* pathmap = new OgrePathMapRenderTechniqueFactory();
|
---|
121 | addRenderTechniqueFactory(pathmap);
|
---|
122 | }
|
---|
123 |
|
---|
124 | OgreIlluminationManager::~OgreIlluminationManager()
|
---|
125 | {
|
---|
126 |
|
---|
127 | }
|
---|
128 |
|
---|
129 | OgreIlluminationManager& OgreIlluminationManager::getSingleton()
|
---|
130 | {
|
---|
131 | if(instance == NULL)
|
---|
132 | instance= new OgreIlluminationManager();
|
---|
133 |
|
---|
134 | return *instance;
|
---|
135 | }
|
---|
136 |
|
---|
137 | void OgreIlluminationManager::fillVisibleList( RenderQueue * rq )
|
---|
138 | {
|
---|
139 | visibleObjects.clear();
|
---|
140 |
|
---|
141 | RenderQueue::QueueGroupIterator queueIt = rq->_getQueueGroupIterator();
|
---|
142 |
|
---|
143 | while (queueIt.hasMoreElements())
|
---|
144 | {
|
---|
145 | RenderQueueGroup* pGroup = queueIt.getNext();
|
---|
146 |
|
---|
147 | RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
|
---|
148 |
|
---|
149 | while (groupIt.hasMoreElements())
|
---|
150 | {
|
---|
151 | RenderPriorityGroup* pPriorityGrp = groupIt.getNext();
|
---|
152 | const QueuedRenderableCollection& solids = pPriorityGrp->getSolidsBasic();
|
---|
153 | const QueuedRenderableCollection& transparents = pPriorityGrp->getTransparents();
|
---|
154 |
|
---|
155 | solids.acceptVisitor(visitor, QueuedRenderableCollection::OM_PASS_GROUP);
|
---|
156 | transparents.acceptVisitor(visitor, QueuedRenderableCollection::OM_SORT_ASCENDING);
|
---|
157 | }
|
---|
158 | }
|
---|
159 |
|
---|
160 | rq->clear();
|
---|
161 | }
|
---|
162 |
|
---|
163 | BillboardSet* OgreIlluminationManager::findRenderableInParticleSystem(ParticleSystem* system)
|
---|
164 | {
|
---|
165 | ParticleSystemRenderer* renderer = system->getRenderer();
|
---|
166 |
|
---|
167 | const String rendererType = renderer->getType();
|
---|
168 | if(rendererType == "billboard")
|
---|
169 | {
|
---|
170 | BillboardSet* bbSet = ((BillboardParticleRenderer*) renderer)->getBillboardSet();
|
---|
171 | return bbSet;
|
---|
172 | }
|
---|
173 |
|
---|
174 | if(rendererType == "sprite")
|
---|
175 | {
|
---|
176 | BillboardSet* bbSet = ((SpriteParticleRenderer*) renderer)->getSpriteSet();
|
---|
177 | return bbSet;
|
---|
178 | }
|
---|
179 |
|
---|
180 | OGRE_EXCEPT(0, "Unsupported particle renderable type", "OgreIlluminationManager::findRenderableInParticleSystem");
|
---|
181 |
|
---|
182 | return NULL;
|
---|
183 | }
|
---|
184 |
|
---|
185 | void OgreIlluminationManager::freeAllResources()
|
---|
186 | {
|
---|
187 | std::list<SharedRuns*>::iterator srit = this->sharedRunRoots.begin();
|
---|
188 | std::list<SharedRuns*>::iterator sritend = this->sharedRunRoots.end();
|
---|
189 | while(srit != sritend)
|
---|
190 | {
|
---|
191 | (*srit)->freeAllResources();
|
---|
192 | srit++;
|
---|
193 | }
|
---|
194 | sharedRunRoots.clear();
|
---|
195 |
|
---|
196 | this->sharedRunRoots.clear();
|
---|
197 |
|
---|
198 | this->globalSharedRuns.freeAllResources();
|
---|
199 |
|
---|
200 | std::map<String, OgreSharedRuns*>::iterator lrit = this->perLightRuns.begin();
|
---|
201 | std::map<String, OgreSharedRuns*>::iterator lritend = this->perLightRuns.end();
|
---|
202 |
|
---|
203 | while(lrit != lritend)
|
---|
204 | {
|
---|
205 | OgreSharedRuns* lightRuns = ((*lrit).second);
|
---|
206 | perLightRuns.erase(lrit);
|
---|
207 | lightRuns->freeAllResources();
|
---|
208 | delete lightRuns;
|
---|
209 | lrit++;
|
---|
210 | }
|
---|
211 | perLightRuns.clear();
|
---|
212 |
|
---|
213 | std::map<enum GlobalTargetType, GlobalUseRenderTarget*>::iterator grtit = this->globalTargets.begin();
|
---|
214 | std::map<enum GlobalTargetType, GlobalUseRenderTarget*>::iterator grtitend = this->globalTargets.end();
|
---|
215 | while(grtit != grtitend)
|
---|
216 | {
|
---|
217 | GlobalUseRenderTarget* rt = (*grtit).second;
|
---|
218 | globalTargets.erase(grtit);
|
---|
219 | delete rt;
|
---|
220 | grtit++;
|
---|
221 | }
|
---|
222 |
|
---|
223 | this->pathMapClusters.clear();
|
---|
224 | this->pathMapEntryPoints.clear();
|
---|
225 |
|
---|
226 | //delete rendertechniquegroups and cloned materials
|
---|
227 | SceneManager::MovableObjectIterator it = Root::getSingleton()._getCurrentSceneManager()
|
---|
228 | ->getMovableObjectIterator("Entity");
|
---|
229 | while(it.hasMoreElements())
|
---|
230 | {
|
---|
231 | MovableObject* o = it.getNext();
|
---|
232 | Entity* e = (Entity*) o;
|
---|
233 |
|
---|
234 | if( e->getParentSceneNode() == 0 )//Entity not attached
|
---|
235 | break;
|
---|
236 |
|
---|
237 | for(unsigned int s = 0; s < e->getNumSubEntities(); s++)
|
---|
238 | {
|
---|
239 | SubEntity* sube = e->getSubEntity(s);
|
---|
240 |
|
---|
241 | Material* mat = sube->getMaterial().getPointer();
|
---|
242 |
|
---|
243 | for(unsigned int t = 0 ; t < mat->getNumTechniques() ; t++)
|
---|
244 | {
|
---|
245 | Technique* tech = mat->getTechnique(t);
|
---|
246 |
|
---|
247 | for(unsigned int p = 0; p< tech->getNumPasses(); p++)
|
---|
248 | {
|
---|
249 | Pass* pass = tech->getPass(p);
|
---|
250 |
|
---|
251 | std::vector<IllumTechniqueParams*>& techniques = pass->getIllumTechniques();
|
---|
252 | if( techniques.size() > 0)
|
---|
253 | {
|
---|
254 | OgreTechniqueGroup* tg = (OgreTechniqueGroup*) sube->getRenderTechniqueGroup();
|
---|
255 | delete tg;
|
---|
256 | sube->setRenderTechniqueGroup(0);
|
---|
257 | }
|
---|
258 | }
|
---|
259 | }
|
---|
260 |
|
---|
261 | MaterialManager::getSingleton().remove(mat->getName());
|
---|
262 | }
|
---|
263 | }
|
---|
264 |
|
---|
265 |
|
---|
266 |
|
---|
267 |
|
---|
268 | }
|
---|
269 |
|
---|
270 | void OgreIlluminationManager::initTechniques(Entity* e)
|
---|
271 | {
|
---|
272 | if( e->getParentSceneNode() == 0 )//Entity not attached
|
---|
273 | return;
|
---|
274 |
|
---|
275 | OgreSharedRuns* sharedruns = 0;
|
---|
276 |
|
---|
277 | for(unsigned int s = 0; s < e->getNumSubEntities(); s++)
|
---|
278 | {
|
---|
279 | SubEntity* sube = e->getSubEntity(s);
|
---|
280 |
|
---|
281 | Material* mat = sube->getMaterial().getPointer();
|
---|
282 |
|
---|
283 | OgreRenderable* rend = 0;
|
---|
284 | OgreTechniqueGroup* group = 0;
|
---|
285 |
|
---|
286 | for(unsigned int t = 0 ; t < mat->getNumTechniques() ; t++)
|
---|
287 | {
|
---|
288 | Technique* tech = mat->getTechnique(t);
|
---|
289 |
|
---|
290 | for(unsigned int p = 0; p< tech->getNumPasses(); p++)
|
---|
291 | {
|
---|
292 | Pass* pass = tech->getPass(p);
|
---|
293 |
|
---|
294 | std::vector<IllumTechniqueParams*>& techniques = pass->getIllumTechniques();
|
---|
295 | if( techniques.size() > 0)
|
---|
296 | {
|
---|
297 | if(rend == 0)
|
---|
298 | {
|
---|
299 | rend = new OgreRenderable(e, s);
|
---|
300 | group = new OgreTechniqueGroup();
|
---|
301 | sube->setRenderTechniqueGroup(group);
|
---|
302 |
|
---|
303 | if( sharedruns == 0)
|
---|
304 | {
|
---|
305 | sharedruns = new OgreSharedRuns();
|
---|
306 | addSharedRuns(sharedruns);
|
---|
307 | }
|
---|
308 |
|
---|
309 | group->addSharedRun(sharedruns);
|
---|
310 | sharedruns->addRenderable(rend);
|
---|
311 | sharedruns->updateBounds();
|
---|
312 | }
|
---|
313 | String newMaterialName = mat->getName() + "_clone_" + rend->getName();
|
---|
314 | Material* newMat = mat->clone(newMaterialName).getPointer();
|
---|
315 | rend->setMaterialName(newMaterialName);
|
---|
316 | mat = sube->getMaterial().getPointer();
|
---|
317 | break;
|
---|
318 | }
|
---|
319 | }
|
---|
320 | }
|
---|
321 |
|
---|
322 |
|
---|
323 | for(unsigned int t = 0 ; t < mat->getNumTechniques() ; t++)
|
---|
324 | {
|
---|
325 | Technique* tech = mat->getTechnique(t);
|
---|
326 |
|
---|
327 | for(unsigned int p = 0; p< tech->getNumPasses(); p++)
|
---|
328 | {
|
---|
329 | Pass* pass = tech->getPass(p);
|
---|
330 |
|
---|
331 | std::vector<IllumTechniqueParams*>& techniques = pass->getIllumTechniques();
|
---|
332 | std::vector<IllumTechniqueParams*>::iterator i = techniques.begin();
|
---|
333 | std::vector<IllumTechniqueParams*>::iterator iend = techniques.end();
|
---|
334 |
|
---|
335 | while( i != iend)
|
---|
336 | {
|
---|
337 | IllumTechniqueParams* params = *i;
|
---|
338 | createTechnique(params, pass, rend, sharedruns);
|
---|
339 |
|
---|
340 | i++;
|
---|
341 | }
|
---|
342 | }
|
---|
343 | }
|
---|
344 | }
|
---|
345 |
|
---|
346 |
|
---|
347 | }
|
---|
348 |
|
---|
349 |
|
---|
350 | void OgreIlluminationManager::initTechniques(BillboardSet* bbs, ParticleSystem* sys)
|
---|
351 | {
|
---|
352 | if( bbs->getParentSceneNode() == 0 )//billboardset not attached
|
---|
353 | return;
|
---|
354 |
|
---|
355 | OgreSharedRuns* sharedruns = 0;
|
---|
356 |
|
---|
357 | Material* mat = bbs->getMaterial().getPointer();
|
---|
358 |
|
---|
359 | OgreRenderable* rend = 0;
|
---|
360 | OgreTechniqueGroup* group = 0;
|
---|
361 |
|
---|
362 | for(unsigned int t = 0 ; t < mat->getNumTechniques() ; t++)
|
---|
363 | {
|
---|
364 | Technique* tech = mat->getTechnique(t);
|
---|
365 |
|
---|
366 | for(unsigned int p = 0; p< tech->getNumPasses(); p++)
|
---|
367 | {
|
---|
368 | Pass* pass = tech->getPass(p);
|
---|
369 |
|
---|
370 | std::vector<IllumTechniqueParams*>& techniques = pass->getIllumTechniques();
|
---|
371 | std::vector<IllumTechniqueParams*>::iterator i = techniques.begin();
|
---|
372 | std::vector<IllumTechniqueParams*>::iterator iend = techniques.end();
|
---|
373 |
|
---|
374 | while( i != iend)
|
---|
375 | {
|
---|
376 | IllumTechniqueParams* params = *i;
|
---|
377 |
|
---|
378 | if(rend == 0)
|
---|
379 | {
|
---|
380 | rend = new OgreRenderable(bbs, sys);
|
---|
381 | group = new OgreTechniqueGroup();
|
---|
382 | bbs->setRenderTechniqueGroup(group);
|
---|
383 |
|
---|
384 | if( sharedruns == 0)
|
---|
385 | {
|
---|
386 | sharedruns = new OgreSharedRuns();
|
---|
387 | addSharedRuns(sharedruns);
|
---|
388 | }
|
---|
389 |
|
---|
390 | group->addSharedRun(sharedruns);
|
---|
391 | sharedruns->addRenderable(rend);
|
---|
392 | sharedruns->updateBounds();
|
---|
393 | }
|
---|
394 |
|
---|
395 | createTechnique(params, pass, rend, sharedruns);
|
---|
396 |
|
---|
397 | i++;
|
---|
398 | }
|
---|
399 | }
|
---|
400 | }
|
---|
401 |
|
---|
402 | }
|
---|
403 |
|
---|
404 | void OgreIlluminationManager::initTechniques()
|
---|
405 | {
|
---|
406 | {
|
---|
407 | //Entities
|
---|
408 | SceneManager::MovableObjectIterator it = Root::getSingleton()._getCurrentSceneManager()
|
---|
409 | ->getMovableObjectIterator("Entity");
|
---|
410 | while(it.hasMoreElements())
|
---|
411 | {
|
---|
412 | MovableObject* o = it.getNext();
|
---|
413 | Entity* e = (Entity*) o;
|
---|
414 |
|
---|
415 | initTechniques(e);
|
---|
416 | }
|
---|
417 | }
|
---|
418 | {
|
---|
419 | //ParticleSystems
|
---|
420 | SceneManager::MovableObjectIterator it = Root::getSingleton()._getCurrentSceneManager()
|
---|
421 | ->getMovableObjectIterator("ParticleSystem");
|
---|
422 | while(it.hasMoreElements())
|
---|
423 | {
|
---|
424 | MovableObject* o = it.getNext();
|
---|
425 | ParticleSystem* psys = (ParticleSystem*) o;
|
---|
426 |
|
---|
427 | try
|
---|
428 | {
|
---|
429 | BillboardSet* bbset = findRenderableInParticleSystem(psys);
|
---|
430 | bbset->setMaterialName(psys->getMaterialName());
|
---|
431 | initTechniques(bbset, psys);
|
---|
432 | }
|
---|
433 | catch( ... )
|
---|
434 | {
|
---|
435 | //unsupported particle renderer, skip init
|
---|
436 | }
|
---|
437 | }
|
---|
438 | }
|
---|
439 | }
|
---|
440 |
|
---|
441 | void OgreIlluminationManager::createTechnique(IllumTechniqueParams* params, Pass* pass, OgreRenderable* rend, OgreSharedRuns* sRuns)
|
---|
442 | {
|
---|
443 | std::list<RenderTechniqueFactory*>::iterator it = techniqueFactories.begin();
|
---|
444 | std::list<RenderTechniqueFactory*>::iterator itend = techniqueFactories.end();
|
---|
445 |
|
---|
446 | OgreTechniqueGroup* group = (OgreTechniqueGroup*) rend->getRenderable()->getRenderTechniqueGroup();
|
---|
447 |
|
---|
448 |
|
---|
449 | while(it != itend)
|
---|
450 | {
|
---|
451 | RenderTechniqueFactory* factory = *it;
|
---|
452 |
|
---|
453 |
|
---|
454 | if(factory->isType(params->getTypeName()))
|
---|
455 | {
|
---|
456 |
|
---|
457 | RenderTechnique* newTechnique = factory->createInstance(params,
|
---|
458 | pass,
|
---|
459 | rend,
|
---|
460 | group );
|
---|
461 |
|
---|
462 | group->addRenderTechnique(newTechnique);
|
---|
463 |
|
---|
464 | }
|
---|
465 |
|
---|
466 | it++;
|
---|
467 | }
|
---|
468 | }
|
---|
469 | void OgreIlluminationManager::preAllUpdates()
|
---|
470 | {
|
---|
471 | std::vector<UpdateListener*>::iterator it = updateListeners.begin();
|
---|
472 | std::vector<UpdateListener*>::iterator itend = updateListeners.end();
|
---|
473 |
|
---|
474 | while(it != itend)
|
---|
475 | {
|
---|
476 | UpdateListener* l = *it;
|
---|
477 | l->preAllUpdates();
|
---|
478 | it++;
|
---|
479 | }
|
---|
480 | }
|
---|
481 |
|
---|
482 | void OgreIlluminationManager::postAllUpdates()
|
---|
483 | {
|
---|
484 | std::vector<UpdateListener*>::iterator it = updateListeners.begin();
|
---|
485 | std::vector<UpdateListener*>::iterator itend = updateListeners.end();
|
---|
486 |
|
---|
487 | while(it != itend)
|
---|
488 | {
|
---|
489 | UpdateListener* l = *it;
|
---|
490 | l->postAllUpdates();
|
---|
491 | it++;
|
---|
492 | }
|
---|
493 | }
|
---|
494 |
|
---|
495 | void OgreIlluminationManager::update(unsigned long frameNumber, RenderTarget* rt)
|
---|
496 | {
|
---|
497 |
|
---|
498 | RenderSystem* renderSystem = Root::getSingleton().getRenderSystem();
|
---|
499 | SceneManager* sceneManager = Root::getSingleton()._getCurrentSceneManager();
|
---|
500 |
|
---|
501 | for(unsigned short i = 0; i<rt->getNumViewports();i++)
|
---|
502 | {
|
---|
503 | //find visible objects from the camera
|
---|
504 | RenderQueue* rq = sceneManager->getRenderQueue();
|
---|
505 | rq->clear();
|
---|
506 | RenderQueue::QueueGroupIterator groupIter = rq->_getQueueGroupIterator();
|
---|
507 | while (groupIter.hasMoreElements())
|
---|
508 | {
|
---|
509 | RenderQueueGroup* g = groupIter.getNext();
|
---|
510 | //g->addOrganisationMode(QueuedRenderableCollection::OM_SORT_ASCENDING);
|
---|
511 | g->defaultOrganisationMode();
|
---|
512 | }
|
---|
513 |
|
---|
514 | //sceneManager->_findVisibleObjectsOC(rt->getViewport(i)->getCamera(), rt->getViewport(i), false, false, false);
|
---|
515 | sceneManager->_findVisibleObjects(rt->getViewport(i)->getCamera(), false);
|
---|
516 |
|
---|
517 | fillVisibleList(rq);
|
---|
518 |
|
---|
519 | if(joinRuns)
|
---|
520 | {
|
---|
521 | int l = visibleObjects.size(); //debug
|
---|
522 | joinSharedRuns();
|
---|
523 | int ll = sharedRunRoots.size(); //debug
|
---|
524 | }
|
---|
525 |
|
---|
526 | //update precomputings
|
---|
527 | std::vector<const Renderable*>::iterator iter = visibleObjects.begin();
|
---|
528 | const std::vector<const Renderable*>::iterator iend = visibleObjects.end();
|
---|
529 |
|
---|
530 | preAllUpdates();
|
---|
531 |
|
---|
532 | while(iter != iend)
|
---|
533 | {
|
---|
534 | const Renderable* rend = *iter;
|
---|
535 | OgreTechniqueGroup* techniqueGroup = (OgreTechniqueGroup*) rend->getRenderTechniqueGroup();
|
---|
536 | if(techniqueGroup != 0)
|
---|
537 | {
|
---|
538 | techniqueGroup->update(frameNumber);
|
---|
539 | }
|
---|
540 | iter++;
|
---|
541 | }
|
---|
542 |
|
---|
543 | postAllUpdates();
|
---|
544 | }
|
---|
545 | }
|
---|
546 |
|
---|
547 | void OgreIlluminationManager::sharedRunSplit(SharedRuns* old, SharedRuns* new1, SharedRuns* new2)
|
---|
548 | {
|
---|
549 | sharedRunRoots.remove(old);
|
---|
550 | sharedRunRoots.push_back(new1);
|
---|
551 | sharedRunRoots.push_back(new2);
|
---|
552 | }
|
---|
553 |
|
---|
554 | void OgreIlluminationManager::sharedRunJoin(SharedRuns* old1, SharedRuns* old2, SharedRuns* newsr)
|
---|
555 | {
|
---|
556 | sharedRunRoots.remove(old1);
|
---|
557 | sharedRunRoots.remove(old2);
|
---|
558 | sharedRunRoots.push_back(newsr);
|
---|
559 | }
|
---|
560 |
|
---|
561 | void OgreIlluminationManager::joinSharedRuns()
|
---|
562 | {
|
---|
563 | std::list<SharedRuns*>::iterator it1 = sharedRunRoots.begin();
|
---|
564 | std::list<SharedRuns*>::iterator itend = sharedRunRoots.end();
|
---|
565 |
|
---|
566 | bool again = false;
|
---|
567 |
|
---|
568 | while(it1 != itend)
|
---|
569 | {
|
---|
570 | std::list<SharedRuns*>::iterator it2 = sharedRunRoots.begin();
|
---|
571 |
|
---|
572 | while(it2 != itend)
|
---|
573 | {
|
---|
574 | if( it1 != it2 && OgreSharedRuns::canJoin(*it1, *it2))
|
---|
575 | {
|
---|
576 | SharedRuns* newruns = (*it1)->joinRuns(*it2);
|
---|
577 | sharedRunJoin(*it1, *it2, newruns);
|
---|
578 | again = true;
|
---|
579 | break;
|
---|
580 | }
|
---|
581 | it2++;
|
---|
582 | }
|
---|
583 |
|
---|
584 | if(again)
|
---|
585 | break;
|
---|
586 |
|
---|
587 | it1++;
|
---|
588 | }
|
---|
589 | if(again)
|
---|
590 | joinSharedRuns();
|
---|
591 |
|
---|
592 | }
|
---|
593 |
|
---|
594 | void OgreIlluminationManager::addSharedRuns(SharedRuns* runs)
|
---|
595 | {
|
---|
596 | sharedRunRoots.push_back(runs);
|
---|
597 | }
|
---|
598 |
|
---|
599 | void OgreIlluminationManager::getNearestCausticCasters(Vector3 position, std::vector<OgreSharedRuns*>* nearestcasters, unsigned int maxCount)
|
---|
600 | {
|
---|
601 | sortfrom = position;
|
---|
602 | std::vector<OgreSharedRuns*> allcasters;
|
---|
603 | //fill casters
|
---|
604 | std::list<SharedRuns*>::iterator it = sharedRunRoots.begin();
|
---|
605 | std::list<SharedRuns*>::iterator itend = sharedRunRoots.end();
|
---|
606 | while(it != itend)
|
---|
607 | {
|
---|
608 | OgreSharedRuns* sr = (OgreSharedRuns*) (*it);
|
---|
609 |
|
---|
610 | sr->findSharedRootsForType(ILLUMRUN_CAUSTIC_CUBEMAP, allcasters);
|
---|
611 |
|
---|
612 | it++;
|
---|
613 | }
|
---|
614 |
|
---|
615 | //sort
|
---|
616 | std::stable_sort(allcasters.begin(), allcasters.end(), sortFromVector());
|
---|
617 |
|
---|
618 | for(unsigned int i = 0; i < maxCount && i < allcasters.size(); i++)
|
---|
619 | {
|
---|
620 | nearestcasters->push_back(allcasters.at(i));
|
---|
621 | }
|
---|
622 | }
|
---|
623 |
|
---|
624 | void OgreIlluminationManager::createGlobalRun(RenderingRunType runType)
|
---|
625 | {
|
---|
626 | switch(runType)
|
---|
627 | {
|
---|
628 | case ILLUMRUN_SCENE_CAMERA_DEPTH:
|
---|
629 | if(globalSharedRuns.getRun(ILLUMRUN_SCENE_CAMERA_DEPTH) == 0)
|
---|
630 | {
|
---|
631 | OgreSceneCameraDepthRenderingRun* run = new OgreSceneCameraDepthRenderingRun
|
---|
632 | (&globalSharedRuns, "ILLUMMODULE_SCENE_CAMERA_DEPTH", mainViewport);
|
---|
633 | globalSharedRuns.addRun(ILLUMRUN_SCENE_CAMERA_DEPTH, run);
|
---|
634 | }
|
---|
635 | case ILLUMRUN_FOCUSING_MAP:
|
---|
636 | if(globalSharedRuns.getRun(ILLUMRUN_FOCUSING_MAP) == 0)
|
---|
637 | {
|
---|
638 | OgreFocusingMapRenderingRun* run = new OgreFocusingMapRenderingRun(
|
---|
639 | "LIGHT_FOCUSING_MAP",
|
---|
640 | Matrix4::IDENTITY,
|
---|
641 | focusingMapSize
|
---|
642 | );
|
---|
643 | globalSharedRuns.addRun(ILLUMRUN_FOCUSING_MAP, run);
|
---|
644 |
|
---|
645 | }
|
---|
646 | case ILLUMRUN_PHASE_TEXTURE:
|
---|
647 | if(globalSharedRuns.getRun(ILLUMRUN_PHASE_TEXTURE) == 0)
|
---|
648 | {
|
---|
649 | OgrePhaseTextureRenderingRun* run = new OgrePhaseTextureRenderingRun(
|
---|
650 | "PHASE_TEXTURE",
|
---|
651 | phaseTextureSize,
|
---|
652 | phaseTextureSize,
|
---|
653 | "Phase_HenyeyGreenStein");
|
---|
654 | globalSharedRuns.addRun(ILLUMRUN_PHASE_TEXTURE, run);
|
---|
655 | }
|
---|
656 | break;
|
---|
657 | case ILLUMRUN_PM_ENTRYPOINTMAP:
|
---|
658 | if(globalSharedRuns.getRun(ILLUMRUN_PM_ENTRYPOINTMAP) == 0)
|
---|
659 | {
|
---|
660 | OgrePMEntryPointMapRenderingRun* run = new OgrePMEntryPointMapRenderingRun(
|
---|
661 | "PM_ENTRYPOINT_MAP");
|
---|
662 | globalSharedRuns.addRun(ILLUMRUN_PM_ENTRYPOINTMAP, run);
|
---|
663 | }
|
---|
664 | break;
|
---|
665 | }
|
---|
666 | }
|
---|
667 |
|
---|
668 | void OgreIlluminationManager::savePhaseTextureToFile(String filename)
|
---|
669 | {
|
---|
670 | OgrePhaseTextureRenderingRun* r = (OgrePhaseTextureRenderingRun*)
|
---|
671 | globalSharedRuns.getRun(ILLUMRUN_PHASE_TEXTURE)->asOgreRenderingRun();
|
---|
672 | Texture* t = (Texture*) TextureManager::getSingleton().getByName(r->getPhaseTextureName()).getPointer();
|
---|
673 |
|
---|
674 | t->getBuffer()->getRenderTarget()->writeContentsToFile(filename);
|
---|
675 | }
|
---|
676 |
|
---|
677 | RenderingRun* OgreIlluminationManager::getGlobalRun(RenderingRunType runType)
|
---|
678 | {
|
---|
679 | if(globalSharedRuns.getRun(runType) == 0)
|
---|
680 | createGlobalRun(runType);
|
---|
681 | return globalSharedRuns.getRun(runType);
|
---|
682 | }
|
---|
683 |
|
---|
684 | GlobalUseRenderTarget* OgreIlluminationManager::getGlobalTarget(GlobalTargetType type)
|
---|
685 | {
|
---|
686 | std::map<GlobalTargetType, GlobalUseRenderTarget*>::iterator it = globalTargets.find(type);
|
---|
687 |
|
---|
688 | if( it != globalTargets.end())
|
---|
689 | return (*it).second;
|
---|
690 |
|
---|
691 | return 0;
|
---|
692 | }
|
---|
693 |
|
---|
694 | void OgreIlluminationManager::addGlobalTarget(GlobalTargetType type, GlobalUseRenderTarget* target)
|
---|
695 | {
|
---|
696 | globalTargets[type] = target;
|
---|
697 | }
|
---|
698 |
|
---|
699 | void OgreIlluminationManager::updateGlobalRun(RenderingRunType runType, unsigned long frameNum)
|
---|
700 | {
|
---|
701 | globalSharedRuns.updateRun(runType, frameNum);
|
---|
702 | }
|
---|
703 |
|
---|
704 | void OgreIlluminationManager::createPerLightRun(String lightName, RenderingRunType runType)
|
---|
705 | {
|
---|
706 | OgreSharedRuns* runs = 0;
|
---|
707 |
|
---|
708 | if(perLightRuns.find(lightName) == perLightRuns.end())
|
---|
709 | {///create sharedruns
|
---|
710 | OgreSharedRuns* newruns = new OgreSharedRuns();
|
---|
711 | perLightRuns[lightName] = newruns;
|
---|
712 | }
|
---|
713 |
|
---|
714 | runs = perLightRuns[lightName];
|
---|
715 |
|
---|
716 | switch(runType)
|
---|
717 | {
|
---|
718 | case ILLUMRUN_DEPTH_SHADOWMAP:
|
---|
719 | if(runs->getRun(ILLUMRUN_DEPTH_SHADOWMAP) == 0)
|
---|
720 | {
|
---|
721 | SceneManager* sm = Root::getSingleton()._getCurrentSceneManager();
|
---|
722 | Light* light = sm->getLight(lightName);
|
---|
723 | unsigned int res;
|
---|
724 | String MaterialName;
|
---|
725 | switch(light->getType())
|
---|
726 | {
|
---|
727 | case Light::LT_DIRECTIONAL:
|
---|
728 | res = shadowMapSizeDirectional;
|
---|
729 | MaterialName = shadowMapMaterialNameDirectional;
|
---|
730 | break;
|
---|
731 | case Light::LT_POINT:
|
---|
732 | res = shadowMapSizePoint;
|
---|
733 | MaterialName = shadowMapMaterialNamePoint;
|
---|
734 | break;
|
---|
735 | case Light::LT_SPOTLIGHT:
|
---|
736 | res = shadowMapSizeSpot;
|
---|
737 | MaterialName = shadowMapMaterialNameSpot;
|
---|
738 | break;
|
---|
739 | }
|
---|
740 |
|
---|
741 | OgreDepthShadowMapRenderingRun* run = new OgreDepthShadowMapRenderingRun(
|
---|
742 | runs,
|
---|
743 | lightName + "DEPTH_SHADOW_MAP",
|
---|
744 | light,
|
---|
745 | res,
|
---|
746 | res,
|
---|
747 | MaterialName
|
---|
748 | );
|
---|
749 | runs->addRun(ILLUMRUN_DEPTH_SHADOWMAP, run);
|
---|
750 |
|
---|
751 | }
|
---|
752 | break;
|
---|
753 | case ILLUMRUN_PM_WEIGHTMAP:
|
---|
754 | if(runs->getRun(ILLUMRUN_PM_WEIGHTMAP) == 0)
|
---|
755 | {
|
---|
756 | SceneManager* sm = Root::getSingleton()._getCurrentSceneManager();
|
---|
757 | OgrePMWeightComputeRenderingRun* run = new OgrePMWeightComputeRenderingRun(
|
---|
758 | lightName + "PM_WEIGHT_MAP",
|
---|
759 | lightName);
|
---|
760 | runs->addRun(ILLUMRUN_PM_WEIGHTMAP, run);
|
---|
761 | }
|
---|
762 | break;
|
---|
763 | }
|
---|
764 | }
|
---|
765 |
|
---|
766 | RenderingRun* OgreIlluminationManager::getPerLightRun(String lightName, RenderingRunType runType)
|
---|
767 | {
|
---|
768 | return perLightRuns[lightName]->getRun(runType);
|
---|
769 | }
|
---|
770 |
|
---|
771 | void OgreIlluminationManager::updatePerLightRun(String lightName, RenderingRunType runType, unsigned long frameNum)
|
---|
772 | {
|
---|
773 | perLightRuns[lightName]->updateRun(runType, frameNum);
|
---|
774 | }
|
---|
775 |
|
---|