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