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

Revision 2189, 12.0 KB checked in by szirmay, 17 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 "OgreCausticRecieverRenderTechnique.h"
11#include "OgreSceneCameraDepthRenderingRun.h"
12#include "OgreSBBRenderTechnique.h"
13#include "OgreDepthShadowMapRenderingRun.h"
14#include "OgreDepthShadowRecieverRenderTechnique.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
24struct PathMapClusters
25{
26        unsigned int count;
27        unsigned int* clusters;
28        String pathMapTextureFilename;
29        unsigned int pathMapResolution;
30};
31
32struct PathMapEntryPoint
33{
34    Vector3 position;
35        Vector3 normal;
36};
37/**
38        @brief Implementation of IlluminationManager in an OGRE environment.
39*/
40class OgreIlluminationManager: public FrameListener
41{
42protected:
43        /**
44                @brief Protected constructor (OgreIlluminationManager is a singleton).
45        */
46        OgreIlluminationManager();
47        /**
48                @brief Protected destructor.
49        */
50        virtual ~OgreIlluminationManager();
51       
52        /**
53                @brief Searches for visible renderables with valid TechniqueGroups in a renderqueue.
54
55                @param rq pointer to the RenderQueue instance to search in
56        */
57        void fillVisibleList(  RenderQueue * rq);
58        /**
59                @brief creates a specific type of RenderTechnique for a Renderable's pass.
60
61                It searches all registered RenderTechniqueFactories.
62        */
63        void createTechnique(IllumTechniqueParams* params, Pass* pass, OgreRenderable* rend, OgreSharedRuns* sRuns);
64        /**
65                @brief A helper function to find the renderable object attached to a particle system (ONLY BILLBOARDSETS ARE SUPPORTED).
66
67                @param system pointer to the ParticleSystem instance to search in
68                @return pointer the connected BillboardSet instance
69        */
70        BillboardSet* findRenderableInParticleSystem(ParticleSystem* system);
71        void preAllUpdates();
72        void postAllUpdates();
73
74        /**
75                @brief registered RenderTechniqueFactories
76        */
77        std::list<RenderTechniqueFactory*> techniqueFactories;
78        /**
79                @brief The maximum bounding sphere radius that groupped objects ( see SharedRuns class ) can have
80                @see canJoin
81                @see joinRuns
82        */
83        float maxRad;
84        unsigned int focusingMapSize;
85        unsigned int shadowMapSize;
86        float areaLightRadius;
87        bool useLISPSM;
88        bool useVSM;
89        bool blurSM;
90        bool focusingSM;
91        String shadowMapMaterialName;
92        unsigned int phaseTextureSize;
93        std::map<RenderingRunType,float> maxRads;
94        std::map<String, PathMapClusters> pathMapClusters;
95        std::vector<PathMapEntryPoint> pathMapEntryPoints;
96        std::vector<unsigned int> pathMapClusterLengths;
97        /**
98                @brief The camera attached to the player.
99        */
100        Camera* mainCamera;
101        /**
102                @brief The viewport of the player camera.
103        */
104        Viewport* mainViewport;
105        /**
106                @brief VisibleFinderVisitor instance.
107               
108                Used for adding visible renderables with valid TechniqueGroups to the visibleObjects vector.
109        */
110        class VisibleFinderVisitor* visitor;
111        /**
112                @brief The one and only OgreIlluminationManager instance.
113        */
114        static OgreIlluminationManager* instance;
115        /**
116                @brief Vector containing visible renderables with valid TechniqueGroups that must be refreshed.
117        */
118        std::vector<const Renderable*> visibleObjects;
119        /**
120                @brief List containing SharedRuns roots.
121
122                It is the IlluminationManager's task to find the SharedRuns which can be joined.
123                Only the root SharedRuns needs to be checked.
124        */
125        std::list<SharedRuns*> sharedRunRoots;
126        /**
127                @brief Group of RenderingRuns that are used globaly.
128
129                Some RenderingRuns have only one instance per application (for example scene depth map).
130                These resources are shared between all RenderTechniques.
131        */
132        OgreSharedRuns globalSharedRuns;
133        /**
134                @brief Stores groups of RenderingRuns that are attached to individual light sources.
135
136                These resources need separate instances for each lightsource ( for example depth shadow maps).
137                They are grouped by the name of the lightsource.
138        */
139        std::map<String, OgreSharedRuns*> perLightRuns;
140
141        std::map<GlobalTargetType, GlobalUseRenderTarget*> globalTargets;
142
143        std::vector<UpdateListener*> updateListeners;
144
145public:
146
147        void addUpdateListener(UpdateListener* l){updateListeners.push_back(l);}
148        /**
149                @brief registers a RenderTechniqueFactory
150        */
151        void addRenderTechniqueFactory(RenderTechniqueFactory* factory)
152        {
153                techniqueFactories.push_back(factory);
154        }
155        /**
156                @brief retirieves the maximum bounding sphere radius with two SharedRuns can be joined.
157        */
158        float getMaxJoinRadius(){return maxRad;}
159        float getMaxJoinRadius(RenderingRunType type){return maxRads[type];}
160        /**
161                @brief sets the maximum bounding sphere radius with two SharedRuns can be joined.
162        */
163        void setMaxJoinRadius(float rad)
164        {
165                std::map<RenderingRunType,float> ::iterator it = maxRads.begin();
166                std::map<RenderingRunType,float> ::iterator itend = maxRads.end();
167               
168                maxRad = rad;
169       
170                while(it != itend)
171                {
172                        (*it).second = maxRad;
173                        it++;
174                }
175               
176        }
177        void setMaxJoinRadius(RenderingRunType type, float rad){maxRads[type] = rad;}
178        void setFocusingMapSize(unsigned int size){focusingMapSize = size;}
179        void setPhaseTextureSize(unsigned int size){phaseTextureSize = size;}
180        void setShadowMapSize(unsigned int size){shadowMapSize = size;}
181        /**
182                @brief Returns the one and only OgreIlluminationManager instance.
183        */
184        static OgreIlluminationManager& getSingleton();
185        /**
186                @brief The function to be called to render one frame.
187
188                This is the main refreshing function. It seasrches for visible objects, manages shared runs, updates render techniques and
189                finally renders the scene to framebuffer.
190
191                @param frameNumber current framenumber
192                @param rt the rendertarget window. Needed to find the viewports that need to be refresh.
193        */
194        void update(unsigned long frameNumber, RenderTarget* rt);
195        /**
196                @brief searches for RenderTechniques in materials and creates them for all objects.
197        */
198        void initTechniques();
199        /**
200                @brief searches for RenderTechniques in materials and creates them for an Entity.
201        */
202        void initTechniques(Entity* e);
203        /**
204                @brief searches for RenderTechniques in materials and creates them for a Billboardset.
205        */
206        void initTechniques(BillboardSet* bbs, ParticleSystem* sys);
207        /**
208                @brief Returns a pointer to the player camera.
209
210                @return pointer to the main player camera. Needed by RenderTechnique and RenderingRun classes.
211        */
212        Camera* getMainCamera(){return mainCamera;}
213        /**
214                @brief Returns a pointer to the viewport attached to the player camera.
215
216                @return pointer to the viewport. Needed by RenderTechnique and RenderingRun classes.
217        */
218        Viewport* getMainViewport(){return mainViewport;}
219        /**
220                @brief Sets the player camera.
221
222                @param camera pointer to the main player camera
223        */
224        void setMainCamera(Camera* camera){mainCamera = camera;}
225        /**
226                @brief Sets the viewport attached to the player camera.
227
228                @param viewport pointer to the viewport
229        */
230        void setMainViewport(Viewport* viewport){mainViewport = viewport;}
231        /**
232                @brief The function to be called when a shared run is splitted.
233
234                @param old pointer to the SharedRuns instance that is split
235                @param new1 pointer to one of the SharedRuns instance that remain after split
236                @param new2 pointer to the other SharedRuns instance that remain after split
237        */
238        void sharedRunSplit(SharedRuns* old, SharedRuns* new1, SharedRuns* new2);
239        /**
240                @brief The function to be called when two shared runs are joined.
241
242                @param old1 pointer to one of the SharedRuns instance that are joined
243                @param old2 pointer to the other SharedRuns instance that are joined
244                @param newsr pointer to the resulting parent SharedRuns instance
245        */
246        void sharedRunJoin(SharedRuns* old1, SharedRuns* old2, SharedRuns* newsr);
247        /**
248                @brief Joins shared runs if needed.
249
250                Searches the registered shared run roots and join them if necessary (they are close enough).
251        */
252        void joinSharedRuns();
253        /**
254                @brief Register a shared run object.
255               
256                Only called when new techniques are created.
257
258                @param runs pointer to the SharedRuns instance to add
259        */
260        void addSharedRuns(SharedRuns* runs);
261        /**
262                @brief Searches for the nearest object groups (SharedRuns) that are caustic casters from a given point.
263
264                @param position the point to obtain distances from
265                @param nearestcasters vector to put the nearest caustic caster SharedRuns to
266                @param maxCount the maximum number of nearest casters to search for
267        */
268        void getNearestCausticCasters(Vector3 position, std::vector<OgreSharedRuns*>* nearestcasters, unsigned int maxCount);
269        /**
270                @brief Creates a global RenderingRun of the given type.
271
272                If  a RenderingRun with the given type already exist there is nothing to do.
273
274                @param runType type enum of the RenderingRun to create
275        */
276        void createGlobalRun(RenderingRunType runType);
277        /**
278                @brief Returns the global RendderingRun with the given type
279
280                @param runType type enum of the RenderingRun to retrieve
281
282                @return pointer to the RenderingRun, NULL if no RenderingRun with the given type exists
283        */
284        RenderingRun* getGlobalRun(RenderingRunType runType);
285
286        GlobalUseRenderTarget* getGlobalTarget(GlobalTargetType type);
287        void addGlobalTarget(GlobalTargetType type, GlobalUseRenderTarget* target);
288        /**
289                @brief Updates a global RenderingRun with the given type.
290
291                @param runType type enum of the RenderingRun to update
292                @param frameNum current framenumber
293        */
294        void updateGlobalRun(RenderingRunType runType, unsigned long frameNum);
295        /**
296                @brief Creates a RenderingRun attached to a lightsource with the given type.
297
298                @param lightName name of the lightsource
299                @param runType type enum of the RenderingRun to create
300        */
301        void createPerLightRun(String lightName, RenderingRunType runType);
302        /**
303                @brief Retuns a RenderingRun attached to a lightsource with the given type.
304
305                @param lightName name of the lightsource
306                @param runType type enum of the RenderingRun to return
307
308                @return pointer to the RenderingRun, NULL if no RenderingRun with the given type exists
309        */
310        RenderingRun* getPerLightRun(String lightName, RenderingRunType runType);
311        /**
312                @brief Updates a RenderingRun attached to a lightsource with the given type.
313
314                @param lightName name of the lightsource
315                @param runType type enum of the RenderingRun to update
316                @param frameNum current framenumber
317        */
318        void updatePerLightRun(String lightName, RenderingRunType runType, unsigned long frameNum);
319
320        void savePhaseTextureToFile(String filename);
321
322        bool frameStarted(const FrameEvent& evt)
323    {
324                update(Root::getSingleton().getCurrentFrameNumber(), mainViewport->getTarget());
325                return FrameListener::frameStarted(evt);
326        }
327
328        bool getUseLISPSM(){return useLISPSM;}
329        bool getUseVSM(){return useVSM;}
330        bool getFocusingShadowMap(){return focusingSM;}
331        bool getBlurShadowMap(){return blurSM;}
332        void setUseLISPSM(bool use){useLISPSM = use;}
333        void setUseVSM(bool use){useVSM = use;}
334        void setFocusingSM(bool use){focusingSM = use;}
335        void setBlurShadowMap(bool use){blurSM = use;}
336        void setShadowMapMaterialName(String name){shadowMapMaterialName = name;}
337
338        void addPathMapClusters(String subEntityName, PathMapClusters clusters)
339        {
340                this->pathMapClusters[subEntityName] = clusters;
341        }
342        PathMapClusters* getPathMapClusters(String subEntityName)
343        {
344                return &pathMapClusters[subEntityName];
345        }
346        void addPathMapEntryPoint(PathMapEntryPoint p)
347        {
348                this->pathMapEntryPoints.push_back(p);
349        }
350        std::vector<PathMapEntryPoint>& getPathMapEntryPoints()
351        {
352                return pathMapEntryPoints;
353        }
354        void addPathMapClusterLength(unsigned int l)
355        {
356                this->pathMapClusterLengths.push_back(l);
357        }
358        unsigned int getPathMapClusterLengthsSize()
359        {
360                return this->pathMapClusterLengths.size();
361        }
362        unsigned int getPathMapClusterLength(unsigned int index)
363        {
364                return pathMapClusterLengths.at(index);
365        }
366        float getAreaLightRadius(){return areaLightRadius;}
367        void setAreaLigtRadius(float radius){areaLightRadius = radius;}
368};
369
Note: See TracBrowser for help on using the repository browser.