23 #include <gazebo/gazebo.hh> 24 #include <gazebo/common/common.hh> 25 #include <gazebo/rendering/rendering.hh> 35 const std::string &_paramName,
36 const std::string &_shaderType,
37 const std::string &_value)
40 if (_shaderType !=
"vertex" && _shaderType !=
"fragment")
42 gzerr <<
"Shader type: '" << _shaderType <<
"' is not supported" 49 auto setNamedParam = [](Ogre::GpuProgramParametersSharedPtr _params,
50 const std::string &_name,
const std::string &_v)
52 auto paramDef = _params->_findNamedConstantDefinition(_name);
56 switch (paramDef->constType)
60 int value = Ogre::StringConverter::parseInt(_v);
61 _params->setNamedConstant(_name, value);
64 case Ogre::GCT_FLOAT1:
66 Ogre::Real value = Ogre::StringConverter::parseReal(_v);
67 _params->setNamedConstant(_name, value);
70 #if (OGRE_VERSION >= ((1 << 16) | (9 << 8) | 0)) 72 case Ogre::GCT_FLOAT2:
74 Ogre::Vector2 value = Ogre::StringConverter::parseVector2(_v);
75 _params->setNamedConstant(_name, value);
80 case Ogre::GCT_FLOAT3:
82 Ogre::Vector3 value = Ogre::StringConverter::parseVector3(_v);
83 _params->setNamedConstant(_name, value);
87 case Ogre::GCT_FLOAT4:
89 Ogre::Vector4 value = Ogre::StringConverter::parseVector4(_v);
90 _params->setNamedConstant(_name, value);
93 case Ogre::GCT_MATRIX_4X4:
95 Ogre::Matrix4 value = Ogre::StringConverter::parseMatrix4(_v);
96 _params->setNamedConstant(_name, value);
105 Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(
106 _visual.GetMaterialName());
109 gzerr <<
"Failed to find material: '" << _visual.GetMaterialName()
113 for (
unsigned int i = 0; i < mat->getNumTechniques(); ++i)
115 Ogre::Technique *technique = mat->getTechnique(i);
118 for (
unsigned int j = 0; j < technique->getNumPasses(); ++j)
120 Ogre::Pass *pass = technique->getPass(j);
125 if (!pass->isProgrammable())
128 if (_shaderType ==
"vertex" && pass->hasVertexProgram())
130 setNamedParam(pass->getVertexProgramParameters(), \
133 else if (_shaderType ==
"fragment" && pass->hasFragmentProgram())
135 setNamedParam(pass->getFragmentProgramParameters(), \
140 gzerr <<
"Failed to retrieve shaders for material: '" 141 << _visual.GetMaterialName() <<
"', technique: '" 142 << technique->getName() <<
"', pass: '" 143 << pass->getName() <<
"'"
Support for methods not available in legacy versions of Gazebo.
void SetMaterialShaderParam(Visual &_visual, const std::string &_paramName, const std::string &_shaderType, const std::string &_value)
Set a shader program parameter associated to this visual's material.