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