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