Hello everyone, i am trying to add distance vertex fog to my terrain engine and this is my firs try. I am under the understanding that when using a shader, i still need to set the render state for FOGENABLE and FOGCOLOR and then add the semantic FOG to my vertex shader output and set the value for each vertex from 0 to 1.
However i cant make it work. Here is the relevant code. If anyone see something wrong or missing please tell me, i checked every post concerning vertex fog and i don't see the problem.
This is set just before the terrain draw call which is done with a vertex and pixel shader.
This is the relevant code from my vertex shader.
extern float3 mCamPos;
extern float mMinFogRange;
extern float mMaxFogRange;
float4 Position : POSITION; // vertex position
float4 Diffuse : COLOR0; // vertex diffuse color
float2 Tex0 : TEXCOORD0; // Main patch texture
float2 Tex1 : TEXCOORD1; // Detail texture
float FogFactor : FOG; // Vertex Fog
VS_OUTPUT PatchRender( in float3 pos : POSITION,
uniform int lod,
uniform int2 patchPos)
VS_OUTPUT Output = (VS_OUTPUT)0;
// Fog density
float viewDist = length(Output.Position.rgb - mCamPos);
float fogFactor = (mMaxFogRange - viewDist) / (mMaxFogRange - mMinFogRange);
Output.FogFactor = fogFactor;
And this is the pixel shader afterward. But i believe the pixel shader do not have anything to do with the vertex fog, right?
float4 PatchRenderPS(in VS_OUTPUT IN) : COLOR0
float4 color = tex2D(tex0, IN.Tex0);
return IN.Diffuse * color;
Whatever i do, i never have any fog. I even tried setting the Output.FogFactor in my vertex shader to a fixed 0.5 to see and even there nothing at all. No fog whatsoever. I really do need help
[Edited by - argeze on January 6, 2007 1:27:33 PM]