Hi
Im trying to get fog to work with my custom shader in irrlicht engine. So in c++ i have this
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);
if (UseHighLevelShaders)
services->setVertexShaderConstant("matViewProjection", worldViewProj.pointer(), 16);
else
services->setVertexShaderConstant(worldViewProj.pointer(), 4, 4);
//send camPos
core::vector3df pos = device->getSceneManager()->getActiveCamera()->getAbsolutePosition();
if (UseHighLevelShaders)
services->setPixelShaderConstant("camPos", reinterpret_cast<f32*>(&pos), 3);
else
services->setPixelShaderConstant(reinterpret_cast<f32*>(&pos), 8, 1);
}
};
This should send the position of the cam to the shader. In hlsl i have this at the top of the file
loat3 camPos : register( c0 );
And the pixelshader output function (in hlsl) looks like this
PS_OUTPUT ps_main(in VS_OUTPUT input)
{
float texScale = 1.0;
PS_OUTPUT output = (PS_OUTPUT)0;
vector a = tex2D(AlphaMap, input.alphamap);
vector i = tex2D(TextureOne, mul(input.tex, texScale));
vector j = tex2D(TextureTwo, mul(input.tex, texScale));
vector k = tex2D(TextureThree, mul(input.tex, texScale));
float4 oneminusx = 1.0 - a.x;
float4 oneminusy = 1.0 - a.y;
float4 oneminusz = 1.0 - a.z;
vector l = a.x * i + oneminusx * i;
vector m = a.y * j + oneminusy * l;
vector n = a.z * k + oneminusz * m;
//how to make use of camPos to alter diffuse here?
output.diffuse = n;
return output;
}
It does some splatting for me on the terrain. Now i want to use camPos to make linear fog from real color to some grey starting at 1000 and being full fog at 1300 (lets just say). So i have to modify output.diffuse right? But i dont know how to do that... Plz help in any way you can.
Thanks
Erik