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