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