Im using hlsl code from a forum that makes textures splatting on my terrain (i use a directx engine, irrlicht). Now i need fog but im a bit confused on how to add it.
I look at examples like this one:
http://communistgame...og-in-hlsl.html
But im still confused on how to add this to my own shader code I already have. I have figured out i can scale the color of the entire terrain by multiplying the diffuse-color I return in the PS_OUTPUT ps_main(in VS_OUTPUT input) function but dont understand how the shader code can use/know the actual distance from the camera (this is needed to do fog right?). Linear fog is fine for now.
The output function i have now is
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(TextureFour, mul(input.tex, texScale));
vector j = tex2D(TextureFive, mul(input.tex, texScale));
vector k = tex2D(TextureSix, 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;
output.diffuse = n;
return output;
}
Thankful for any help
Erik