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