Sign in to follow this  

Should one put Fog over a SkyBox as you do with terrain ,If so I need help

This topic is 3601 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all. Do you put fog over a skybox if so Im having trouble, how do I add the fog, here is my shader.
uniform extern float4x4 gWVP;
uniform extern texture  gEnvMap;
uniform extern float3  gEyePosW;

//FOG INPUTS WILL MAKE IT SO WE SET THE COLOUR
static float3 gFogColor = {1.5f, 0.5f, 0.5f};
static float  gFogStart = 1.0f;
static float  gFogRange = 20.0f;


sampler EnvMapS = sampler_state
{
    Texture   = <gEnvMap>;
    MinFilter = LINEAR; 
    MagFilter = LINEAR;
    MipFilter = LINEAR;
    AddressU  = WRAP;
    AddressV  = WRAP;
};


void SkyVS(float3 posL : POSITION0, 
           out float4 oPosH : POSITION0, 
           out float3 oEnvTex : TEXCOORD0,
	   out float  fogLerpParam : TEXCOORD1)
{
	// Set z = w so that z/w = 1 (i.e., skydome always on far plane).
    	oPosH = mul(float4(posL, 1.0f), gWVP).xyww; 
    
    	// Use skymesh vertex position, in local space, as index into cubemap. 
    	oEnvTex = posL;

	// Compute vertex distance from camera in world space for fog calculation.
	float dist = distance(posL, gEyePosW);
	fogLerpParam = saturate((dist - gFogStart) / gFogRange);

}

float4 SkyPS(float3 envTex : TEXCOORD0,
		float fogLerpParam : TEXCOORD2) : COLOR
{
HERE IS THE AREA
// Add fog.
    float4 tc = texCUBE(EnvMapS, envTex);
	
	
    float3 final = lerp(tc, gFogColor, fogLerpParam);

    float4 ft = float4(final, 1.0f);

    return ft;

    //return texCUBE(EnvMapS, envTex);
}

technique SkyTech
{
    pass P0
    {
        vertexShader = compile vs_2_0 SkyVS();
        pixelShader  = compile ps_2_0 SkyPS();
		CullMode = None;
		ZFunc = Always; // Always write sky to depth buffer
		StencilEnable = true;
		StencilFunc   = Always;
		StencilPass   = Replace;
		StencilRef    = 0; // clear to zero
    }
}



Share this post


Link to post
Share on other sites
I would say yes. Your skybox needs to APPEAR that is is very far away (not actually infinitely far away) which can be approximated by:

reducing the size

increasing the fog (e.g. if your fog factor is 1e-4 and your skybox actual distance is 100 units, but you want it to appear to be 1000 units, set the fog factor to 1e-3.

making it move more slowly (if you want it 10x further away than it actually is, make it move 10x slower. This gives the impression of greater distance.

Share this post


Link to post
Share on other sites
No you shouldn't, at least not for your basic cube-with-sky-texture style skybox.

But, if you do have fog in your game, you need to be aware of this when you make the skybox. If it just contains sky, you're fine.

However, if you've generated a fancy skybox texture with terragen or something similar, with majestic mountains in the background, it will look pants. This is because nearby objects (actual geometry) will look foggy, but distant objects (textured into the skybox) will look sharper. The only way you can avoid this is to ensure that when you generate the skybox texture, you ensure that it is generated with similar fog colour to that used in your game, and strong enough fog to ensure that all the hills and mountains visible in the skybox texture are fully saturated with fog.

Another approach is to have open sky for your skybox texture and attach some simple geometry in the skybox to approximate distant objects such as hills and mountains and whatnot. In that case, the additional geometry wants to be flat shaded and in the same colour as the fog, so distant objects in the game world proper blend seamlessly with the skybox when fog is applied.

Share this post


Link to post
Share on other sites

This topic is 3601 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this