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