1 | #include "OgreTechniqueGroup.h"
|
---|
2 | #include "OgreIllumVolumeRenderTechnique.h"
|
---|
3 | #include "OgreChildPSystemRenderingRun.h"
|
---|
4 | #include "OgreLightVolumeRenderingRun.h"
|
---|
5 |
|
---|
6 | OgreIllumVolumeRenderTechnique::OgreIllumVolumeRenderTechnique(
|
---|
7 | unsigned long startFrame,
|
---|
8 | unsigned long illumVolumeUpdateInterval,
|
---|
9 | unsigned int illumTextureResolution,
|
---|
10 | unsigned int textureDepth,
|
---|
11 | unsigned char illumTexID,
|
---|
12 | bool useDistCalc,
|
---|
13 | String materialName,
|
---|
14 | String lightMatrixGPUParamName,
|
---|
15 | bool useHierarchicalImpostor,
|
---|
16 | unsigned char impostorTexID,
|
---|
17 | Pass* pass,
|
---|
18 | OgreRenderable* parentRenderable,
|
---|
19 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
20 | :OgreRenderTechnique( pass, parentRenderable, parentTechniqueGroup),
|
---|
21 | IllumVolumeRenderTechnique(startFrame, illumVolumeUpdateInterval, illumTextureResolution, textureDepth, useDistCalc, useHierarchicalImpostor, parentRenderable, parentTechniqueGroup),
|
---|
22 | RenderTechnique(parentRenderable, parentTechniqueGroup)
|
---|
23 | {
|
---|
24 | this->illumTexID = illumTexID;
|
---|
25 | this->materialName = materialName;
|
---|
26 | this->lightMatrixGPUParamName = lightMatrixGPUParamName;
|
---|
27 | this->impostorTexID = impostorTexID;
|
---|
28 | this->lightMatrixGPUParamName = lightMatrixGPUParamName;
|
---|
29 |
|
---|
30 | if(sharedRuns->getRun(ILLUMRUN_LIGHTVOLUME_MAP) == 0)
|
---|
31 | sharedRuns->addRun(ILLUMRUN_LIGHTVOLUME_MAP, createLightVolumeRenderingRun());
|
---|
32 |
|
---|
33 | lightVolumeChanged(sharedRuns->getRun(ILLUMRUN_LIGHTVOLUME_MAP));
|
---|
34 | }
|
---|
35 |
|
---|
36 |
|
---|
37 | OgreIllumVolumeRenderTechnique::~OgreIllumVolumeRenderTechnique()
|
---|
38 | {
|
---|
39 |
|
---|
40 | }
|
---|
41 |
|
---|
42 | void OgreIllumVolumeRenderTechnique::lightVolumeChanged(RenderingRun* run)
|
---|
43 | {
|
---|
44 | OgreLightVolumeRenderingRun* r = (OgreLightVolumeRenderingRun*) run->asOgreRenderingRun();
|
---|
45 | pass->getTextureUnitState(illumTexID)->setTextureName(r->getLightVolumeTextureName());
|
---|
46 | }
|
---|
47 |
|
---|
48 | void OgreIllumVolumeRenderTechnique::lightVolumeUpdated(RenderingRun* run)
|
---|
49 | {
|
---|
50 | OgreLightVolumeRenderingRun* r = (OgreLightVolumeRenderingRun*) run->asOgreRenderingRun();
|
---|
51 | pass->getVertexProgramParameters()->setNamedConstant(lightMatrixGPUParamName,
|
---|
52 | r->getLightViewProjectionMatrix());
|
---|
53 | }
|
---|
54 |
|
---|
55 | void OgreIllumVolumeRenderTechnique::hierarchicalImpostorUpdated(RenderingRun* run)
|
---|
56 | {
|
---|
57 | if(useHierarchicalImpostor)
|
---|
58 | {
|
---|
59 | OgreChildPSystemRenderingRun* r = (OgreChildPSystemRenderingRun*) run->asOgreRenderingRun();
|
---|
60 | Material* m = (Material*) MaterialManager::getSingleton().getByName(materialName).getPointer();
|
---|
61 | m->getTechnique(0)->getPass(0)->getTextureUnitState(impostorTexID)
|
---|
62 | ->setTextureName(r->getImpostorTextureName());
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | RenderingRun* OgreIllumVolumeRenderTechnique::createLightVolumeRenderingRun()
|
---|
67 | {
|
---|
68 | return new OgreLightVolumeRenderingRun( (OgreSharedRuns*) parentTechniqueGroup->getSharedRuns(),
|
---|
69 | parentOgreRenderable->getName() + "_LIGHT_VOLUME",
|
---|
70 | startFrame,
|
---|
71 | illumVolumeUpdateInterval,
|
---|
72 | illumTextureResolution,
|
---|
73 | textureDepth,
|
---|
74 | materialName);
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 | ///Technique Parsers
|
---|
79 | namespace IllumVolumeParsers
|
---|
80 | {
|
---|
81 | void parseStartFrame(String& params, RenderTechniqueFactory* factory)
|
---|
82 | {
|
---|
83 | OgreIllumVolumeRenderTechniqueFactory* f = (OgreIllumVolumeRenderTechniqueFactory*) factory;
|
---|
84 | f->startFrame = StringConverter::parseUnsignedLong(params);
|
---|
85 | }
|
---|
86 | void parseIllumVolumeUpdateInterval(String& params, RenderTechniqueFactory* factory)
|
---|
87 | {
|
---|
88 | OgreIllumVolumeRenderTechniqueFactory* f = (OgreIllumVolumeRenderTechniqueFactory*) factory;
|
---|
89 | f->illumVolumeUpdateInterval = StringConverter::parseUnsignedLong(params);
|
---|
90 | }
|
---|
91 |
|
---|
92 | void parseIllumTextureResolution(String& params, RenderTechniqueFactory* factory)
|
---|
93 | {
|
---|
94 | OgreIllumVolumeRenderTechniqueFactory* f = (OgreIllumVolumeRenderTechniqueFactory*) factory;
|
---|
95 | f->illumTextureResolution = StringConverter::parseUnsignedInt(params);
|
---|
96 | }
|
---|
97 |
|
---|
98 | void parseIllumTextureDepth(String& params, RenderTechniqueFactory* factory)
|
---|
99 | {
|
---|
100 | OgreIllumVolumeRenderTechniqueFactory* f = (OgreIllumVolumeRenderTechniqueFactory*) factory;
|
---|
101 | f->textureDepth = StringConverter::parseUnsignedInt(params);
|
---|
102 | }
|
---|
103 |
|
---|
104 | void parseIllumTexID(String& params, RenderTechniqueFactory* factory)
|
---|
105 | {
|
---|
106 | OgreIllumVolumeRenderTechniqueFactory* f = (OgreIllumVolumeRenderTechniqueFactory*) factory;
|
---|
107 | f->illumTexID = StringConverter::parseUnsignedInt(params);
|
---|
108 | }
|
---|
109 |
|
---|
110 | void parseUseDistCalc(String& params, RenderTechniqueFactory* factory)
|
---|
111 | {
|
---|
112 | /* OgreHierarchicalParticleSystemTechniqueFactory* f = (OgreHierarchicalParticleSystemTechniqueFactory*) factory;
|
---|
113 | // format: on/off tolerance(float)
|
---|
114 | StringVector vecparams = StringUtil::split(params, " \t");
|
---|
115 |
|
---|
116 | if(StringConverter::parseBool(vecparams[0]))//on
|
---|
117 | {
|
---|
118 | f->useDistCalc = true;
|
---|
119 |
|
---|
120 | if(vecparams.size()>1)
|
---|
121 | {
|
---|
122 | f->distTolerance = StringConverter::parseReal(vecparams[1]);
|
---|
123 | }
|
---|
124 | }
|
---|
125 | else
|
---|
126 | {
|
---|
127 | f->useDistCalc = false;
|
---|
128 | }*/
|
---|
129 | ///TODO
|
---|
130 | }
|
---|
131 |
|
---|
132 | void parseMaterialName(String& params, RenderTechniqueFactory* factory)
|
---|
133 | {
|
---|
134 | OgreIllumVolumeRenderTechniqueFactory* f = (OgreIllumVolumeRenderTechniqueFactory*) factory;
|
---|
135 | f->materialName = params;
|
---|
136 | }
|
---|
137 |
|
---|
138 | void parseLightMatrixGPUParamName(String& params, RenderTechniqueFactory* factory)
|
---|
139 | {
|
---|
140 | OgreIllumVolumeRenderTechniqueFactory* f = (OgreIllumVolumeRenderTechniqueFactory*) factory;
|
---|
141 | f->lightMatrixGPUParamName = params;
|
---|
142 | }
|
---|
143 |
|
---|
144 | void parseImpostorTexID(String& params, RenderTechniqueFactory* factory)
|
---|
145 | {
|
---|
146 | OgreIllumVolumeRenderTechniqueFactory* f = (OgreIllumVolumeRenderTechniqueFactory*) factory;
|
---|
147 | f->impostorTexID = StringConverter::parseUnsignedInt(params);
|
---|
148 | }
|
---|
149 |
|
---|
150 | void parseUseHierarchicalImpostor(String& params, RenderTechniqueFactory* factory)
|
---|
151 | {
|
---|
152 | OgreIllumVolumeRenderTechniqueFactory* f = (OgreIllumVolumeRenderTechniqueFactory*) factory;
|
---|
153 | f->useHierarchicalImpostor = StringConverter::parseBool(params);
|
---|
154 | }
|
---|
155 | }
|
---|
156 | ///Technique factory
|
---|
157 | OgreIllumVolumeRenderTechniqueFactory::OgreIllumVolumeRenderTechniqueFactory()
|
---|
158 | {
|
---|
159 | typeName = "IllumVolume";
|
---|
160 |
|
---|
161 | using namespace IllumVolumeParsers;
|
---|
162 |
|
---|
163 | //register parsers
|
---|
164 | this->attributeParsers.insert(AttribParserList::value_type("start_frame", (ILLUM_ATTRIBUTE_PARSER) parseStartFrame));
|
---|
165 | this->attributeParsers.insert(AttribParserList::value_type("update_interval", (ILLUM_ATTRIBUTE_PARSER) parseIllumVolumeUpdateInterval));
|
---|
166 | this->attributeParsers.insert(AttribParserList::value_type("resolution", (ILLUM_ATTRIBUTE_PARSER) parseIllumTextureResolution));
|
---|
167 | this->attributeParsers.insert(AttribParserList::value_type("depths", (ILLUM_ATTRIBUTE_PARSER) parseIllumTextureDepth));
|
---|
168 | this->attributeParsers.insert(AttribParserList::value_type("texture_unit_id", (ILLUM_ATTRIBUTE_PARSER) parseIllumTexID));
|
---|
169 | this->attributeParsers.insert(AttribParserList::value_type("impostor_texture_unit_id", (ILLUM_ATTRIBUTE_PARSER) parseImpostorTexID));
|
---|
170 | this->attributeParsers.insert(AttribParserList::value_type("distance_calc", (ILLUM_ATTRIBUTE_PARSER) parseUseDistCalc));
|
---|
171 | this->attributeParsers.insert(AttribParserList::value_type("material", (ILLUM_ATTRIBUTE_PARSER) parseMaterialName));
|
---|
172 | this->attributeParsers.insert(AttribParserList::value_type("use_hier_system", (ILLUM_ATTRIBUTE_PARSER) parseUseHierarchicalImpostor));
|
---|
173 | this->attributeParsers.insert(AttribParserList::value_type("lightmatrix_param_name", (ILLUM_ATTRIBUTE_PARSER) parseLightMatrixGPUParamName));
|
---|
174 |
|
---|
175 | }
|
---|
176 |
|
---|
177 | OgreRenderTechnique* OgreIllumVolumeRenderTechniqueFactory::createInstance(
|
---|
178 | IllumTechniqueParams* params,
|
---|
179 | Pass* pass,
|
---|
180 | OgreRenderable* parentRenderable,
|
---|
181 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
182 | {
|
---|
183 | materialName = "Smoke_IllumVolume";
|
---|
184 | illumTexID = 2;
|
---|
185 | startFrame = 0;
|
---|
186 | illumVolumeUpdateInterval = 1;
|
---|
187 | illumTextureResolution = 256;
|
---|
188 | textureDepth = 1;
|
---|
189 | useDistCalc = false;
|
---|
190 | lightMatrixGPUParamName = "lightViewProj";
|
---|
191 | impostorTexID = 0;
|
---|
192 | useHierarchicalImpostor = false;
|
---|
193 |
|
---|
194 | parseParams(params);
|
---|
195 |
|
---|
196 | OgreIllumVolumeRenderTechnique* result = new OgreIllumVolumeRenderTechnique(
|
---|
197 | startFrame,
|
---|
198 | illumVolumeUpdateInterval,
|
---|
199 | illumTextureResolution,
|
---|
200 | textureDepth,
|
---|
201 | illumTexID,
|
---|
202 | useDistCalc,
|
---|
203 | materialName,
|
---|
204 | lightMatrixGPUParamName,
|
---|
205 | useHierarchicalImpostor,
|
---|
206 | impostorTexID,
|
---|
207 | pass,
|
---|
208 | parentRenderable,
|
---|
209 | parentTechniqueGroup);
|
---|
210 |
|
---|
211 | return result;
|
---|
212 | }
|
---|
213 |
|
---|
214 |
|
---|