As a first step in my testing I created a wrapper for the createEntity() call to modify the entity's material and set the custom parameter to blue. Unfortunately, all I am getting are black entities as if the shader is failing.
But when I manually use setNamedConstant() as a parameter in the pass for the vertex shader it seems to work, which suggests that the shader is working (at some level). I've been searching through the forums for the past couple of weeks and found many related comments (mostly old posts) but nothing quite like what I've experienced.
Here is my wrapper code to set the material and custom colour for each entity:
Code: Select all
constexpr unsigned int MODELCOLOR_INDEX=0;
inline Ogre::MaterialPtr get_object_material()
{
static Ogre::MaterialPtr g_mat;
if (g_mat.isNull())
{
g_mat = Ogre::MaterialManager::getSingleton().getByName("Gazebo/ObjectMap");
g_mat->load();
}
return g_mat;
}
template<typename... Args>
Ogre::Entity* create_entity(Ogre::SceneManager* sm, Args&&... args)
{
Ogre::Vector4 somecolor{0.0, 0.0, 1.0, 1.0};
Ogre::Entity* pEntity = sm->createEntity(args...);
pEntity->setMaterial(get_object_material());
for (unsigned int i = 0; i < pEntity->getNumSubEntities(); ++i)
{
pEntity->getSubEntity(i)->setCustomParameter(MODELCOLOR_INDEX, somecolor);
pEntity->getSubEntity(i)->setMaterial(get_object_material());
}
return pEntity;
}
Code: Select all
vertex_program Gazebo/ObjectMapVS glsl
{
source object_map.vert
param_named_auto modelColor custom 0
default_params
{
param_named_auto texelOffsets texel_offsets
}
}
fragment_program Gazebo/ObjectMapFS glsl
{
source object_map.frag
}
material Gazebo/ObjectMap
{
technique
{
pass
{
vertex_program_ref Gazebo/ObjectMapVS { }
fragment_program_ref Gazebo/ObjectMapFS { }
}
}
}
The vertex shader object_map.vert:
Code: Select all
uniform vec4 texelOffsets;
uniform vec4 modelColor;
varying vec4 mcolor;
void main()
{
gl_Position = ftransform();
gl_Position.xy += texelOffsets.zw * gl_Position.w;
mcolor = modelColor;
}
Code: Select all
varying vec4 mcolor;
void main()
{
gl_FragColor = mcolor;
}
However, as part of rendering to a texture (which is ultimately what I want to do) I explicitly set the "modelColor" named constant as a parameter for the vertex shader pass:
Code: Select all
auto vparams = pass->getVertexProgramParameters();
Ogre::Vector4 vec4{0.0, 1.0, 0.0, 1.0};
vparams->setNamedConstant("modelColor", vec4);
pass->setVertexProgramParameters(vparams);
So I am confused why it is not treating the "modelColor" as a custom parameter (which should be set here with index 0) and instead treating it as a named constant. Is there something wrong in how I've set up the shaders or is it something deeper in my (lack of) understanding?
Dave
