source: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreIlluminationManager.h @ 2298

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