1 | #include "OgreCausticCasterRenderTechnique.h"
|
---|
2 | #include "OgreTechniqueGroup.h"
|
---|
3 | #include "OgreCausticCubeMapRenderingRun.h"
|
---|
4 | #include "OgrePhotonMapRenderingRun.h"
|
---|
5 | #include "OgreCubeMapRenderingRun.h"
|
---|
6 |
|
---|
7 |
|
---|
8 | OgreCausticCasterRenderTechnique::OgreCausticCasterRenderTechnique(unsigned long startFrame,
|
---|
9 | unsigned long photonMapUpdateInterval,
|
---|
10 | unsigned int photonMapResolution,
|
---|
11 | unsigned int causticCubeMapResolution,
|
---|
12 | String photonMapMaterialName,
|
---|
13 | String causticMapMaterialName,
|
---|
14 | unsigned char photonMapTexID,
|
---|
15 | bool updateAllFace,
|
---|
16 | bool useDistance,
|
---|
17 | float attenuation,
|
---|
18 | bool useTriangles,
|
---|
19 | bool blurCauCubeMap,
|
---|
20 | Pass* pass,
|
---|
21 | OgreRenderable* parentRenderable,
|
---|
22 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
23 | :OgreRenderTechnique( pass, parentRenderable, parentTechniqueGroup),
|
---|
24 | CausticCasterRenderTechnique(startFrame, photonMapUpdateInterval, photonMapResolution, causticCubeMapResolution, updateAllFace, useDistance, parentRenderable, parentTechniqueGroup),
|
---|
25 | RenderTechnique( parentRenderable, parentTechniqueGroup)
|
---|
26 | {
|
---|
27 | this->attenuation = attenuation;
|
---|
28 | this->useTriangles = useTriangles;
|
---|
29 | this->photonMapMaterialName = photonMapMaterialName;
|
---|
30 | this->blurCauCubeMap = blurCauCubeMap;
|
---|
31 |
|
---|
32 | String newMaterialName = causticMapMaterialName + "_clone_" + parentRenderable->getName();
|
---|
33 | Material* mat = (Material*) MaterialManager::getSingleton().getByName(causticMapMaterialName).getPointer();
|
---|
34 | Material* newMat = mat->clone(newMaterialName).getPointer();
|
---|
35 | this->causticMapMaterialName = newMat->getName();
|
---|
36 | //this->causticMapMaterialName =causticMapMaterialName;
|
---|
37 |
|
---|
38 | this->photonMapTexID = photonMapTexID;
|
---|
39 |
|
---|
40 | if(sharedRuns->getRun(ILLUMRUN_CAUSTIC_CUBEMAP) == 0)
|
---|
41 | sharedRuns->addRun(ILLUMRUN_CAUSTIC_CUBEMAP, createCausticCubeMapRun());
|
---|
42 | if(sharedRuns->getRun(ILLUMRUN_PHOTONMAP) == 0)
|
---|
43 | sharedRuns->addRun(ILLUMRUN_PHOTONMAP, createPhotonMapRun());
|
---|
44 |
|
---|
45 | if(useDistance)
|
---|
46 | {
|
---|
47 | if(sharedRuns->getRun(ILLUMRUN_DISTANCE_CUBEMAP) == 0)
|
---|
48 | sharedRuns->addRun(ILLUMRUN_DISTANCE_CUBEMAP, createDistanceCubeMapRun());
|
---|
49 | distanceCubeMapRunChanged(sharedRuns->getRun(ILLUMRUN_DISTANCE_CUBEMAP));
|
---|
50 | }
|
---|
51 |
|
---|
52 | photonMapRunChanged(sharedRuns->getRun(ILLUMRUN_PHOTONMAP));
|
---|
53 | causticCubeMapRunChanged(sharedRuns->getRun(ILLUMRUN_CAUSTIC_CUBEMAP));
|
---|
54 | }
|
---|
55 |
|
---|
56 | OgreCausticCasterRenderTechnique::~OgreCausticCasterRenderTechnique()
|
---|
57 | {
|
---|
58 | MaterialManager::getSingleton().remove(causticMapMaterialName);
|
---|
59 | }
|
---|
60 |
|
---|
61 | void OgreCausticCasterRenderTechnique::photonMapRunChanged(RenderingRun* run)
|
---|
62 | {
|
---|
63 | OgreCausticCubeMapRenderingRun* caurun = (OgreCausticCubeMapRenderingRun*)
|
---|
64 | sharedRuns->getRun(ILLUMRUN_CAUSTIC_CUBEMAP)->asOgreRenderingRun();
|
---|
65 | caurun->photonMapChanged(sharedRuns->getRun(ILLUMRUN_PHOTONMAP));
|
---|
66 | }
|
---|
67 |
|
---|
68 | void OgreCausticCasterRenderTechnique::distanceCubeMapRunChanged(RenderingRun* run)
|
---|
69 | {
|
---|
70 | if(useDistance)
|
---|
71 | {
|
---|
72 | OgrePhotonMapRenderingRun* photonrun = (OgrePhotonMapRenderingRun*)
|
---|
73 | sharedRuns->getRun(ILLUMRUN_PHOTONMAP)->asOgreRenderingRun();
|
---|
74 | photonrun->distanceCubeMapChanged(sharedRuns->getRun(ILLUMRUN_DISTANCE_CUBEMAP));
|
---|
75 | }
|
---|
76 | }
|
---|
77 | void OgreCausticCasterRenderTechnique::distanceCubeMapRunUpdated(RenderingRun* run)
|
---|
78 | {
|
---|
79 | if(useDistance)
|
---|
80 | {
|
---|
81 | OgrePhotonMapRenderingRun* photonrun = (OgrePhotonMapRenderingRun*)
|
---|
82 | sharedRuns->getRun(ILLUMRUN_PHOTONMAP)->asOgreRenderingRun();
|
---|
83 | photonrun->distanceCubeMapUpdated(sharedRuns->getRun(ILLUMRUN_DISTANCE_CUBEMAP));
|
---|
84 | }
|
---|
85 | }
|
---|
86 | void OgreCausticCasterRenderTechnique::causticCubeMapRunChanged(RenderingRun* run)
|
---|
87 | {
|
---|
88 | }
|
---|
89 |
|
---|
90 | RenderingRun* OgreCausticCasterRenderTechnique::createPhotonMapRun()
|
---|
91 | {
|
---|
92 | return new OgrePhotonMapRenderingRun((OgreSharedRuns*) sharedRuns,
|
---|
93 | parentOgreRenderable->getName() + "_PHOTONMAP",
|
---|
94 | startFrame,
|
---|
95 | photonMapUpdateInterval,
|
---|
96 | photonMapResolution,
|
---|
97 | photonMapMaterialName,
|
---|
98 | useDistance);
|
---|
99 |
|
---|
100 | }
|
---|
101 |
|
---|
102 | RenderingRun* OgreCausticCasterRenderTechnique::createCausticCubeMapRun()
|
---|
103 | {
|
---|
104 | return new OgreCausticCubeMapRenderingRun((OgreSharedRuns*) sharedRuns,
|
---|
105 | parentOgreRenderable->getName() + "_CAUSTICCUBEMAP",
|
---|
106 | startFrame,
|
---|
107 | photonMapUpdateInterval,
|
---|
108 | causticCubeMapResolution,
|
---|
109 | causticMapMaterialName,
|
---|
110 | photonMapTexID,
|
---|
111 | updateAllFace,
|
---|
112 | attenuation,
|
---|
113 | useTriangles,
|
---|
114 | blurCauCubeMap
|
---|
115 | );
|
---|
116 |
|
---|
117 | }
|
---|
118 |
|
---|
119 | RenderingRun* OgreCausticCasterRenderTechnique::createDistanceCubeMapRun()
|
---|
120 | {
|
---|
121 | return new OgreCubeMapRenderingRun((OgreSharedRuns*) sharedRuns,
|
---|
122 | parentOgreRenderable->getName() + "_DISTANCECUBEMAP",
|
---|
123 | startFrame,
|
---|
124 | photonMapUpdateInterval,
|
---|
125 | causticCubeMapResolution,
|
---|
126 | 0,
|
---|
127 | 0,
|
---|
128 | 0,
|
---|
129 | 0,
|
---|
130 | updateAllFace,
|
---|
131 | false,
|
---|
132 | true,
|
---|
133 | "",
|
---|
134 | "GTP/Basic/Distance",
|
---|
135 | "ILLUM_TRIGGER_DISTANCE",
|
---|
136 | false,
|
---|
137 | ILLUMRUN_DISTANCE_CUBEMAP);
|
---|
138 |
|
---|
139 | }
|
---|
140 |
|
---|
141 | const String& OgreCausticCasterRenderTechnique::getCausticCubeMapName()
|
---|
142 | {
|
---|
143 | return ((OgreCausticCubeMapRenderingRun*) sharedRuns->getRun(ILLUMRUN_CAUSTIC_CUBEMAP)->asOgreRenderingRun())->
|
---|
144 | getCausticCubeMapTextureName();
|
---|
145 | }
|
---|
146 |
|
---|
147 |
|
---|
148 | ///Technique Parsers
|
---|
149 | namespace CausticCasterParsers
|
---|
150 | {
|
---|
151 | void parseStartFrame(String& params, RenderTechniqueFactory* factory)
|
---|
152 | {
|
---|
153 | OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory;
|
---|
154 | f->startFrame = StringConverter::parseUnsignedLong(params);
|
---|
155 | }
|
---|
156 | void parsePhotonMapUpdateInterval(String& params, RenderTechniqueFactory* factory)
|
---|
157 | {
|
---|
158 | OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory;
|
---|
159 | f->photonMapUpdateInterval = StringConverter::parseUnsignedLong(params);
|
---|
160 | }
|
---|
161 |
|
---|
162 | void parsePhotonMapResolution(String& params, RenderTechniqueFactory* factory)
|
---|
163 | {
|
---|
164 | OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory;
|
---|
165 | f->photonMapResolution = StringConverter::parseUnsignedInt(params);
|
---|
166 | }
|
---|
167 |
|
---|
168 | void parseCausticCubeMapResolution(String& params, RenderTechniqueFactory* factory)
|
---|
169 | {
|
---|
170 | OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory;
|
---|
171 | f->causticCubeMapResolution = StringConverter::parseUnsignedInt(params);
|
---|
172 | }
|
---|
173 |
|
---|
174 | void parseTexID(String& params, RenderTechniqueFactory* factory)
|
---|
175 | {
|
---|
176 | OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory;
|
---|
177 | f->photonMapTexID = StringConverter::parseUnsignedInt(params);
|
---|
178 | }
|
---|
179 |
|
---|
180 | void parseUseDistance(String& params, RenderTechniqueFactory* factory)
|
---|
181 | {
|
---|
182 | OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory;
|
---|
183 | f->useDistance = StringConverter::parseBool(params);
|
---|
184 | }
|
---|
185 |
|
---|
186 | void parseUpdateAllFace(String& params, RenderTechniqueFactory* factory)
|
---|
187 | {
|
---|
188 | OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory;
|
---|
189 | f->updateAllFace = StringConverter::parseBool(params);
|
---|
190 | }
|
---|
191 |
|
---|
192 | void parsePhotonMapMaterial(String& params, RenderTechniqueFactory* factory)
|
---|
193 | {
|
---|
194 | OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory;
|
---|
195 | f->photonMapMaterialName = params;
|
---|
196 | }
|
---|
197 |
|
---|
198 | void parseCauMapMaterial(String& params, RenderTechniqueFactory* factory)
|
---|
199 | {
|
---|
200 | OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory;
|
---|
201 | f->causticMapMaterialName = params;
|
---|
202 | }
|
---|
203 |
|
---|
204 | void parseAttenuation(String& params, RenderTechniqueFactory* factory)
|
---|
205 | {
|
---|
206 | OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory;
|
---|
207 | f->attenuation = StringConverter::parseReal(params);
|
---|
208 | }
|
---|
209 |
|
---|
210 | void parseUseTriangles(String& params, RenderTechniqueFactory* factory)
|
---|
211 | {
|
---|
212 | OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory;
|
---|
213 | f->useTriangles = StringConverter::parseBool(params);
|
---|
214 | }
|
---|
215 |
|
---|
216 | void parseBlurCauCubeMap(String& params, RenderTechniqueFactory* factory)
|
---|
217 | {
|
---|
218 | OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory;
|
---|
219 | f->blurCauCubeMap = StringConverter::parseBool(params);
|
---|
220 | }
|
---|
221 | }
|
---|
222 |
|
---|
223 |
|
---|
224 | ///Technique factory
|
---|
225 | OgreCausticCasterRenderTechniqueFactory::OgreCausticCasterRenderTechniqueFactory()
|
---|
226 | {
|
---|
227 | typeName = "CausticCaster";
|
---|
228 |
|
---|
229 | using namespace CausticCasterParsers;
|
---|
230 |
|
---|
231 | //register parsers
|
---|
232 | this->attributeParsers.insert(AttribParserList::value_type("start_frame", (ILLUM_ATTRIBUTE_PARSER) parseStartFrame));
|
---|
233 | this->attributeParsers.insert(AttribParserList::value_type("update_interval", (ILLUM_ATTRIBUTE_PARSER) parsePhotonMapUpdateInterval));
|
---|
234 | this->attributeParsers.insert(AttribParserList::value_type("photonmap_resolution", (ILLUM_ATTRIBUTE_PARSER) parsePhotonMapResolution));
|
---|
235 | this->attributeParsers.insert(AttribParserList::value_type("caustic_cubemap_resolution", (ILLUM_ATTRIBUTE_PARSER) parseCausticCubeMapResolution));
|
---|
236 | this->attributeParsers.insert(AttribParserList::value_type("photon_map_material", (ILLUM_ATTRIBUTE_PARSER) parsePhotonMapMaterial));
|
---|
237 | this->attributeParsers.insert(AttribParserList::value_type("caustic_map_material", (ILLUM_ATTRIBUTE_PARSER) parseCauMapMaterial));
|
---|
238 | this->attributeParsers.insert(AttribParserList::value_type("photon_map_tex_id", (ILLUM_ATTRIBUTE_PARSER) parseTexID));
|
---|
239 | this->attributeParsers.insert(AttribParserList::value_type("distance_impostor", (ILLUM_ATTRIBUTE_PARSER) parseUseDistance));
|
---|
240 | this->attributeParsers.insert(AttribParserList::value_type("update_all_face", (ILLUM_ATTRIBUTE_PARSER) parseUpdateAllFace));
|
---|
241 | this->attributeParsers.insert(AttribParserList::value_type("attenuation", (ILLUM_ATTRIBUTE_PARSER) parseAttenuation));
|
---|
242 | this->attributeParsers.insert(AttribParserList::value_type("use_triangles", (ILLUM_ATTRIBUTE_PARSER) parseUseTriangles));
|
---|
243 | this->attributeParsers.insert(AttribParserList::value_type("blur_caustic_cubemap", (ILLUM_ATTRIBUTE_PARSER) parseBlurCauCubeMap));
|
---|
244 |
|
---|
245 | }
|
---|
246 |
|
---|
247 | OgreRenderTechnique* OgreCausticCasterRenderTechniqueFactory::createInstance(
|
---|
248 | IllumTechniqueParams* params,
|
---|
249 | Pass* pass,
|
---|
250 | OgreRenderable* parentRenderable,
|
---|
251 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
252 | {
|
---|
253 | //reset parameters
|
---|
254 | attenuation = 1.0;
|
---|
255 | startFrame = 1;
|
---|
256 | photonMapUpdateInterval = 1;
|
---|
257 | photonMapResolution = 64;
|
---|
258 | causticCubeMapResolution = 128;
|
---|
259 | photonMapMaterialName = "GTP/Caustic/PhotonMap_HitEnv";
|
---|
260 | causticMapMaterialName = "GTP/Caustic/CauCube_PointSprite";
|
---|
261 | photonMapTexID = 0;
|
---|
262 | useDistance = true;
|
---|
263 | updateAllFace = false;
|
---|
264 | useTriangles = false;
|
---|
265 | blurCauCubeMap = false;
|
---|
266 |
|
---|
267 | parseParams(params);
|
---|
268 |
|
---|
269 | OgreCausticCasterRenderTechnique* result = new OgreCausticCasterRenderTechnique(
|
---|
270 | startFrame,
|
---|
271 | photonMapUpdateInterval,
|
---|
272 | photonMapResolution,
|
---|
273 | causticCubeMapResolution,
|
---|
274 | photonMapMaterialName,
|
---|
275 | causticMapMaterialName,
|
---|
276 | photonMapTexID,
|
---|
277 | updateAllFace,
|
---|
278 | useDistance,
|
---|
279 | attenuation,
|
---|
280 | useTriangles,
|
---|
281 | blurCauCubeMap,
|
---|
282 | pass,
|
---|
283 | parentRenderable,
|
---|
284 | parentTechniqueGroup);
|
---|
285 |
|
---|
286 | return result;
|
---|
287 | } |
---|