1 | #include "OgreCubeMapRenderTechnique.h"
|
---|
2 | #include "OgreTechniqueGroup.h"
|
---|
3 | #include "OgreHierarchicalParticleSystemTechnique.h"
|
---|
4 | #include "OgreChildPSystemRenderingRun.h"
|
---|
5 | #include "OgreLightVolumeRenderingRun.h"
|
---|
6 |
|
---|
7 | OgreHierarchicalParticleSystemTechnique::OgreHierarchicalParticleSystemTechnique(
|
---|
8 | unsigned long startFrame,
|
---|
9 | unsigned long impostorUpdateInterval,
|
---|
10 | unsigned int impostorResolution,
|
---|
11 | unsigned char impostorTexID,
|
---|
12 | bool useDistCalc,
|
---|
13 | bool perspectiveRendering,
|
---|
14 | String childPSysScriptName,
|
---|
15 | bool useOwnMaterial,
|
---|
16 | String impostorMaterialName,
|
---|
17 | bool useVParam,
|
---|
18 | String VParamRadius,
|
---|
19 | bool useFParam,
|
---|
20 | String FParamRadius,
|
---|
21 | Pass* pass,
|
---|
22 | OgreRenderable* parentRenderable,
|
---|
23 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
24 | :OgreRenderTechnique( pass, parentRenderable, parentTechniqueGroup),
|
---|
25 | HierarchicalParticleSystemTechnique(startFrame, impostorUpdateInterval, impostorResolution, useDistCalc, perspectiveRendering, parentRenderable, parentTechniqueGroup),
|
---|
26 | RenderTechnique(parentRenderable, parentTechniqueGroup)
|
---|
27 | {
|
---|
28 | this->impostorTexID = impostorTexID;
|
---|
29 | this->childPSysScriptName = childPSysScriptName;
|
---|
30 | this->impostorMaterialName = impostorMaterialName;
|
---|
31 | this->useOwnMaterial = useOwnMaterial;
|
---|
32 | this->VParamRadius = VParamRadius;
|
---|
33 | this->FParamRadius = FParamRadius;
|
---|
34 | this->useVParam = useVParam;
|
---|
35 | this->useFParam = useFParam;
|
---|
36 |
|
---|
37 | //create the Particle system
|
---|
38 | childPSysName = parentOgreRenderable->getName() + "_small_PSYS";
|
---|
39 | ParticleSystem* psys = Root::getSingleton()._getCurrentSceneManager()->createParticleSystem(childPSysName, childPSysScriptName);
|
---|
40 | SceneNode* node = Root::getSingleton()._getCurrentSceneManager()->getRootSceneNode()->createChildSceneNode();
|
---|
41 | node->attachObject(psys);
|
---|
42 | psys->setVisible(false);
|
---|
43 |
|
---|
44 | if(sharedRuns->getRun(ILLUMRUN_HPP_IMPOSTOR) == 0)
|
---|
45 | sharedRuns->addRun(ILLUMRUN_HPP_IMPOSTOR, createChildPSysRenderingRun());
|
---|
46 |
|
---|
47 | ((OgreChildPSystemRenderingRun*) sharedRuns->getRun(ILLUMRUN_HPP_IMPOSTOR)->asOgreRenderingRun())->setNode(node);
|
---|
48 | impostorChanged(sharedRuns->getRun(ILLUMRUN_HPP_IMPOSTOR));
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 | OgreHierarchicalParticleSystemTechnique::~OgreHierarchicalParticleSystemTechnique()
|
---|
53 | {
|
---|
54 |
|
---|
55 | }
|
---|
56 |
|
---|
57 | void OgreHierarchicalParticleSystemTechnique::impostorChanged(RenderingRun* run)
|
---|
58 | {
|
---|
59 | OgreChildPSystemRenderingRun* r = (OgreChildPSystemRenderingRun*) run->asOgreRenderingRun();
|
---|
60 | pass->getTextureUnitState(impostorTexID)->setTextureName(r->getImpostorTextureName());
|
---|
61 | }
|
---|
62 |
|
---|
63 | RenderingRun* OgreHierarchicalParticleSystemTechnique::createChildPSysRenderingRun()
|
---|
64 | {
|
---|
65 | return new OgreChildPSystemRenderingRun( (OgreSharedRuns*) parentTechniqueGroup->getSharedRuns(),
|
---|
66 | parentOgreRenderable->getName() + "_HPP_IMPOSTOR",
|
---|
67 | startFrame,
|
---|
68 | impostorUpdateInterval,
|
---|
69 | impostorResolution,
|
---|
70 | perspectiveRendering,
|
---|
71 | childPSysName,
|
---|
72 | childPSysScriptName,
|
---|
73 | useOwnMaterial,
|
---|
74 | impostorMaterialName);
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 | void OgreHierarchicalParticleSystemTechnique::impostorUpdated(RenderingRun* run)
|
---|
79 | {
|
---|
80 | OgreChildPSystemRenderingRun* r = (OgreChildPSystemRenderingRun*) run->asOgreRenderingRun();
|
---|
81 |
|
---|
82 | float radius = r->getSmallSysRadius();
|
---|
83 | if(useVParam)
|
---|
84 | pass->getVertexProgramParameters()->setNamedConstant(VParamRadius, radius);
|
---|
85 | if(useFParam)
|
---|
86 | pass->getFragmentProgramParameters()->setNamedConstant(FParamRadius, radius);
|
---|
87 | }
|
---|
88 |
|
---|
89 | ///Technique Parsers
|
---|
90 | namespace HPSParsers
|
---|
91 | {
|
---|
92 | void parseStartFrame(String& params, RenderTechniqueFactory* factory)
|
---|
93 | {
|
---|
94 | OgreHierarchicalParticleSystemTechniqueFactory* f = (OgreHierarchicalParticleSystemTechniqueFactory*) factory;
|
---|
95 | f->startFrame = StringConverter::parseUnsignedLong(params);
|
---|
96 | }
|
---|
97 | void parseImpostorUpdateInterval(String& params, RenderTechniqueFactory* factory)
|
---|
98 | {
|
---|
99 | OgreHierarchicalParticleSystemTechniqueFactory* f = (OgreHierarchicalParticleSystemTechniqueFactory*) factory;
|
---|
100 | f->impostorUpdateInterval = StringConverter::parseUnsignedLong(params);
|
---|
101 | }
|
---|
102 |
|
---|
103 | void parseImpostorResolution(String& params, RenderTechniqueFactory* factory)
|
---|
104 | {
|
---|
105 | OgreHierarchicalParticleSystemTechniqueFactory* f = (OgreHierarchicalParticleSystemTechniqueFactory*) factory;
|
---|
106 | f->impostorResolution = StringConverter::parseUnsignedInt(params);
|
---|
107 | }
|
---|
108 |
|
---|
109 | void parseImpostorTexID(String& params, RenderTechniqueFactory* factory)
|
---|
110 | {
|
---|
111 | OgreHierarchicalParticleSystemTechniqueFactory* f = (OgreHierarchicalParticleSystemTechniqueFactory*) factory;
|
---|
112 | f->impostorTexID = StringConverter::parseUnsignedInt(params);
|
---|
113 | }
|
---|
114 |
|
---|
115 | void parseUseDistCalc(String& params, RenderTechniqueFactory* factory)
|
---|
116 | {
|
---|
117 | /* OgreHierarchicalParticleSystemTechniqueFactory* f = (OgreHierarchicalParticleSystemTechniqueFactory*) factory;
|
---|
118 | // format: on/off tolerance(float)
|
---|
119 | StringVector vecparams = StringUtil::split(params, " \t");
|
---|
120 |
|
---|
121 | if(StringConverter::parseBool(vecparams[0]))//on
|
---|
122 | {
|
---|
123 | f->useDistCalc = true;
|
---|
124 |
|
---|
125 | if(vecparams.size()>1)
|
---|
126 | {
|
---|
127 | f->distTolerance = StringConverter::parseReal(vecparams[1]);
|
---|
128 | }
|
---|
129 | }
|
---|
130 | else
|
---|
131 | {
|
---|
132 | f->useDistCalc = false;
|
---|
133 | }*/
|
---|
134 | ///TODO
|
---|
135 | }
|
---|
136 |
|
---|
137 | void parsePerspectiveRendering(String& params, RenderTechniqueFactory* factory)
|
---|
138 | {
|
---|
139 | OgreHierarchicalParticleSystemTechniqueFactory* f = (OgreHierarchicalParticleSystemTechniqueFactory*) factory;
|
---|
140 | f->perspectiveRendering = StringConverter::parseBool(params);
|
---|
141 | }
|
---|
142 | void parseMaterialName(String& params, RenderTechniqueFactory* factory)
|
---|
143 | {
|
---|
144 | OgreHierarchicalParticleSystemTechniqueFactory* f = (OgreHierarchicalParticleSystemTechniqueFactory*) factory;
|
---|
145 | f->impostorMaterialName = params;
|
---|
146 | f->useOwnMaterial = false;
|
---|
147 | }
|
---|
148 | void parseScriptName(String& params, RenderTechniqueFactory* factory)
|
---|
149 | {
|
---|
150 | OgreHierarchicalParticleSystemTechniqueFactory* f = (OgreHierarchicalParticleSystemTechniqueFactory*) factory;
|
---|
151 | f->childPSysScriptName = params;
|
---|
152 | }
|
---|
153 | void parseVparamRadius(String& params, RenderTechniqueFactory* factory)
|
---|
154 | {
|
---|
155 | OgreHierarchicalParticleSystemTechniqueFactory* f = (OgreHierarchicalParticleSystemTechniqueFactory*) factory;
|
---|
156 | f->VParamRadius = params;
|
---|
157 | f->useVParam = true;
|
---|
158 | }
|
---|
159 | void parseFparamRadius(String& params, RenderTechniqueFactory* factory)
|
---|
160 | {
|
---|
161 | OgreHierarchicalParticleSystemTechniqueFactory* f = (OgreHierarchicalParticleSystemTechniqueFactory*) factory;
|
---|
162 | f->FParamRadius = params;
|
---|
163 | f->useFParam = true;
|
---|
164 | }
|
---|
165 |
|
---|
166 |
|
---|
167 | }
|
---|
168 | ///Technique factory
|
---|
169 | OgreHierarchicalParticleSystemTechniqueFactory::OgreHierarchicalParticleSystemTechniqueFactory()
|
---|
170 | {
|
---|
171 | typeName = "HPS";
|
---|
172 |
|
---|
173 | using namespace HPSParsers;
|
---|
174 |
|
---|
175 | //register parsers
|
---|
176 | this->attributeParsers.insert(AttribParserList::value_type("start_frame", (ILLUM_ATTRIBUTE_PARSER) parseStartFrame));
|
---|
177 | this->attributeParsers.insert(AttribParserList::value_type("update_interval", (ILLUM_ATTRIBUTE_PARSER) parseImpostorUpdateInterval));
|
---|
178 | this->attributeParsers.insert(AttribParserList::value_type("resolution", (ILLUM_ATTRIBUTE_PARSER) parseImpostorResolution));
|
---|
179 | this->attributeParsers.insert(AttribParserList::value_type("texture_unit_id", (ILLUM_ATTRIBUTE_PARSER) parseImpostorTexID));
|
---|
180 | this->attributeParsers.insert(AttribParserList::value_type("distance_calc", (ILLUM_ATTRIBUTE_PARSER) parseUseDistCalc));
|
---|
181 | this->attributeParsers.insert(AttribParserList::value_type("perspective", (ILLUM_ATTRIBUTE_PARSER) parsePerspectiveRendering));
|
---|
182 | this->attributeParsers.insert(AttribParserList::value_type("particle_script", (ILLUM_ATTRIBUTE_PARSER) parseScriptName));
|
---|
183 | this->attributeParsers.insert(AttribParserList::value_type("material", (ILLUM_ATTRIBUTE_PARSER) parseMaterialName));
|
---|
184 | this->attributeParsers.insert(AttribParserList::value_type("vparam_radius", (ILLUM_ATTRIBUTE_PARSER) parseVparamRadius));
|
---|
185 | this->attributeParsers.insert(AttribParserList::value_type("fparam_radius", (ILLUM_ATTRIBUTE_PARSER) parseFparamRadius));
|
---|
186 |
|
---|
187 | }
|
---|
188 |
|
---|
189 | OgreRenderTechnique* OgreHierarchicalParticleSystemTechniqueFactory::createInstance(
|
---|
190 | IllumTechniqueParams* params,
|
---|
191 | Pass* pass,
|
---|
192 | OgreRenderable* parentRenderable,
|
---|
193 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
194 | {
|
---|
195 | impostorUpdateInterval = 1;
|
---|
196 | impostorResolution = 256;
|
---|
197 | startFrame = 1;
|
---|
198 | useDistCalc = false;
|
---|
199 | impostorTexID = 0;
|
---|
200 | perspectiveRendering = true;
|
---|
201 | impostorMaterialName = "";
|
---|
202 | childPSysScriptName = "";
|
---|
203 | useOwnMaterial = true;
|
---|
204 | VParamRadius = "";
|
---|
205 | FParamRadius = "";
|
---|
206 | useVParam = false;
|
---|
207 | useFParam = false;
|
---|
208 |
|
---|
209 | parseParams(params);
|
---|
210 |
|
---|
211 | OgreHierarchicalParticleSystemTechnique* result = new OgreHierarchicalParticleSystemTechnique(
|
---|
212 | startFrame,
|
---|
213 | impostorUpdateInterval,
|
---|
214 | impostorResolution,
|
---|
215 | impostorTexID,
|
---|
216 | useDistCalc,
|
---|
217 | perspectiveRendering,
|
---|
218 | childPSysScriptName,
|
---|
219 | useOwnMaterial,
|
---|
220 | impostorMaterialName,
|
---|
221 | useVParam,
|
---|
222 | VParamRadius,
|
---|
223 | useFParam,
|
---|
224 | FParamRadius,
|
---|
225 | pass,
|
---|
226 | parentRenderable,
|
---|
227 | parentTechniqueGroup);
|
---|
228 |
|
---|
229 | return result;
|
---|
230 | }
|
---|
231 |
|
---|
232 |
|
---|