1 | #include "OgreConvolvedCubeMapRenderTechnique.h"
|
---|
2 | #include "OgreTechniqueGroup.h"
|
---|
3 | #include "OgreReducedCubeMapRenderingRun.h"
|
---|
4 | #include "OgreColorCubeMapRenderingRun.h"
|
---|
5 |
|
---|
6 | OgreConvolvedCubeMapRenderTechnique::OgreConvolvedCubeMapRenderTechnique(unsigned long startFrame,
|
---|
7 | unsigned long cubeMapUpdateInterval,
|
---|
8 | unsigned int cubeMapResolution,
|
---|
9 | unsigned int reducedCubeMapResolution,
|
---|
10 | unsigned char reducedTexID,
|
---|
11 | bool useDistCalc,
|
---|
12 | bool useFaceAngleCalc,
|
---|
13 | float distTolerance,
|
---|
14 | float angleTolerance,
|
---|
15 | bool updateAllFace,
|
---|
16 | Pass* pass,
|
---|
17 | OgreRenderable* parentRenderable,
|
---|
18 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
19 | :OgreRenderTechnique( pass, parentRenderable, parentTechniqueGroup),
|
---|
20 | ConvolvedCubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, reducedCubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, parentRenderable, parentTechniqueGroup),
|
---|
21 | RenderTechnique(parentRenderable, parentTechniqueGroup)
|
---|
22 | {
|
---|
23 | this->reducedTexID = reducedTexID;
|
---|
24 |
|
---|
25 | if(sharedRuns->getRun(ILLUMRUN_COLOR_CUBEMAP) == 0)
|
---|
26 | sharedRuns->addRun(ILLUMRUN_COLOR_CUBEMAP, createColorCubeMapRun());
|
---|
27 |
|
---|
28 | if(sharedRuns->getRun(ILLUMRUN_REDUCED_CUBEMAP) == 0)
|
---|
29 | sharedRuns->addRun(ILLUMRUN_REDUCED_CUBEMAP, createReducedCubeMapRun());
|
---|
30 |
|
---|
31 | colorCubeMapRunChanged(sharedRuns->getRun(ILLUMRUN_COLOR_CUBEMAP));
|
---|
32 | reducedCubeMapRunChanged(sharedRuns->getRun(ILLUMRUN_REDUCED_CUBEMAP));
|
---|
33 | }
|
---|
34 |
|
---|
35 |
|
---|
36 | OgreConvolvedCubeMapRenderTechnique::~OgreConvolvedCubeMapRenderTechnique()
|
---|
37 | {
|
---|
38 |
|
---|
39 | }
|
---|
40 |
|
---|
41 | void OgreConvolvedCubeMapRenderTechnique::update(unsigned long frameNum)
|
---|
42 | {
|
---|
43 | ConvolvedCubeMapRenderTechnique::update(frameNum);
|
---|
44 | }
|
---|
45 |
|
---|
46 | void OgreConvolvedCubeMapRenderTechnique::reducedCubeMapRunChanged(RenderingRun* run)
|
---|
47 | {
|
---|
48 | OgreReducedCubeMapRenderingRun* cuberun =(OgreReducedCubeMapRenderingRun*) (run->asOgreRenderingRun());
|
---|
49 | String cubemapname = cuberun->getReducedCubeMapTextureName();
|
---|
50 |
|
---|
51 | pass->getTextureUnitState(reducedTexID)->setTextureName(cubemapname);
|
---|
52 | }
|
---|
53 |
|
---|
54 | void OgreConvolvedCubeMapRenderTechnique::colorCubeMapRunChanged(RenderingRun* run)
|
---|
55 | {
|
---|
56 |
|
---|
57 | OgreColorCubeMapRenderingRun* cuberun =(OgreColorCubeMapRenderingRun*) (run->asOgreRenderingRun());
|
---|
58 | String cubemapname = cuberun->getColorCubeMapTextureName();
|
---|
59 |
|
---|
60 | OgreReducedCubeMapRenderingRun* rr = (OgreReducedCubeMapRenderingRun*) sharedRuns->getRun(ILLUMRUN_REDUCED_CUBEMAP)->asOgreRenderingRun();
|
---|
61 | rr->colorCubeMapChanged(cubemapname);
|
---|
62 |
|
---|
63 | }
|
---|
64 |
|
---|
65 | RenderingRun* OgreConvolvedCubeMapRenderTechnique::createColorCubeMapRun()
|
---|
66 | {
|
---|
67 | return new OgreColorCubeMapRenderingRun( (OgreSharedRuns*) parentTechniqueGroup->getSharedRuns(),
|
---|
68 | parentOgreRenderable->getName() + "_COLORCUBEMAP",
|
---|
69 | startFrame,
|
---|
70 | cubeMapUpdateInterval,
|
---|
71 | cubeMapResolution,
|
---|
72 | useDistCalc,
|
---|
73 | useFaceAngleCalc,
|
---|
74 | distTolerance,
|
---|
75 | angleTolerance,
|
---|
76 | updateAllFace);
|
---|
77 | }
|
---|
78 |
|
---|
79 | RenderingRun* OgreConvolvedCubeMapRenderTechnique::createReducedCubeMapRun()
|
---|
80 | {
|
---|
81 | return new OgreReducedCubeMapRenderingRun( (OgreSharedRuns*) parentTechniqueGroup->getSharedRuns(),
|
---|
82 | parentOgreRenderable->getName() + "_COLORCUBEMAP_REDUCED",
|
---|
83 | startFrame,
|
---|
84 | cubeMapUpdateInterval,
|
---|
85 | reducedCubeMapResolution,
|
---|
86 | useDistCalc,
|
---|
87 | useFaceAngleCalc,
|
---|
88 | distTolerance,
|
---|
89 | angleTolerance,
|
---|
90 | updateAllFace);
|
---|
91 | }
|
---|
92 |
|
---|
93 | ///Technique Parsers
|
---|
94 | namespace ConvolvedCubemapParsers
|
---|
95 | {
|
---|
96 | void parseStartFrame(String& params, RenderTechniqueFactory* factory)
|
---|
97 | {
|
---|
98 | OgreConvoledCubeMapRenderTechniqueFactory* f = (OgreConvoledCubeMapRenderTechniqueFactory*) factory;
|
---|
99 | f->startFrame = StringConverter::parseUnsignedLong(params);
|
---|
100 | }
|
---|
101 | void parseCubeMapUpdateInterval(String& params, RenderTechniqueFactory* factory)
|
---|
102 | {
|
---|
103 | OgreConvoledCubeMapRenderTechniqueFactory* f = (OgreConvoledCubeMapRenderTechniqueFactory*) factory;
|
---|
104 | f->cubeMapUpdateInterval = StringConverter::parseUnsignedLong(params);
|
---|
105 | }
|
---|
106 |
|
---|
107 | void parseCubeMapResolution(String& params, RenderTechniqueFactory* factory)
|
---|
108 | {
|
---|
109 | OgreConvoledCubeMapRenderTechniqueFactory* f = (OgreConvoledCubeMapRenderTechniqueFactory*) factory;
|
---|
110 | f->cubeMapResolution = StringConverter::parseUnsignedInt(params);
|
---|
111 | }
|
---|
112 |
|
---|
113 | void parseReducedCubeMapResolution(String& params, RenderTechniqueFactory* factory)
|
---|
114 | {
|
---|
115 | OgreConvoledCubeMapRenderTechniqueFactory* f = (OgreConvoledCubeMapRenderTechniqueFactory*) factory;
|
---|
116 | f->reducedCubeMapResolution = StringConverter::parseUnsignedInt(params);
|
---|
117 | }
|
---|
118 |
|
---|
119 | void parseTexID(String& params, RenderTechniqueFactory* factory)
|
---|
120 | {
|
---|
121 | OgreConvoledCubeMapRenderTechniqueFactory* f = (OgreConvoledCubeMapRenderTechniqueFactory*) factory;
|
---|
122 | f->texID = StringConverter::parseUnsignedInt(params);
|
---|
123 | }
|
---|
124 |
|
---|
125 | void parseUseDistCalc(String& params, RenderTechniqueFactory* factory)
|
---|
126 | {
|
---|
127 | OgreConvoledCubeMapRenderTechniqueFactory* f = (OgreConvoledCubeMapRenderTechniqueFactory*) factory;
|
---|
128 | // format: on/off tolerance(float)
|
---|
129 | StringVector vecparams = StringUtil::split(params, " \t");
|
---|
130 |
|
---|
131 | if(StringConverter::parseBool(vecparams[0]))//on
|
---|
132 | {
|
---|
133 | f->useDistCalc = true;
|
---|
134 |
|
---|
135 | if(vecparams.size()>1)
|
---|
136 | {
|
---|
137 | f->distTolerance = StringConverter::parseReal(vecparams[1]);
|
---|
138 | }
|
---|
139 | }
|
---|
140 | else
|
---|
141 | {
|
---|
142 | f->useDistCalc = false;
|
---|
143 | }
|
---|
144 | }
|
---|
145 |
|
---|
146 | void parseUseFaceAngleCalc(String& params, RenderTechniqueFactory* factory)
|
---|
147 | {
|
---|
148 | OgreConvoledCubeMapRenderTechniqueFactory* f = (OgreConvoledCubeMapRenderTechniqueFactory*) factory;
|
---|
149 | // format: on/off tolerance(float)
|
---|
150 | StringVector vecparams = StringUtil::split(params, " \t");
|
---|
151 |
|
---|
152 | if(StringConverter::parseBool(vecparams[0]))//on
|
---|
153 | {
|
---|
154 | f->useFaceAngleCalc = true;
|
---|
155 |
|
---|
156 | if(vecparams.size()>1)
|
---|
157 | {
|
---|
158 | f->angleTolerance = StringConverter::parseReal(vecparams[1]);
|
---|
159 | }
|
---|
160 | }
|
---|
161 | else
|
---|
162 | {
|
---|
163 | f->useFaceAngleCalc = false;
|
---|
164 | }
|
---|
165 | }
|
---|
166 |
|
---|
167 | void parseUpdateAllFace(String& params, RenderTechniqueFactory* factory)
|
---|
168 | {
|
---|
169 | OgreConvoledCubeMapRenderTechniqueFactory* f = (OgreConvoledCubeMapRenderTechniqueFactory*) factory;
|
---|
170 | f->updateAllFace = StringConverter::parseBool(params);
|
---|
171 | }
|
---|
172 | }
|
---|
173 | ///Technique factory
|
---|
174 | OgreConvoledCubeMapRenderTechniqueFactory::OgreConvoledCubeMapRenderTechniqueFactory()
|
---|
175 | {
|
---|
176 | typeName = "ReducedColorCubeMap";
|
---|
177 |
|
---|
178 | using namespace ConvolvedCubemapParsers;
|
---|
179 | //register parsers
|
---|
180 | this->attributeParsers.insert(AttribParserList::value_type("start_frame", (ILLUM_ATTRIBUTE_PARSER) parseStartFrame));
|
---|
181 | this->attributeParsers.insert(AttribParserList::value_type("update_interval", (ILLUM_ATTRIBUTE_PARSER) parseCubeMapUpdateInterval));
|
---|
182 | this->attributeParsers.insert(AttribParserList::value_type("resolution", (ILLUM_ATTRIBUTE_PARSER) parseCubeMapResolution));
|
---|
183 | this->attributeParsers.insert(AttribParserList::value_type("reduced_resolution", (ILLUM_ATTRIBUTE_PARSER) parseReducedCubeMapResolution));
|
---|
184 | this->attributeParsers.insert(AttribParserList::value_type("texture_unit_id", (ILLUM_ATTRIBUTE_PARSER) parseTexID));
|
---|
185 | this->attributeParsers.insert(AttribParserList::value_type("distance_calc", (ILLUM_ATTRIBUTE_PARSER) parseUseDistCalc));
|
---|
186 | this->attributeParsers.insert(AttribParserList::value_type("face_angle_calc", (ILLUM_ATTRIBUTE_PARSER) parseUseFaceAngleCalc));
|
---|
187 | this->attributeParsers.insert(AttribParserList::value_type("update_all_face", (ILLUM_ATTRIBUTE_PARSER) parseUpdateAllFace));
|
---|
188 |
|
---|
189 | }
|
---|
190 |
|
---|
191 | OgreRenderTechnique* OgreConvoledCubeMapRenderTechniqueFactory::createInstance(
|
---|
192 | IllumTechniqueParams* params,
|
---|
193 | Pass* pass,
|
---|
194 | OgreRenderable* parentRenderable,
|
---|
195 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
196 | {
|
---|
197 | //reset parameters
|
---|
198 | startFrame = 1;
|
---|
199 | cubeMapUpdateInterval = 1;
|
---|
200 | cubeMapResolution = 256;
|
---|
201 | reducedCubeMapResolution = 8;
|
---|
202 | texID = 0;
|
---|
203 | useDistCalc = 1;
|
---|
204 | useFaceAngleCalc = false;
|
---|
205 | distTolerance = 2.0;
|
---|
206 | angleTolerance = 2.0;
|
---|
207 | updateAllFace = false;
|
---|
208 |
|
---|
209 | parseParams(params);
|
---|
210 |
|
---|
211 | OgreConvolvedCubeMapRenderTechnique* result = new OgreConvolvedCubeMapRenderTechnique(
|
---|
212 | startFrame,
|
---|
213 | cubeMapUpdateInterval,
|
---|
214 | cubeMapResolution,
|
---|
215 | reducedCubeMapResolution,
|
---|
216 | texID,
|
---|
217 | useDistCalc,
|
---|
218 | useFaceAngleCalc,
|
---|
219 | distTolerance,
|
---|
220 | angleTolerance,
|
---|
221 | updateAllFace,
|
---|
222 | pass,
|
---|
223 | parentRenderable,
|
---|
224 | parentTechniqueGroup);
|
---|
225 |
|
---|
226 | return result;
|
---|
227 | }
|
---|
228 |
|
---|
229 |
|
---|