Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------

// 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.
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
    return tex2D(Sampler, input.TextureCoordinate) * input.Color;
}
share|improve this question
    
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

1 Answer 1

up vote 1 down vote accepted

You could take a look in XNA's BasicEffect shader source and see how they have implemented Fog support there.

The source code is available here.

share|improve this answer
    
Yes I know it is much easier to integrate a fog with class "BasicEffect". However, for other special reasons, I have to use the class "Effect" with a file. "Fx". Because I use an importer of special model for the technique "Model Instancing".And your link does not work for info ... ^ ^ –  Mehdi Bugnard Mar 14 '13 at 12:58
    
I understand that there might be numerous reasons to use your own custom shader instead of BasicEffect. The link I provided contains a downloadable zip which contains all XNA stock effect files in their raw HLSL format. I suggested that it might be a good starting point to look how they have implemented Fog effect. I cannot help other than that as I am not that familiar with Fog effect principles myself. –  J2V Mar 14 '13 at 13:21
    
Ok thank you. It's already help me a lot. However I do not see where is your link .. The link mentioned above does not work. (dead link?) –  Mehdi Bugnard Mar 14 '13 at 13:55
    
I wonder why the link didn't work ... anyway, I have changed it so it points to direct download link of the sample (hope it isn't against the rules). Let me know if there are still problems. –  J2V Mar 14 '13 at 14:02
    
Super. Thank you very much! Everything works perfectly now. Vai I take a look at these data. And I come back to keep you informed ;-). –  Mehdi Bugnard Mar 14 '13 at 14:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.