Project

General

Profile

SO3Engine
SO3ShaderGenerator.cpp
Go to the documentation of this file.
1
8#include <boost/format.hpp>
9#include <boost/algorithm/string.hpp>
10
11#include "SO3Renderer/SO3Root.h"
13#include "SO3Material/SO3Pass.h"
18
19namespace SO3
20{
22
23SShaderGenerator::SShaderGenerator(Ogre::Technique* technique, Ogre::Pass* pass, ShaderType type, bool ignoreSlicePlane)
24{
25 mTechnique = technique;
26 mPass = pass;
27 mType = type;
28 mConfig = 0;
29 mShaderName = "";
30 mHighProfile = false;
31 mRefTexCoef = 1.0f;
32 mNotLight = false;
33 mNbLights = 6;
34 mUseVertexColor = false;
35 mUseAlphaRejection = false;
36 mIgnoreSlicePlane = ignoreSlicePlane;
37 ComputePass();
38}
39
40SShaderGenerator::SShaderGenerator()
41{
42 // Forbiden (private)
43}
44
49
51{
52 return mConfig;
53}
54
55void SShaderGenerator::ComputePass()
56{
57 std::stringstream out;
58 out << "SO3";
59
60 if (mPass->getAlphaRejectValue() > 120.0f)
61 mUseAlphaRejection = true;
62
63 switch (mType)
64 {
66 {
67 bool lightSet = false;
68 Ogre::RTShader::ShaderGenerator* shaderGen = Ogre::RTShader::ShaderGenerator::getSingletonPtr();
69 Ogre::RTShader::RenderState* rs = shaderGen->getRenderState(Ogre::MSN_SHADERGEN, *mTechnique->getParent(), mPass->getIndex());
70
71 if (!rs)
72 return;
73
74 //clean up first
75 rs->resetToBuiltinSubRenderStates();
76
77 Ogre::Any any = mPass->getUserObjectBindings().getUserAny("_RTSS_nonFFP_TUS");
78 if (any.has_value())
79 mPass->getUserObjectBindings().eraseUserAny("_RTSS_nonFFP_TUS");
80
81 if ((mPass->getVertexColourTracking() & Ogre::TVC_AMBIENT) || (mPass->getVertexColourTracking() == Ogre::TVC_DIFFUSE))
82 {
83 mUseVertexColor = true;
84
85 Ogre::RTShader::SubRenderState* srs = shaderGen->createSubRenderState(Ogre::RTShader::SRS_VERTEX_COLOUR);
86 rs->addTemplateSubRenderState(srs);
87 }
88
90 {
91 Ogre::RTShader::SubRenderState* srs = shaderGen->createSubRenderState(SRS_CLIP_PLANE);
92 rs->addTemplateSubRenderState(srs);
93 }
94
95 unsigned int refIndex = 0;
96 unsigned int specIndex = 0;
97
98 Ogre::Pass::TextureUnitStates units = mPass->getTextureUnitStates();
99 for (unsigned int i = 0; i < units.size(); i++)
100 {
101 Ogre::TextureUnitState* pTex = units[i];
103 Ogre::String tex_filename = pTex->getTextureName();
104 Ogre::StringUtil::toLowerCase(tex_filename);
105
106 Ogre::TextureUnitState::EffectMap effects = pTex->getEffects();
107 Ogre::TextureUnitState::EffectMap::const_iterator effectEnd = effects.end();
108
109 bool animatedUv = false;
110 if (!effects.empty() && ((effects.find(Ogre::TextureUnitState::ET_ROTATE) != effectEnd) ||
111 (effects.find(Ogre::TextureUnitState::ET_TRANSFORM) != effectEnd) ||
112 (effects.find(Ogre::TextureUnitState::ET_USCROLL) != effectEnd) ||
113 (effects.find(Ogre::TextureUnitState::ET_VSCROLL) != effectEnd) ||
114 (effects.find(Ogre::TextureUnitState::ET_UVSCROLL) != effectEnd)))
115 {
116 animatedUv = true;
117 }
118
119 if ((pTex->getTextureUScroll() != 0.0f) || (pTex->getTextureVScroll() != 0.0f) ||
120 (pTex->getTextureUScale() != 1.0f) || (pTex->getTextureVScale() != 1.0f) ||
121 (pTex->getTextureRotate().valueRadians() != 0.0f))
122 {
123 animatedUv = true;
124 }
125
126 bool envMap = false;
127 if (!effects.empty() && (effects.find(Ogre::TextureUnitState::ET_ENVIRONMENT_MAP) != effectEnd))
128 envMap = true;
129
130 if (!(mConfig & MAP_NORMAL) && (uType == MAP_NORMAL))
131 {
133 Ogre::RTShader::ShaderGenerator::_markNonFFP(pTex);
134 Ogre::RTShader::SubRenderState* srs = shaderGen->createSubRenderState(Ogre::RTShader::SRS_NORMALMAP);
135 srs->setParameter("texture_index", std::to_string(mPass->getTextureUnitStateIndex(pTex)));
136
137 if (tex_filename.find("object") != Ogre::String::npos)
138 srs->setParameter("normalmap_space", "object_space");
139 else if (tex_filename.find("parallax") != Ogre::String::npos)
140 srs->setParameter("normalmap_space", "parallax");
141 else if ((tex_filename.find("parallax_oc") != Ogre::String::npos) || (tex_filename.find("normheight") != Ogre::String::npos) || (tex_filename.find("parallax_occlusion") != Ogre::String::npos))
142 srs->setParameter("normalmap_space", "parallax_occlusion");
143 else
144 srs->setParameter("normalmap_space", "tangent_space");
145
146 srs->setParameter("height_scale", "0.1");
147
148 rs->addTemplateSubRenderState(srs);
149 }
150 else if (!(mConfig & MAP_ROUGHNESS) && (uType == MAP_ROUGHNESS))
151 {
153
154 Ogre::RTShader::SubRenderState* lightsrs = shaderGen->createSubRenderState(SRS_ADV_COOK_TORRANCE_LIGHTING);
155 //Ogre::RTShader::SubRenderState* lightsrs = shaderGen->createSubRenderState(Ogre::RTShader::SRS_COOK_TORRANCE_LIGHTING);
156 if (mPass->getCullingMode() == Ogre::CULL_NONE)
157 lightsrs->setParameter("two_sided", "1");
158
159 Ogre::RTShader::ShaderGenerator::_markNonFFP(pTex);
160 lightsrs->setParameter("texture", pTex->getTextureName());
161 if ((tex_filename.find("occlusion") != Ogre::String::npos) || (tex_filename.find("orm") != Ogre::String::npos) || (tex_filename.find("occ_") != Ogre::String::npos))
162 lightsrs->setParameter("occlusion", "YES");
163
164 rs->addTemplateSubRenderState(lightsrs);
165
166 Ogre::RTShader::SubRenderState* srs = shaderGen->createSubRenderState(Ogre::RTShader::SRS_TEXTURING);
167 srs->setParameter("late_add_blend", "true");
168 rs->addTemplateSubRenderState(srs);
169 lightSet = true;
170 }
171 else if (!(mConfig & MAP_EMISSIVE) && (uType == MAP_EMISSIVE))
172 {
174 Ogre::RTShader::LayeredBlending* lrs = static_cast<Ogre::RTShader::LayeredBlending*>(shaderGen->createSubRenderState(Ogre::RTShader::SRS_LAYERED_BLENDING));
175 lrs->setBlendMode(i, "add");
176 rs->addTemplateSubRenderState(lrs);
177 }
178 else if (!(mConfig & MAP_REFMASK) && (uType == MAP_REFMASK))
179 {
181 Ogre::RTShader::ShaderGenerator::_markNonFFP(pTex);
182 }
183 else if (!(mConfig & MAP_REFLECTION) && (uType == MAP_REFLECTION))
184 {
186 refIndex = i;
187 }
188 else if (!(mConfig & MAP_OPACITY) && (uType == MAP_OPACITY))
189 {
191 Ogre::RTShader::SubRenderState* srs = shaderGen->createSubRenderState(Ogre::RTShader::SRS_ALPHA_TEST);
192 rs->addTemplateSubRenderState(srs);
193 }
194 else if (!(mConfig & MAP_SPECULAR) && (uType == MAP_SPECULAR))
195 {
197 pTex->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_TEXTURE, Ogre::LBS_SPECULAR, Ogre::ColourValue::White, Ogre::ColourValue::White, 1.0);
198 specIndex = i;
199 }
200 else if (!(mConfig & MAP_SHININESS) && (uType == MAP_SHININESS))
201 {
203 Ogre::RTShader::ShaderGenerator::_markNonFFP(pTex);
204 }
205 else if (!(mConfig & MAP_DIFFUSE)) // only one
206 {
208 }
209 else //dummy
210 {
212 }
213 }
214
215 //use specular map as roughness
216 /*if (mConfig & MAP_SPECULAR)
217 {
218 Ogre::TextureUnitState* pTex = mPass->getTextureUnitState(specIndex);
219 if (pTex)
220 {
221 if (mConfig & MAP_ROUGHNESS)
222 {
223 //ignore texture unit
224 Ogre::RTShader::ShaderGenerator::_markNonFFP(pTex);
225 }
226 else
227 {
228 mConfig |= MAP_ROUGHNESS;
229
230 Ogre::RTShader::SubRenderState* lightsrs = shaderGen->createSubRenderState(SRS_ADV_COOK_TORRANCE_LIGHTING);
231 if (mPass->getCullingMode() == Ogre::CULL_NONE)
232 lightsrs->setParameter("two_sided", "1");
233
234 Ogre::RTShader::ShaderGenerator::_markNonFFP(pTex);
235 lightsrs->setParameter("texture", pTex->getTextureName());
236
237 Ogre::RTShader::SubRenderState* srs = shaderGen->createSubRenderState(Ogre::RTShader::SRS_TEXTURING);
238 srs->setParameter("late_add_blend", "true");
239 rs->addTemplateSubRenderState(srs);
240 rs->addTemplateSubRenderState(lightsrs);
241 lightSet = true;
242 }
243 }
244 }*/
245
246 if (!lightSet)
247 {
248 Ogre::RTShader::SubRenderState* lightsrs = shaderGen->createSubRenderState(Ogre::RTShader::SRS_PER_PIXEL_LIGHTING);
249 if (mPass->getCullingMode() == Ogre::CULL_NONE)
250 lightsrs->setParameter("two_sided", "1");
251 rs->addTemplateSubRenderState(lightsrs);
252 }
253
254 // use reflection coef
256 {
257 Ogre::TextureUnitState* pTex = mPass->getTextureUnitState(refIndex);
258
259 if (pTex)
260 {
261 const Ogre::LayerBlendModeEx& bl = pTex->getColourBlendMode();
262 Ogre::RTShader::ShaderGenerator::_markNonFFP(pTex);
263 Ogre::RTShader::SubRenderState* srs = shaderGen->createSubRenderState(Ogre::RTShader::SRS_IMAGE_BASED_LIGHTING);
264 srs->setParameter("texture", pTex->getTextureName());
265 srs->setParameter("luminance", std::to_string((bl.factor == 0.0f) ? 4.0f : bl.factor * 4.0f));
266 rs->addTemplateSubRenderState(srs);
267 }
268 }
269 //else if (mConfig & MAP_REFLECTION)
270 //{
271 // Ogre::TextureUnitState* pTex = mPass->getTextureUnitState(refIndex);
272 //
273 // if (pTex)
274 // {
275 // Ogre::RTShader::LayeredBlending* srs = static_cast<Ogre::RTShader::LayeredBlending*>(shaderGen->createSubRenderState(Ogre::RTShader::SRS_LAYERED_BLENDING));
276 // srs->setBlendMode(refIndex, "multiply");
277 // rs->addTemplateSubRenderState(srs);
278 // }
279 //}
280 }
282 {
283 if (!mPass->getLightingEnabled())
284 {
285 out << "vsNoLightGEN";
286 mNotLight = true;
287 mNbLights = 0;
288 }
289 else
290 out << "vsLightGEN";
291
292 if ((mPass->getVertexColourTracking() & Ogre::TVC_AMBIENT) || (mPass->getVertexColourTracking() == Ogre::TVC_DIFFUSE))
293 {
294 mUseVertexColor = true;
295 out << "VCOLOR";
296 }
297
298 Ogre::Pass::TextureUnitStates units = mPass->getTextureUnitStates();
299 for (unsigned int i = 0; i < units.size(); i++)
300 {
301 Ogre::TextureUnitState* pTex = units[i];
303
304 Ogre::TextureUnitState::EffectMap effects = pTex->getEffects();
305 Ogre::TextureUnitState::EffectMap::const_iterator effectEnd = effects.end();
306
307 bool animatedUv = false;
308 if (!effects.empty() && ((effects.find(Ogre::TextureUnitState::ET_ROTATE) != effectEnd) ||
309 (effects.find(Ogre::TextureUnitState::ET_TRANSFORM) != effectEnd) ||
310 (effects.find(Ogre::TextureUnitState::ET_USCROLL) != effectEnd) ||
311 (effects.find(Ogre::TextureUnitState::ET_VSCROLL) != effectEnd) ||
312 (effects.find(Ogre::TextureUnitState::ET_UVSCROLL) != effectEnd)))
313 {
314 animatedUv = true;
315 }
316
317 if ((pTex->getTextureUScroll() != 0.0f) || (pTex->getTextureVScroll() != 0.0f) ||
318 (pTex->getTextureUScale() != 1.0f) || (pTex->getTextureVScale() != 1.0f) ||
319 (pTex->getTextureRotate().valueRadians() != 0.0f))
320 {
321 animatedUv = true;
322 }
323
324 bool envMap = false;
325 if (!effects.empty() && (effects.find(Ogre::TextureUnitState::ET_ENVIRONMENT_MAP) != effectEnd))
326 envMap = true;
327
328 if (!(mConfig & MAP_AMBIENT) && (uType == MAP_AMBIENT))
329 {
331 mTexUnits.push_back(pTex->getTextureCoordSet());
332 mAnimatedUv.push_back(animatedUv);
333 mTexTypes.push_back(MAP_AMBIENT);
334 mCubeUv.push_back(pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP);
335 }
336 else if (!(mConfig & MAP_NORMAL) && (uType == MAP_NORMAL))
337 {
339 out << i;
340 out << "NORM";
341 mTexUnits.push_back(pTex->getTextureCoordSet());
342 mAnimatedUv.push_back(animatedUv);
343 mTexTypes.push_back(MAP_NORMAL);
344 mCubeUv.push_back(pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP);
345 }
346 else if (!(mConfig & MAP_EMISSIVE) && (uType == MAP_EMISSIVE))
347 {
349 mTexUnits.push_back(pTex->getTextureCoordSet());
350 mAnimatedUv.push_back(animatedUv);
351 mTexTypes.push_back(MAP_EMISSIVE);
352 mCubeUv.push_back(pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP);
353 }
354 else if (!(mConfig & MAP_REFMASK) && (uType == MAP_REFMASK))
355 {
357 mTexUnits.push_back(pTex->getTextureCoordSet());
358 mAnimatedUv.push_back(animatedUv);
359 mTexTypes.push_back(MAP_REFMASK);
360 mCubeUv.push_back(pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP);
361 }
362 else if (!(mConfig & MAP_REFLECTION) && (uType == MAP_REFLECTION))
363 {
365 mTexUnits.push_back(pTex->getTextureCoordSet());
366 mAnimatedUv.push_back(animatedUv);
367 mTexTypes.push_back(MAP_REFLECTION);
368 mCubeUv.push_back(pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP);
369 }
370 else if (!(mConfig & MAP_OPACITY) && (uType == MAP_OPACITY))
371 {
373 mTexUnits.push_back(pTex->getTextureCoordSet());
374 mAnimatedUv.push_back(animatedUv);
375 mTexTypes.push_back(MAP_OPACITY);
376 mCubeUv.push_back(pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP);
377 }
378 else if (!(mConfig & MAP_SPECULAR) && (uType == MAP_SPECULAR))
379 {
381 mTexUnits.push_back(pTex->getTextureCoordSet());
382 mAnimatedUv.push_back(animatedUv);
383 mTexTypes.push_back(MAP_SPECULAR);
384 mCubeUv.push_back(pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP);
385 }
386 else if (!(mConfig & MAP_SHININESS) && (uType == MAP_SHININESS))
387 {
389 mTexUnits.push_back(pTex->getTextureCoordSet());
390 mAnimatedUv.push_back(animatedUv);
391 mTexTypes.push_back(MAP_SHININESS);
392 mCubeUv.push_back(pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP);
393 }
394 else if (!(mConfig & MAP_ROUGHNESS) && (uType == MAP_ROUGHNESS))
395 {
397 mTexUnits.push_back(pTex->getTextureCoordSet());
398 mAnimatedUv.push_back(animatedUv);
399 mTexTypes.push_back(MAP_ROUGHNESS);
400 mCubeUv.push_back(pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP);
401 }
402 else if (!(mConfig & MAP_DIFFUSE)) // only one
403 {
405 mTexUnits.push_back(pTex->getTextureCoordSet());
406 mAnimatedUv.push_back(animatedUv);
407 mTexTypes.push_back(MAP_DIFFUSE);
408 mCubeUv.push_back(pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP);
409 }
410 else //dummy
411 {
413 mTexUnits.push_back(pTex->getTextureCoordSet());
414 mAnimatedUv.push_back(animatedUv);
415 mTexTypes.push_back(MAP_DUMMY);
416 mCubeUv.push_back(pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP);
417 }
418 }
419
421 std::sort(mSortedTexUnits.begin(), mSortedTexUnits.end());
422 mSortedTexUnits.erase(std::unique(mSortedTexUnits.begin(), mSortedTexUnits.end()), mSortedTexUnits.end());
423
424 for (unsigned int i = 0; i < mSortedTexUnits.size(); i++)
425 {
426 out << mSortedTexUnits[i];
427 bool iscube = false;
428 for (unsigned int j = 0; j < mTexUnits.size(); j++)
429 {
430 if (mTexUnits[j] == mSortedTexUnits[i])
431 {
432 if (mCubeUv[j])
433 {
434 out << "C";
435 iscube = true;
436 }
437
438 if (mAnimatedUv[j])
439 {
440 out << j;
441 out << "A";
442 }
443 }
444 }
445 mSortedCubeUv.push_back(iscube);
446 }
447
448 break;
449 }
450
452 {
453 if (!mPass->getLightingEnabled())
454 {
455 out << "fpNoLightGEN";
456 mNotLight = true;
457 mNbLights = 0;
458 }
459 else
460 out << "fpLightGEN";
461
463 out << "NOSLP";
464
465 if ((mPass->getVertexColourTracking() & Ogre::TVC_AMBIENT) || (mPass->getVertexColourTracking() == Ogre::TVC_DIFFUSE))
466 {
467 mUseVertexColor = true;
468 out << "VCOLOR";
469 }
470
472 out << "REJECT";
473
474 bool isMask = false;
475 Ogre::Pass::TextureUnitStates units = mPass->getTextureUnitStates();
476 for (unsigned int i = 0; i < units.size(); i++)
477 {
478 Ogre::TextureUnitState* pTex = units[i];
480 Ogre::String tex_filename = pTex->getTextureName();
481 Ogre::StringUtil::toLowerCase(tex_filename);
482
483 Ogre::TextureUnitState::EffectMap effects = pTex->getEffects();
484 Ogre::TextureUnitState::EffectMap::const_iterator effectEnd = effects.end();
485
486 bool envMap = false;
487 if (!effects.empty() && (effects.find(Ogre::TextureUnitState::ET_ENVIRONMENT_MAP) != effectEnd))
488 envMap = true;
489
490 if (!(mConfig & MAP_AMBIENT) && (uType == MAP_AMBIENT))
491 {
493 out << i;
494 out << "AMB";
495 out << pTex->getTextureCoordSet();
496 if (pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP)
497 out << "C";
498
499 mTexUnits.push_back(pTex->getTextureCoordSet());
500 mTexTypes.push_back(MAP_AMBIENT);
501 mCubeUv.push_back(pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP);
502 }
503 else if (!(mConfig & MAP_NORMAL) && (uType == MAP_NORMAL))
504 {
506 out << i;
507 out << "NORM";
508 out << pTex->getTextureCoordSet();
509 if (pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP)
510 out << "C";
511
512 mTexUnits.push_back(pTex->getTextureCoordSet());
513 mTexTypes.push_back(MAP_NORMAL);
514 mCubeUv.push_back(pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP);
515 }
516 else if (!(mConfig & MAP_EMISSIVE) && (uType == MAP_EMISSIVE))
517 {
518 out << i;
519 out << "EMI";
520 out << pTex->getTextureCoordSet();
521 if (pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP)
522 out << "C";
523
525 mTexUnits.push_back(pTex->getTextureCoordSet());
526 mTexTypes.push_back(MAP_EMISSIVE);
527 mCubeUv.push_back(pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP);
528 }
529 else if (!(mConfig & MAP_REFMASK) && (uType == MAP_REFMASK))
530 {
531 out << i;
532 out << "REFMASK";
533 out << pTex->getTextureCoordSet();
534 if (pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP)
535 out << "C";
536
538 mTexUnits.push_back(pTex->getTextureCoordSet());
539 mTexTypes.push_back(MAP_REFMASK);
540 mCubeUv.push_back(pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP);
541 }
542 else if (!(mConfig & MAP_REFLECTION) && (uType == MAP_REFLECTION))
543 {
544 out << i;
545 out << "REF";
546
547 mRefTexCoef = pTex->getColourBlendMode().factor;
548 if (mRefTexCoef == 0.0f)
549 mRefTexCoef = 1.0f; //default
550
551 if ((tex_filename.find("fresn") != Ogre::String::npos))
552 {
553 out << "Fresnel";
555 }
556
557 out << pTex->getTextureCoordSet();
558 if (pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP)
559 out << "C";
560
562 mTexUnits.push_back(pTex->getTextureCoordSet());
563 mTexTypes.push_back(MAP_REFLECTION);
564 mCubeUv.push_back(pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP);
565 }
566 else if (!(mConfig & MAP_OPACITY) && (uType == MAP_OPACITY))
567 {
568 out << i;
569 out << "OPAC";
570 out << pTex->getTextureCoordSet();
571 if (pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP)
572 out << "C";
573
575 mTexUnits.push_back(pTex->getTextureCoordSet());
576 mTexTypes.push_back(MAP_OPACITY);
577 mCubeUv.push_back(pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP);
578 }
579 else if (!(mConfig & MAP_SPECULAR) && (uType == MAP_SPECULAR))
580 {
581 out << i;
582 out << "SPEC";
583 out << pTex->getTextureCoordSet();
584 if (pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP)
585 out << "C";
586
588 mTexUnits.push_back(pTex->getTextureCoordSet());
589 mTexTypes.push_back(MAP_SPECULAR);
590 mCubeUv.push_back(pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP);
591 }
592 else if (!(mConfig & MAP_SHININESS) && (uType == MAP_SHININESS))
593 {
594 out << i;
595 out << "SHIN";
596 out << pTex->getTextureCoordSet();
597 if (pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP)
598 out << "C";
599
601 mTexUnits.push_back(pTex->getTextureCoordSet());
602 mTexTypes.push_back(MAP_SHININESS);
603 mCubeUv.push_back(pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP);
604 }
605 else if (!(mConfig & MAP_ROUGHNESS) && (uType == MAP_ROUGHNESS))
606 {
608 mTexUnits.push_back(pTex->getTextureCoordSet());
609 mTexTypes.push_back(MAP_ROUGHNESS);
610 mCubeUv.push_back(pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP);
611 }
612 else if (!(mConfig & MAP_DIFFUSE)) // only one
613 {
614 out << i;
615 out << "DIFF";
616 out << pTex->getTextureCoordSet();
617 if (pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP)
618 out << "C";
619
621 mTexUnits.push_back(pTex->getTextureCoordSet());
622 mTexTypes.push_back(MAP_DIFFUSE);
623 mCubeUv.push_back(pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP);
624 }
625 else //dummy
626 {
628
629 mTexUnits.push_back(pTex->getTextureCoordSet());
630 mTexTypes.push_back(MAP_DUMMY);
631 mCubeUv.push_back(pTex->getTextureType() == Ogre::TEX_TYPE_CUBE_MAP);
632 }
633 }
634
635 if ((mConfig & MAP_FRESNEL) && (mConfig & MAP_NORMAL))
636 {
637 mNbLights = 4;
638 }
639
640 if (mNbLights > 0)
641 {
642 out << "L";
643 out << mNbLights;
644 }
645
647 std::sort(mSortedTexUnits.begin(), mSortedTexUnits.end());
648 mSortedTexUnits.erase(std::unique(mSortedTexUnits.begin(), mSortedTexUnits.end()), mSortedTexUnits.end());
649
650 for (unsigned int i = 0; i < mSortedTexUnits.size(); i++)
651 {
652 bool iscube = false;
653 for (unsigned int j = 0; j < mTexUnits.size() && !iscube; j++)
654 {
655 if (mTexUnits[j] == mSortedTexUnits[i] && mCubeUv[j])
656 {
657 iscube = true;
658 }
659 }
660 mSortedCubeUv.push_back(iscube);
661 }
662
663 break;
664 }
665 }
666 mShaderName = out.str();
667}
668
670{
671 return mShaderName;
672}
673
675{
676 for (unsigned int i = 0; i < mTexUnits.size(); i++)
677 {
678 if ((mTexUnits[i] == uvindex) && mAnimatedUv[i])
679 return true;
680 }
681
682 return false;
683}
684
689
694
696{
697 return "";
698}
699
701{
702 return "";
703}
704
706{
708 {
710
711 //Ogre::SceneManager* sceneManager = shaderGen->getActiveSceneManager();
712 //if (!sceneManager)
713 // return;
714 //
715 //shaderGen->validateMaterial(Ogre::MSN_SHADERGEN, *mTechnique->getParent());
716 }
717}
718
719}
static SShaderGenerator::ShaderMapType GetTextureUnitType(Ogre::TextureUnitState *unit)
Definition SO3Pass.cpp:115
static SRoot * getSingletonPtr()
Definition SO3Root.cpp:111
void InvalidateGeneratedMaterial(Ogre::Material *mat)
Definition SO3Root.cpp:2350
std::vector< unsigned int > mSortedTexUnits
virtual std::string GetUniformParams()
std::list< Ogre::GpuProgramPtr > GeneratedShaders
Ogre::Technique * mTechnique
std::vector< ShaderMapType > mTexTypes
std::vector< bool > mSortedCubeUv
bool IsUvAnimated(int uvindex)
std::vector< unsigned int > mTexUnits
std::vector< bool > mCubeUv
virtual std::string GetProgram()
std::vector< bool > mAnimatedUv
static GeneratedShaders mGeneratedShaders
const Ogre::String SRS_CLIP_PLANE
const Ogre::String SRS_ADV_COOK_TORRANCE_LIGHTING