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 + parentRenderable->getName() + "_clone";
|
---|
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 |
|
---|
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 | "GameTools/DistanceShader",
|
---|
135 | ILLUMRUN_DISTANCE_CUBEMAP);
|
---|
136 |
|
---|
137 | }
|
---|
138 |
|
---|
139 | const String& OgreCausticCasterRenderTechnique::getCausticCubeMapName()
|
---|
140 | {
|
---|
141 | return ((OgreCausticCubeMapRenderingRun*) sharedRuns->getRun(ILLUMRUN_CAUSTIC_CUBEMAP)->asOgreRenderingRun())->
|
---|
142 | getCausticCubeMapTextureName();
|
---|
143 | }
|
---|
144 |
|
---|
145 |
|
---|
146 | ///Technique Parsers
|
---|
147 | namespace CausticCasterParsers
|
---|
148 | {
|
---|
149 | void parseStartFrame(String& params, RenderTechniqueFactory* factory)
|
---|
150 | {
|
---|
151 | OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory;
|
---|
152 | f->startFrame = StringConverter::parseUnsignedLong(params);
|
---|
153 | }
|
---|
154 | void parsePhotonMapUpdateInterval(String& params, RenderTechniqueFactory* factory)
|
---|
155 | {
|
---|
156 | OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory;
|
---|
157 | f->photonMapUpdateInterval = StringConverter::parseUnsignedLong(params);
|
---|
158 | }
|
---|
159 |
|
---|
160 | void parsePhotonMapResolution(String& params, RenderTechniqueFactory* factory)
|
---|
161 | {
|
---|
162 | OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory;
|
---|
163 | f->photonMapResolution = StringConverter::parseUnsignedInt(params);
|
---|
164 | }
|
---|
165 |
|
---|
166 | void parseCausticCubeMapResolution(String& params, RenderTechniqueFactory* factory)
|
---|
167 | {
|
---|
168 | OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory;
|
---|
169 | f->causticCubeMapResolution = StringConverter::parseUnsignedInt(params);
|
---|
170 | }
|
---|
171 |
|
---|
172 | void parseTexID(String& params, RenderTechniqueFactory* factory)
|
---|
173 | {
|
---|
174 | OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory;
|
---|
175 | f->photonMapTexID = StringConverter::parseUnsignedInt(params);
|
---|
176 | }
|
---|
177 |
|
---|
178 | void parseUseDistance(String& params, RenderTechniqueFactory* factory)
|
---|
179 | {
|
---|
180 | OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory;
|
---|
181 | f->useDistance = StringConverter::parseBool(params);
|
---|
182 | }
|
---|
183 |
|
---|
184 | void parseUpdateAllFace(String& params, RenderTechniqueFactory* factory)
|
---|
185 | {
|
---|
186 | OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory;
|
---|
187 | f->updateAllFace = StringConverter::parseBool(params);
|
---|
188 | }
|
---|
189 |
|
---|
190 | void parsePhotonMapMaterial(String& params, RenderTechniqueFactory* factory)
|
---|
191 | {
|
---|
192 | OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory;
|
---|
193 | f->photonMapMaterialName = params;
|
---|
194 | }
|
---|
195 |
|
---|
196 | void parseCauMapMaterial(String& params, RenderTechniqueFactory* factory)
|
---|
197 | {
|
---|
198 | OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory;
|
---|
199 | f->causticMapMaterialName = params;
|
---|
200 | }
|
---|
201 |
|
---|
202 | void parseAttenuation(String& params, RenderTechniqueFactory* factory)
|
---|
203 | {
|
---|
204 | OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory;
|
---|
205 | f->attenuation = StringConverter::parseReal(params);
|
---|
206 | }
|
---|
207 |
|
---|
208 | void parseUseTriangles(String& params, RenderTechniqueFactory* factory)
|
---|
209 | {
|
---|
210 | OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory;
|
---|
211 | f->useTriangles = StringConverter::parseBool(params);
|
---|
212 | }
|
---|
213 |
|
---|
214 | void parseBlurCauCubeMap(String& params, RenderTechniqueFactory* factory)
|
---|
215 | {
|
---|
216 | OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory;
|
---|
217 | f->blurCauCubeMap = StringConverter::parseBool(params);
|
---|
218 | }
|
---|
219 | }
|
---|
220 |
|
---|
221 |
|
---|
222 | ///Technique factory
|
---|
223 | OgreCausticCasterRenderTechniqueFactory::OgreCausticCasterRenderTechniqueFactory()
|
---|
224 | {
|
---|
225 | typeName = "CausticCaster";
|
---|
226 |
|
---|
227 | using namespace CausticCasterParsers;
|
---|
228 |
|
---|
229 | //register parsers
|
---|
230 | this->attributeParsers.insert(AttribParserList::value_type("start_frame", (ILLUM_ATTRIBUTE_PARSER) parseStartFrame));
|
---|
231 | this->attributeParsers.insert(AttribParserList::value_type("update_interval", (ILLUM_ATTRIBUTE_PARSER) parsePhotonMapUpdateInterval));
|
---|
232 | this->attributeParsers.insert(AttribParserList::value_type("photonmap_resolution", (ILLUM_ATTRIBUTE_PARSER) parsePhotonMapResolution));
|
---|
233 | this->attributeParsers.insert(AttribParserList::value_type("caustic_cubemap_resolution", (ILLUM_ATTRIBUTE_PARSER) parseCausticCubeMapResolution));
|
---|
234 | this->attributeParsers.insert(AttribParserList::value_type("photon_map_material", (ILLUM_ATTRIBUTE_PARSER) parsePhotonMapMaterial));
|
---|
235 | this->attributeParsers.insert(AttribParserList::value_type("caustic_map_material", (ILLUM_ATTRIBUTE_PARSER) parseCauMapMaterial));
|
---|
236 | this->attributeParsers.insert(AttribParserList::value_type("photon_map_tex_id", (ILLUM_ATTRIBUTE_PARSER) parseTexID));
|
---|
237 | this->attributeParsers.insert(AttribParserList::value_type("distance_impostor", (ILLUM_ATTRIBUTE_PARSER) parseUseDistance));
|
---|
238 | this->attributeParsers.insert(AttribParserList::value_type("update_all_face", (ILLUM_ATTRIBUTE_PARSER) parseUpdateAllFace));
|
---|
239 | this->attributeParsers.insert(AttribParserList::value_type("attenuation", (ILLUM_ATTRIBUTE_PARSER) parseAttenuation));
|
---|
240 | this->attributeParsers.insert(AttribParserList::value_type("use_triangles", (ILLUM_ATTRIBUTE_PARSER) parseUseTriangles));
|
---|
241 | this->attributeParsers.insert(AttribParserList::value_type("blur_caustic_cubemap", (ILLUM_ATTRIBUTE_PARSER) parseBlurCauCubeMap));
|
---|
242 |
|
---|
243 | }
|
---|
244 |
|
---|
245 | OgreRenderTechnique* OgreCausticCasterRenderTechniqueFactory::createInstance(
|
---|
246 | IllumTechniqueParams* params,
|
---|
247 | Pass* pass,
|
---|
248 | OgreRenderable* parentRenderable,
|
---|
249 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
250 | {
|
---|
251 | //reset parameters
|
---|
252 | attenuation = 1.0;
|
---|
253 | startFrame = 1;
|
---|
254 | photonMapUpdateInterval = 1;
|
---|
255 | photonMapResolution = 64;
|
---|
256 | causticCubeMapResolution = 128;
|
---|
257 | photonMapMaterialName = "GameTools/PhotonMapCaustic";
|
---|
258 | causticMapMaterialName = "GameTools/Cau";
|
---|
259 | photonMapTexID = 0;
|
---|
260 | useDistance = true;
|
---|
261 | updateAllFace = false;
|
---|
262 | useTriangles = false;
|
---|
263 | blurCauCubeMap = false;
|
---|
264 |
|
---|
265 | parseParams(params);
|
---|
266 |
|
---|
267 | OgreCausticCasterRenderTechnique* result = new OgreCausticCasterRenderTechnique(
|
---|
268 | startFrame,
|
---|
269 | photonMapUpdateInterval,
|
---|
270 | photonMapResolution,
|
---|
271 | causticCubeMapResolution,
|
---|
272 | photonMapMaterialName,
|
---|
273 | causticMapMaterialName,
|
---|
274 | photonMapTexID,
|
---|
275 | updateAllFace,
|
---|
276 | useDistance,
|
---|
277 | attenuation,
|
---|
278 | useTriangles,
|
---|
279 | blurCauCubeMap,
|
---|
280 | pass,
|
---|
281 | parentRenderable,
|
---|
282 | parentTechniqueGroup);
|
---|
283 |
|
---|
284 | return result;
|
---|
285 | } |
---|