# How to create a fog effect in XNA with PixelShaderFunction?

I developped a small XNA games in 3D. I would like to add a "fog of war" on my models instantiated with an effect in my (.fx) file. The problem is, I do not know how to change the function "PixelShaderFunction".

File [.fx]

Here is the declaration of my variables in my effect file (.fx):

// InstancedModel.fx
//
// Microsoft XNA Community Game Platform
//-----------------------------------------------------------------------------

// Camera settings.
float4x4 World;
float4x4 View;
float4x4 Projection;

//Fog settings
float FogNear;
float FogFar;
float4 FogColor;


And my function "PixelShaderFunction" in my effect file (.fx):

// Both techniques share this same pixel shader.
{
return tex2D(Sampler, input.TextureCoordinate) * input.Color;
}

• What do you mean "fog of war"? Is it about putting fog where there are no units in a strategy game? or about 3D fog where things get fainter as they get farther from the point of view? – Panda Pajama Mar 14 '13 at 13:25
• i think about the 3D fog where things get fainter as they get farther from the point of view – Mehdi Bugnard Mar 14 '13 at 13:52
• You made the exact same question, and you even accepted it. If you got your question solved, why did you make a new one? gamedev.stackexchange.com/questions/50905 – Panda Pajama Mar 14 '13 at 13:58
• Because the old answer was correct! I asked how to apply a fog of war! Now I wonder how to create a function in my file PixelToShader. fx – Mehdi Bugnard Mar 14 '13 at 14:08
• And anyway I can not delete because someone called attention to a moderator ...super – Mehdi Bugnard Mar 14 '13 at 14:10