Code: Select all
class MyShaderCallBack : public video::IShaderConstantSetCallBack
{
public:
virtual void OnSetConstants(video::IMaterialRendererServices* services,
s32 userData)
{
video::IVideoDriver* driver = services->getVideoDriver();
// set clip matrix
//core::matrix4 worldViewProj;
//worldViewProj = driver->getTransform(video::ETS_PROJECTION);
//worldViewProj *= driver->getTransform(video::ETS_VIEW);
//worldViewProj *= driver->getTransform(video::ETS_WORLD);
//services->setVertexShaderConstant("mWorldViewProj", worldViewProj.pointer(), 16);
// set camera position
core::vector3df pos_cam = device->getSceneManager()->
getActiveCamera()->getAbsolutePosition();
core::vector3df pos_light = device->getSceneManager()->getSceneNodeFromId(66,0)->getAbsolutePosition();
services->setVertexShaderConstant("fvEyePosition", reinterpret_cast<f32*>(&pos_cam), 3);
services->setVertexShaderConstant("fvLightPosition", reinterpret_cast<f32*>(&pos_light), 3);
// set transposed world matrix
core::matrix4 world = driver->getTransform(video::ETS_WORLD);
world = world.makeInverse();
world = world.getTransposed();
services->setVertexShaderConstant("matWorldInverseTranspose", world.pointer(), 16);
}
};
Code: Select all
//apply the shaders
gpu = driver->getGPUProgrammingServices();
carReflectionMaterial = gpu->addHighLevelShaderMaterialFromFiles("data/shaders/reflection.vert",
"main", EVST_VS_2_0,
"data/shaders/reflection.frag",
"main", EPST_PS_2_0, mc, video::EMT_SPHERE_MAP, 0);
car_chassis_node->setMaterialTexture(0, driver->getTexture(ChassisTexture.c_str()));
car_chassis_node->setMaterialTexture(1, driver->getTexture(ChassisTexture.c_str()));
car_chassis_node->setMaterialType(video::EMT_SOLID_2_LAYER);
car_chassis_node->setMaterialFlag(EMF_LIGHTING, false);
car_body_node->setMaterialTexture(0, driver->getTexture(ChassisTexture.c_str()));
car_body_node->setMaterialType(video::EMT_SOLID);
//car_body_node->setMaterialTexture(1, driver->getTexture(ChassisTexture.c_str()));
//car_body_node->setMaterialType((video::E_MATERIAL_TYPE)carReflectionMaterial);
car_body_node->setMaterialFlag(EMF_LIGHTING, false);
//car_body_node->getMaterial(0).Shininess = 100.0f;