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
}
}
Should one put Fog over a SkyBox as you do with terrain ,If so I need help
Hi all.
Do you put fog over a skybox if so Im having trouble, how do I add the fog, here
is my shader.
Traditional sky-boxes are supposed to be viewed as if they were infinitely far away, so it doesn't make sense to add fog to them.
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.
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement