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