source: GTP/branches/IllumWPdeliver2008dec/IlluminationWP/precompiled/include/OgreIllumModule/OgreIlluminationManager.h @ 3255

Revision 3255, 19.2 KB checked in by szirmay, 15 years ago (diff)
Line 
1#pragma once
2
3#include "Ogre.h"
4#include "OgreTechniqueGroup.h"
5#include "GTPOgreRenderable.h"
6
7
8using namespace Ogre;
9
10/**
11 @brief Structure to store path map cluster information for a subentity.
12*/
13struct PathMapClusters
14{
15        /**
16                @brief the number of clusters this subentity belongs to
17        */
18        unsigned int count;
19        /**
20                @brief the indices of the cluster this subentity belongs to.
21        */
22        unsigned int* clusters;
23        /**
24                @brief the name of the path map file this subentity uses
25        */
26        String pathMapTextureFilename;
27        /**
28                @brief the resolution of the path map file.
29        */
30        unsigned int pathMapResolution;
31};
32
33/**
34        @brief Structure of a path map entry point.
35*/
36struct PathMapEntryPoint
37{
38        /**
39                @brief the position of the entry point.
40        */
41    Vector3 position;
42        /**
43                @brief the normal of the entry point.
44        */
45        Vector3 normal;
46        /**
47                @brief the probability of the entry point.
48        */
49        float prob;
50        int clusterID;
51};
52
53/**
54        @brief Implementation of IlluminationManager in an OGRE environment.
55*/
56class __declspec( dllexport ) OgreIlluminationManager: public FrameListener
57{
58protected:
59        /**
60                @brief Protected constructor (OgreIlluminationManager is a singleton).
61        */
62        OgreIlluminationManager();
63        /**
64                @brief Protected destructor.
65        */
66        virtual ~OgreIlluminationManager();
67       
68        /**
69                @brief Searches for visible renderables with valid TechniqueGroups in a renderqueue.
70
71                @param rq pointer to the RenderQueue instance to search in
72        */
73        void fillVisibleList(  RenderQueue * rq);
74        /**
75                @brief creates a specific type of RenderTechnique for a Renderable's pass.
76
77                It searches all registered RenderTechniqueFactories.
78        */
79        void createTechnique(IllumTechniqueParams* params, Pass* pass, OgreRenderable* rend, OgreSharedRuns* sRuns);
80        bool needMaterialCopyForTechnique(IllumTechniqueParams* params);
81        /**
82                @brief A helper function to find the renderable object attached to a particle system (ONLY BILLBOARDSETS ARE SUPPORTED).
83
84                @param system pointer to the ParticleSystem instance to search in
85                @return pointer the connected BillboardSet instance
86        */
87        BillboardSet* findRenderableInParticleSystem(ParticleSystem* system);
88        /**
89                @brief Fires preAllUpdates for registered UpdateListeners.
90
91                This is called in each frame before updating the RenderTechniques.
92        */
93        void preAllUpdates();
94        /**
95                @brief Fires postAllUpdates for registered UpdateListeners.
96
97                This is called in each frame after updating the RenderTechniques.
98        */
99        void postAllUpdates();
100
101        /**
102                @brief registered RenderTechniqueFactories
103        */
104        std::list<RenderTechniqueFactory*> techniqueFactories;
105        /**
106                @brief The maximum bounding sphere radius that groupped objects ( see SharedRuns class __declspec( dllexport ) ) can have
107                @see canJoin
108                @see joinRuns
109        */
110        float maxRad;
111        /**
112                @brief Size of the focusing map.
113
114                This map is used if the shadow maps should be focused.
115        */
116        unsigned int focusingMapSize;
117        /**
118                @brief Size of the shadow maps.
119        */
120        unsigned int shadowMapSizePoint;
121        unsigned int shadowMapSizeSpot;
122        unsigned int shadowMapSizeDirectional;
123        /**
124                @brief Size of area lights for soft shadows.
125        */
126        float areaLightRadius;
127        /**
128                @brief Sets if light space perspective shadow mapping should be used.
129        */
130        bool useLISPSMPoint;
131        bool useLISPSMSpot;
132        bool useLISPSMDirectional;
133        /**
134                @brief Sets if the shadow maps should be blurred.
135
136                Used in variance shadow mapping.
137        */
138        bool blurSMPoint;
139        bool blurSMSpot;
140        bool blurSMDirectional;
141        /**
142                @brief Sets if shadow maps should be focused.
143        */
144        bool focusingSMPoint;
145        bool focusingSMSpot;
146        bool focusingSMDirectional;
147        /**
148                @brief The material name that should be used during rendering the shadow maps.
149
150                There are several predefined materials that can be used to render shadow maps:
151                 - GTP/Basic/Depth : writes projected depth values of front facing polygons
152                 - GTP/Basic/DepthCCW : writes projected depth values of back facing polygons
153                 - GTP/Basic/Distance : writes distance values (from eyepoint) of front facing polygons
154                 - GTP/Basic/DistanceCCW : writes distance values (from eyepoint) of back facing polygons
155                 - GTP/Basic/Distance_Normalized : writes normalized distance values
156                        (distance values devided by projection farplane - which is set to the attenuation range in case of shadow maps) of front facing polygons
157                 - GTP/Basic/Distance_NormalizedCCW : writes normalized distance values of back facing polygons
158
159                 The default material is GTP/Basic/Distance_NormalizedCCW.
160                 Recommended materials for different light types:
161                 - spot and point lights : GTP/Basic/Distance_NormalizedCCW or GTP/Basic/Distance_Normalized
162                 - directional lights : GTP/Basic/Depth or GTP/Basic/DepthCCW
163        */
164        String shadowMapMaterialNamePoint;
165        String shadowMapMaterialNameSpot;
166        String shadowMapMaterialNameDirectional;
167        /**
168                @brief Size of the phase texture.
169        */
170        unsigned int phaseTextureSize;
171        /**
172                @brief Stores maximum bounding radius values for each rendering run type.
173        */
174        std::map<RenderingRunType,float> maxRads;
175        /**
176                @brief Stores PathMapClusters structures for each subentity.
177
178                The String key is the name of the subentity.
179        */
180        std::map<String, PathMapClusters> pathMapClusters;
181        /**
182                @brief PathMapEntryPoint list.
183        */
184        std::vector<PathMapEntryPoint> pathMapEntryPoints;
185        /**
186                @brief Stores cluster size for each path map cluster.
187        */
188        std::vector<unsigned int> pathMapClusterLengths;
189        /**
190                @brief The camera attached to the player.
191        */
192        Camera* mainCamera;
193        /**
194                @brief The viewport of the player camera.
195        */
196        Viewport* mainViewport;
197        /**
198                @brief VisibleFinderVisitor instance.
199               
200                Used for adding visible renderables with valid TechniqueGroups to the visibleObjects vector.
201        */
202        class __declspec( dllexport ) VisibleFinderVisitor* visitor;
203        /**
204                @brief The one and only OgreIlluminationManager instance.
205        */
206        static OgreIlluminationManager* instance;
207        /**
208                @brief Vector containing visible renderables with valid TechniqueGroups that must be refreshed.
209        */
210        std::vector<const Renderable*> visibleObjects;
211        /**
212                @brief List containing SharedRuns roots.
213
214                It is the IlluminationManager's task to find the SharedRuns which can be joined.
215                Only the root SharedRuns needs to be checked.
216        */
217        std::list<SharedRuns*> sharedRunRoots;
218        /**
219                @brief Group of RenderingRuns that are used globaly.
220
221                Some RenderingRuns have only one instance per application (for example scene depth map).
222                These resources are shared between all RenderTechniques.
223        */
224        OgreSharedRuns globalSharedRuns;
225        /**
226                @brief Stores groups of RenderingRuns that are attached to individual light sources.
227
228                These resources need separate instances for each lightsource ( for example depth shadow maps).
229                They are grouped by the name of the lightsource.
230        */
231        std::map<String, OgreSharedRuns*> perLightRuns;
232        /**
233                @brief
234        */
235        std::map<GlobalTargetType, GlobalUseRenderTarget*> globalTargets;
236        /**
237                @brief Stores registered UpdateListeners.
238        */
239        std::vector<UpdateListener*> updateListeners;
240
241        bool joinRuns;
242
243public:
244
245        void joinSharedRuns(bool join){joinRuns = join;}
246        /**
247                @brief Registers an UpdateListener instance. @see UpdateListener
248        */
249        void addUpdateListener(UpdateListener* l){updateListeners.push_back(l);}
250        /**
251                @brief registers a RenderTechniqueFactory
252        */
253        void addRenderTechniqueFactory(RenderTechniqueFactory* factory)
254        {
255                techniqueFactories.push_back(factory);
256        }
257        /**
258                @brief retirieves the maximum bounding sphere radius with two SharedRuns can be joined.
259
260                Only valid fi all run types use the same radius. This can be set with calling setMaxJoinRadius().
261                @see setMaxJoinRadius
262        */
263        float getMaxJoinRadius(){return maxRad;}
264        /**
265                @brief Retirieves the maximum shared bounding sphere radius for a given run type.
266        */
267        float getMaxJoinRadius(RenderingRunType type){return maxRads[type];}
268        /**
269                @brief sets the maximum bounding sphere radius with two SharedRuns can be joined for all run type.
270        */
271        void setMaxJoinRadius(float rad)
272        {
273                std::map<RenderingRunType,float> ::iterator it = maxRads.begin();
274                std::map<RenderingRunType,float> ::iterator itend = maxRads.end();
275               
276                maxRad = rad;
277       
278                while(it != itend)
279                {
280                        (*it).second = maxRad;
281                        it++;
282                }
283               
284        }
285        /**
286                @brief Sets the maximum shared bounding sphere radius for a given run type.
287        */
288        void setMaxJoinRadius(RenderingRunType type, float rad){maxRads[type] = rad;}
289        /**
290                @see focusingMapSize
291        */
292        void setFocusingMapSize(unsigned int size){focusingMapSize = size;}
293        /**
294                @see phaseTextureSize
295        */
296        void setPhaseTextureSize(unsigned int size){phaseTextureSize = size;}
297        /**
298                @see shadowMapSize
299        */
300        void setShadowMapSize(unsigned int size)
301        {
302                shadowMapSizeDirectional = size;
303                shadowMapSizePoint = size;
304                shadowMapSizeSpot = size;
305        }
306        void setShadowMapSize(Light::LightTypes type, unsigned int size)
307        {
308                switch(type)
309                {
310                        case Light::LT_DIRECTIONAL:
311                                shadowMapSizeDirectional = size;break;
312                        case Light::LT_POINT:
313                                shadowMapSizePoint = size;break;
314                        case Light::LT_SPOTLIGHT:
315                                shadowMapSizeSpot = size;break;
316                }
317        }
318        /**
319                @brief Returns the one and only OgreIlluminationManager instance.
320        */
321        static OgreIlluminationManager& getSingleton();
322        /**
323                @brief The function to be called to render one frame.
324
325                This is the main refreshing function. It seasrches for visible objects, manages shared runs, updates render techniques and
326                finally renders the scene to framebuffer.
327
328                @param frameNumber current framenumber
329                @param rt the rendertarget window. Needed to find the viewports that need to be refresh.
330        */
331        void update(unsigned long frameNumber, RenderTarget* rt);
332        /**
333                @brief searches for RenderTechniques in materials and creates them for all objects.
334        */
335        void initTechniques();
336        /**
337                @brief searches for RenderTechniques in materials and creates them for an Entity.
338        */
339        void initTechniques(Entity* e);
340        /**
341                @brief searches for RenderTechniques in materials and creates them for a Billboardset.
342        */
343        void initTechniques(BillboardSet* bbs, ParticleSystem* sys);
344        /**
345                @brief Returns a pointer to the player camera.
346
347                @return pointer to the main player camera. Needed by RenderTechnique and RenderingRun class __declspec( dllexport )es.
348        */
349        Camera* getMainCamera(){return mainCamera;}
350        /**
351                @brief Returns a pointer to the viewport attached to the player camera.
352
353                @return pointer to the viewport. Needed by RenderTechnique and RenderingRun class __declspec( dllexport )es.
354        */
355        Viewport* getMainViewport(){return mainViewport;}
356        /**
357                @brief Sets the player camera.
358
359                @param camera pointer to the main player camera
360        */
361        void setMainCamera(Camera* camera){mainCamera = camera;}
362        /**
363                @brief Sets the viewport attached to the player camera.
364
365                @param viewport pointer to the viewport
366        */
367        void setMainViewport(Viewport* viewport){mainViewport = viewport;}
368        /**
369                @brief The function to be called when a shared run is splitted.
370
371                @param old pointer to the SharedRuns instance that is split
372                @param new1 pointer to one of the SharedRuns instance that remain after split
373                @param new2 pointer to the other SharedRuns instance that remain after split
374        */
375        void sharedRunSplit(SharedRuns* old, SharedRuns* new1, SharedRuns* new2);
376        /**
377                @brief The function to be called when two shared runs are joined.
378
379                @param old1 pointer to one of the SharedRuns instance that are joined
380                @param old2 pointer to the other SharedRuns instance that are joined
381                @param newsr pointer to the resulting parent SharedRuns instance
382        */
383        void sharedRunJoin(SharedRuns* old1, SharedRuns* old2, SharedRuns* newsr);
384        /**
385                @brief Joins shared runs if needed.
386
387                Searches the registered shared run roots and join them if necessary (they are close enough).
388        */
389        void joinSharedRuns();
390        /**
391                @brief Register a shared run object.
392               
393                Only called when new techniques are created.
394
395                @param runs pointer to the SharedRuns instance to add
396        */
397        void addSharedRuns(SharedRuns* runs);
398        /**
399                @brief Searches for the nearest object groups (SharedRuns) that are caustic casters from a given point.
400
401                @param position the point to obtain distances from
402                @param nearestcasters vector to put the nearest caustic caster SharedRuns to
403                @param maxCount the maximum number of nearest casters to search for
404        */
405        void getNearestCausticCasters(Vector3 position, std::vector<OgreSharedRuns*>* nearestcasters, unsigned int maxCount);
406        /**
407                @brief Creates a global RenderingRun of the given type.
408
409                If  a RenderingRun with the given type already exist there is nothing to do.
410
411                @param runType type enum of the RenderingRun to create
412        */
413        void createGlobalRun(RenderingRunType runType);
414        /**
415                @brief Returns the global RendderingRun with the given type
416
417                @param runType type enum of the RenderingRun to retrieve
418
419                @return pointer to the RenderingRun, NULL if no RenderingRun with the given type exists
420        */
421        RenderingRun* getGlobalRun(RenderingRunType runType);
422
423        // These GlobalUseRenderTargets are only used in fire render technique. Maybe it could be solved with global rendering runs too.
424        GlobalUseRenderTarget* getGlobalTarget(GlobalTargetType type);
425        void addGlobalTarget(GlobalTargetType type, GlobalUseRenderTarget* target);
426
427        /**
428                @brief Updates a global RenderingRun with the given type.
429
430                @param runType type enum of the RenderingRun to update
431                @param frameNum current framenumber
432        */
433        void updateGlobalRun(RenderingRunType runType, unsigned long frameNum);
434        /**
435                @brief Creates a RenderingRun attached to a lightsource with the given type.
436
437                @param lightName name of the lightsource
438                @param runType type enum of the RenderingRun to create
439        */
440        void createPerLightRun(String lightName, RenderingRunType runType);
441        /**
442                @brief Retuns a RenderingRun attached to a lightsource with the given type.
443
444                @param lightName name of the lightsource
445                @param runType type enum of the RenderingRun to return
446
447                @return pointer to the RenderingRun, NULL if no RenderingRun with the given type exists
448        */
449        RenderingRun* getPerLightRun(String lightName, RenderingRunType runType);
450        /**
451                @brief Updates a RenderingRun attached to a lightsource with the given type.
452
453                @param lightName name of the lightsource
454                @param runType type enum of the RenderingRun to update
455                @param frameNum current framenumber
456        */
457        void updatePerLightRun(String lightName, RenderingRunType runType, unsigned long frameNum);
458        /**
459                @brief Saves the phase texture to the given file.
460        */
461        void savePhaseTextureToFile(String filename);
462        /**
463                @brief Frame listener event handler function.
464               
465                Inherited from FrameListener. Called at the beginning of each frame.
466        */
467        bool frameStarted(const FrameEvent& evt)
468    {
469                update(Root::getSingleton().getCurrentFrameNumber(), mainViewport->getTarget());
470                return FrameListener::frameStarted(evt);
471        }       
472        /**
473                @see useLISPSM
474        */
475        bool getUseLISPSM(Light::LightTypes type)
476        {
477                switch(type)
478                {
479                        case Light::LT_DIRECTIONAL:
480                        return useLISPSMDirectional;
481                        case Light::LT_POINT:
482                        return useLISPSMPoint;
483                        case Light::LT_SPOTLIGHT:
484                        return useLISPSMSpot;
485                }
486        }
487        /**
488                @see focusingSM
489        */
490        bool getFocusingShadowMap(Light::LightTypes type)
491        {
492                switch(type)
493                {
494                        case Light::LT_DIRECTIONAL:
495                        return focusingSMDirectional;
496                        case Light::LT_POINT:
497                        return focusingSMPoint;
498                        case Light::LT_SPOTLIGHT:
499                        return focusingSMSpot;
500                }
501        }
502        /**
503                @see blurSM
504        */
505        bool getBlurShadowMap(Light::LightTypes type)
506        {
507                switch(type)
508                {
509                        case Light::LT_DIRECTIONAL:
510                        return blurSMDirectional;
511                        case Light::LT_POINT:
512                        return blurSMPoint;
513                        case Light::LT_SPOTLIGHT:
514                        return blurSMSpot;
515                }
516        }
517        /**
518                @see useLISPSM
519        */
520        void setUseLISPSM(bool use)
521        {
522                useLISPSMDirectional = use;
523                useLISPSMPoint = use;
524                useLISPSMSpot = use;
525        }
526        void setUseLISPSM(Light::LightTypes type, bool use)
527        {
528                switch(type)
529                {
530                        case Light::LT_DIRECTIONAL:
531                                useLISPSMDirectional = use;break;
532                        case Light::LT_POINT:
533                                useLISPSMPoint = use;break;
534                        case Light::LT_SPOTLIGHT:
535                                useLISPSMSpot = use;break;
536                }
537        }
538        /**
539                @see focusingSM
540        */
541        void setFocusingSM(bool use)
542        {
543                focusingSMDirectional = use;
544                focusingSMPoint = use;
545                focusingSMSpot = use;
546        }
547        void setFocusingSM(Light::LightTypes type, bool use)
548        {
549                switch(type)
550                {
551                        case Light::LT_DIRECTIONAL:
552                                focusingSMDirectional = use;break;
553                        case Light::LT_POINT:
554                                focusingSMPoint = use;break;
555                        case Light::LT_SPOTLIGHT:
556                                focusingSMSpot = use;break;
557                }
558        }
559        /**
560                @see blurSM
561        */
562        void setBlurShadowMap(bool use)
563        {
564                blurSMDirectional = use;
565                blurSMPoint = use;
566                blurSMSpot = use;
567        }
568        void setBlurShadowMap(Light::LightTypes type, bool use)
569        {
570                switch(type)
571                {
572                        case Light::LT_DIRECTIONAL:
573                                blurSMDirectional = use;break;
574                        case Light::LT_POINT:
575                                blurSMPoint = use;break;
576                        case Light::LT_SPOTLIGHT:
577                                blurSMSpot = use;break;
578                }
579        }
580        /**
581                @see shadowMapMaterialName
582        */
583        void setShadowMapMaterialName(String name)
584        {
585                shadowMapMaterialNameDirectional = name;
586                shadowMapMaterialNamePoint = name;
587                shadowMapMaterialNameSpot = name;
588        }
589        void setShadowMapMaterialName(Light::LightTypes type, String name)
590        {
591                switch(type)
592                {
593                        case Light::LT_DIRECTIONAL:
594                                shadowMapMaterialNameDirectional = name;break;
595                        case Light::LT_POINT:
596                                shadowMapMaterialNamePoint = name;break;
597                        case Light::LT_SPOTLIGHT:
598                                shadowMapMaterialNameSpot = name;break;
599                }
600        }
601        /**
602                @brief Registers a PathMapClusters structure for a given subentity.
603
604                @param subEntityName name of te subentity
605                @param clusters the PathMapClusters that belongs to the given subentity
606        */
607        void addPathMapClusters(String subEntityName, PathMapClusters clusters)
608        {
609                this->pathMapClusters[subEntityName] = clusters;
610        }
611        /**
612                @brief Returns the PathMapClusters structure registered for a given subentity.
613
614                @param subEntityName name of te subentity
615                @return pointer to the PathMapClusters structure that belongs to the given subentity
616        */
617        PathMapClusters* getPathMapClusters(String subEntityName)
618        {
619                return &pathMapClusters[subEntityName];
620        }
621        /**
622                @brief Adds a new PathMapEntryPoint cluster to the entrypoint list.
623        */
624        void addPathMapEntryPoint(PathMapEntryPoint p)
625        {
626                this->pathMapEntryPoints.push_back(p);
627        }
628        /**
629                @brief Returns the list of entrypoints.
630        */
631        std::vector<PathMapEntryPoint>& getPathMapEntryPoints()
632        {
633                return pathMapEntryPoints;
634        }
635        /**
636                @brief Adds a new cluster size.
637        */
638        void addPathMapClusterLength(unsigned int l)
639        {
640                this->pathMapClusterLengths.push_back(l);
641        }
642        /**
643                @brief Gets the number of clusters.
644        */
645        unsigned int getPathMapClusterLengthsSize()
646        {
647                return this->pathMapClusterLengths.size();
648        }
649        /**
650                @brief Gets the size of the given cluster.
651
652                @param index of the cluster
653                @return the size of the cluster
654        */
655        unsigned int getPathMapClusterLength(unsigned int index)
656        {
657                return pathMapClusterLengths.at(index);
658        }
659        /**
660                @see areaLightRadius
661        */
662        float getAreaLightRadius(){return areaLightRadius;}
663        /**
664                @see areaLightRadius
665        */
666        void setAreaLigtRadius(float radius){areaLightRadius = radius;}
667        /**
668                @brief Sets the fire rendertarget - frame buffer resolution ratio
669        */
670        inline void setFireRenderTargetSize(int size);
671
672        void freeAllResources();
673};
674
Note: See TracBrowser for help on using the repository browser.