I found a very ugly way to pass any data to shaders. Is a quite simple, but is not so ellegant.
Uploaded with ImageShack.us
The numbers on the cars noose aren't part of the texture. They are applyed via shaders. The same shader applyed both numbers.
I wont post the whole shader here, because I think that is not so useful.
The data are passed this way:
main.cpp
Code: Select all
struct shaderData
{
float number;
//any other data to pass? Go ahead...
};
...
int main()
{
...
shaderData carData;
carData.number = 17;
shaderData * pointer = &carData;
car->getMaterial(3).MaterialTypeParam2 = (f32)((int)pointer);
car->getMaterial(3).MaterialType = (E_MATERIAL_TYPE)shaderMat;
...
}
Code: Select all
class MyShaderCallBack: public video::IShaderConstantSetCallBack
{
f32 number;
const video::SMaterial * mat;
public:
virtual void OnSetMaterial(const video::SMaterial& material)
{
mat = &material;
shaderData * data;
data = (shaderData*)((int)mat->MaterialTypeParam2);
number = data->number;
};
virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
{
int texture = 0;
services->setPixelShaderConstant("tex0",(float*)(&texture),1);
services->setPixelShaderConstant("number", reinterpret_cast<irr::f32*>(&number),1);
};
};
To make this, only I had to do is pass a pointer to my structure in the 'MaterialTypeParam2'. Inside the callback I retrieved that pointer and this does the trick.
Hope it helps!