I made my lightnode a global variable (mistake?) so I could access it in my callback.
Here's my shader callback:
Code: Select all
class MyShaderCallBack : public video::IShaderConstantSetCallBack
{
public:
virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
{
video::IVideoDriver* driver = services->getVideoDriver();
core::matrix4 invWorld = driver->getTransform(video::ETS_WORLD);
invWorld.makeInverse();
// set clip matrix
core::matrix4 worldViewProj;
worldViewProj = driver->getTransform(video::ETS_PROJECTION);
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
if (UseHighLevelShaders)
services->setVertexShaderConstant("mWorldViewProj", &worldViewProj.M[0], 16);
else
services->setVertexShaderConstant(&worldViewProj.M[0], 4, 4);
vector3df lightPosOS;
invWorld.transformVect(light1->getPosition(),lightPosOS);
if (UseHighLevelShaders)
services->setVertexShaderConstant("mLightPos", reinterpret_cast<f32*>(&lightPosOS), 3);
else
services->setVertexShaderConstant(reinterpret_cast<f32*>(&lightPosOS), 8, 1);
// set light color
video::SColorf col(0.0f,1.0f,1.0f,0.0f);
}
};
Code: Select all
s32 toonshader = 0;
if (gpu)
{
MyShaderCallBack* mc = new MyShaderCallBack();
if (UseHighLevelShaders)
{
toonshader = gpu->addHighLevelShaderMaterialFromFiles(
vsFileName, "vertexMain", video::EVST_VS_1_1,
psFileName, "pixelMain", video::EPST_PS_1_1,
mc, video::EMT_SOLID);
}
else
{
toonshader = gpu->addShaderMaterialFromFiles(vsFileName,
psFileName, mc, video::EMT_SOLID);
}
mc->drop();
}
//==============================================================================
IAnimatedMesh* mesh = smgr->getMesh("models/goku.3ds");
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, true);
node->setMaterialTexture( 0, driver->getTexture("models/TW_GOKU.JPG") );
node->setMaterialTexture( 3, driver->getTexture("data/toonshader.bmp") );
node->setMaterialType((video::E_MATERIAL_TYPE)toonshader);
}