fog with shaders

Posted By: zefor

fog with shaders - 01/12/06 23:13

Is there a way to have the shader objects react better with fog. Have them blend into the fog instead of stick out when you are far away from them?
Posted By: Matt_Aufderheide

Re: fog with shaders - 01/13/06 06:04

Sure there is, but it takes a bit of trickery. First of all, this only occurs when you use blend mode like mulitply or additive, and mulitple passes.

Say you have a two pass shader, and the second pass is added to the first. Becasue each pass is fogged seperately, the second pass wi9ll also add the fog color to the first, giving you a lighter overall fog color. The way to deal with this in this case is chnage the fog color for the second pass only, to black.

This is done like this--in your technique, in the second pass, put this line:
fogcolor={0.0,0.0,0.0,0.0};

If that second pass is multiplied, you want the fog color to be white:
fogcolor={1.0,1.0,1.0,1.0};

This may not work if you are using other, non-standard blending modes, but additive and multiply are the ones used in nearly all multi-pass shaders, in whcih the first pass is not blended normally... so this work for nealry all cases where you need normal fogging (such as in multi-pass per-pixel lighting).
Posted By: zefor

Re: fog with shaders - 01/13/06 15:18

So This cant be incoporated into your "bump specular with sun" script?

P.S. How did you get to be so knowledgeable of shaders?
Posted By: Matt_Aufderheide

Re: fog with shaders - 01/13/06 16:08

hmm.. you dont need to use this mehtod with a single pass shader. Simply calculate the normal fog values in that shader...to do this simpoly find this block of code in the vertex shader:
// float ofog = 1 - (distance(PosWorld, vecViewPos) - vecFog.x)*(vecFog.z);
// Out.Fog = ofog;
Out.Fog = 10000;

and just uncomment the first two lines, and comment out this one:
Out.Fog = 10000;

then you should have correct fogging.

About how i learned about shaders: just a lot of work converting other shaders, reading theory, and asking questions. I am by no means an expert, however.
© 2024 lite-C Forums