17 #ifndef _LIGHTMATERIALGENERATOR_HH_
18 #define _LIGHTMATERIALGENERATOR_HH_
20 #include <OgreStringConverter.h>
21 #include <OgreException.h>
22 #include <OgreMaterialManager.h>
25 #include <OgreTechnique.h>
27 #include <OgreHighLevelGpuProgram.h>
28 #include <OgreHighLevelGpuProgramManager.h>
41 template<
typename techniquePolicy>
44 template<
typename techniquePolicy>
53 MI_DIRECTIONAL = 0x04,
56 MI_SHADOW_CASTER = 0x20
66 this->schemeName.clear();
67 materialBaseName = this->GetMaterialPrefix() +
"/LightMaterial/";
76 template<
typename techniquePolicy>
78 public MaterialGenerator::Impl,
public techniquePolicy
84 : baseName(_baseName) {}
93 std::string programName =
"DeferredShading/";
99 programName +=
"LightMaterial_vs";
101 Ogre::GpuProgramPtr ptr =
102 Ogre::HighLevelGpuProgramManager::getSingleton().getByName(
160 if (this->masterSource.empty())
162 Ogre::DataStreamPtr ptrMasterSource =
163 Ogre::ResourceGroupManager::getSingleton().openResource(
164 "deferred_rendering/deferred_shading/light_material_ps.glsl",
165 Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
167 if (ptrMasterSource.isNull())
170 this->masterSource = ptrMasterSource->getAsString();
173 if (this->masterSource.empty())
177 std::string name = this->baseName +
178 Ogre::StringConverter::toString(_permutation) +
"_ps";
181 Ogre::HighLevelGpuProgramPtr ptrProgram =
182 Ogre::HighLevelGpuProgramManager::getSingleton().createProgram(
183 name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
184 "glsl", Ogre::GPT_FRAGMENT_PROGRAM);
186 ptrProgram->setSource(this->masterSource);
193 ptrProgram->setParameter(
"preprocessor_defines",
194 this->GetPPDefines(_permutation));
196 this->SetUpBaseParameters(ptrProgram->getDefaultParameters());
198 ptrProgram->getDefaultParameters()->setNamedConstant(
199 "tex0", static_cast<int>(0));
203 if (ptrProgram->getDefaultParameters()->_findNamedConstantDefinition(
206 ptrProgram->getDefaultParameters()->setNamedConstant(
207 "tex1", static_cast<int>(1));
213 ptrProgram->getDefaultParameters()->setNamedConstant(
214 "shadowTex", static_cast<int>(1));
217 return Ogre::GpuProgramPtr(ptrProgram);
224 std::string materialName = this->baseName;
228 materialName +=
"Quad";
230 materialName +=
"Geometry";
234 materialName +=
"Shadow";
236 return Ogre::MaterialManager::getSingleton().getByName(
290 std::string lightType;
296 else if (_permutation &
301 else if (_permutation &
304 lightType =
"DIRECTIONAL";
307 gzthrow(
"Permutation must have a light type");
309 strPPD +=
"LIGHT_TYPE=LIGHT_" + lightType +
";";
315 strPPD +=
"IS_SPECULAR=1;";
321 strPPD +=
"IS_ATTENUATED=1;";
327 strPPD +=
"IS_SHADOW_CASTER=1;";
330 if (this->UseMaterialProperties())
331 strPPD +=
"USE_MAT_PROPERTIES=1;";
338 const Ogre::GpuProgramParametersSharedPtr &_params)
340 if (_params.isNull())
346 Ogre::GpuProgramParameters::AutoConstantType type;
351 static const AutoParamPair AUTO_PARAMS[] =
354 Ogre::GpuProgramParameters::ACT_VIEWPORT_WIDTH},
356 Ogre::GpuProgramParameters::ACT_VIEWPORT_HEIGHT},
358 Ogre::GpuProgramParameters::ACT_WORLDVIEW_MATRIX},
360 Ogre::GpuProgramParameters::ACT_INVERSE_PROJECTION_MATRIX},
362 Ogre::GpuProgramParameters::ACT_INVERSE_VIEW_MATRIX},
364 Ogre::GpuProgramParameters::ACT_RENDER_TARGET_FLIPPING},
365 {
"lightDiffuseColor",
366 Ogre::GpuProgramParameters::ACT_LIGHT_DIFFUSE_COLOUR},
367 {
"lightSpecularColor",
368 Ogre::GpuProgramParameters::ACT_LIGHT_SPECULAR_COLOUR},
370 Ogre::GpuProgramParameters::ACT_LIGHT_ATTENUATION},
372 Ogre::GpuProgramParameters::ACT_LIGHT_POSITION_VIEW_SPACE},
374 Ogre::GpuProgramParameters::ACT_LIGHT_DIRECTION_VIEW_SPACE},
376 Ogre::GpuProgramParameters::ACT_SPOTLIGHT_PARAMS},
378 Ogre::GpuProgramParameters::ACT_FAR_CLIP_DISTANCE},
379 {
"shadowViewProjMat",
380 Ogre::GpuProgramParameters::ACT_TEXTURE_VIEWPROJ_MATRIX}
383 int numParams =
sizeof(AUTO_PARAMS) /
sizeof(AutoParamPair);
385 for (
int i = 0; i < numParams; ++i)
387 if (_params->_findNamedConstantDefinition(AUTO_PARAMS[i].name))
389 _params->setNamedAutoConstant(
390 AUTO_PARAMS[i].name, AUTO_PARAMS[i].type);
std::string masterSource
Definition: LightMaterialGenerator.hh:396
std::string baseName
Definition: LightMaterialGenerator.hh:395
Definition: LightMaterialGenerator.hh:53
LightMaterialGenerator()
Definition: LightMaterialGenerator.hh:59
virtual Ogre::GpuProgramPtr GenerateVertexShader(Perm _permutation)
Definition: LightMaterialGenerator.hh:90
Definition: LightMaterialGenerator.hh:42
void SetUpBaseParameters(const Ogre::GpuProgramParametersSharedPtr &_params)
Definition: LightMaterialGenerator.hh:337
virtual Ogre::GpuProgramPtr GenerateFragmentShader(Perm _permutation)
Definition: LightMaterialGenerator.hh:156
#define gzthrow(msg)
This macro logs an error to the throw stream and throws an exception that contains the file name and ...
Definition: Exception.hh:39
MaterialGenerator::Perm Perm
Definition: LightMaterialGenerator.hh:80
std::string GetPPDefines(Perm _permutation)
Definition: LightMaterialGenerator.hh:285
Definition: LightMaterialGenerator.hh:45
LightMaterialGeneratorGLSL(const std::string &_baseName)
Definition: LightMaterialGenerator.hh:83
Caching, on-the-fly material generator.
Definition: MaterialGenerator.hh:39
virtual Ogre::MaterialPtr GenerateTemplateMaterial(Perm _permutation)
Definition: LightMaterialGenerator.hh:221
Definition: LightMaterialGenerator.hh:56
MaterialID
Permutation of light materials.
Definition: LightMaterialGenerator.hh:49
virtual ~LightMaterialGenerator()
Definition: LightMaterialGenerator.hh:72
virtual ~LightMaterialGeneratorGLSL()
Definition: LightMaterialGenerator.hh:87
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
uint32_t Perm
Bitfield used to signify a material permutations.
Definition: MaterialGenerator.hh:42