fog
//Note the below code is for 3.0 and 3.1 where there is no fog yet as of 12/23/2013. This is a way to simulate fog. Thanks to shadmar for the code.
//If you want to hack in your own fog, add this to the bottom of all fragment shaders you use just before } to add fog.
//Original post: http://www.leadwerks.com/werkspace/topic/7624-still-no-fog/#entry60931
 
vec4 fog=vec4(1,1,1,0.05); // R,G,B,strength
#define LOG2 1.442695
float z = gl_FragCoord.z / gl_FragCoord.w;
float fogFactor = clamp(exp2(-fog.w*fog.w*z*z*LOG2),0.0,1.0);
gl_FragColor = mix(vec4(fog.xyz,1.0), gl_FragColor, fogFactor);
 
//For terrain :
//terrain.shader, just before     gl_FragData[0] = outcolor; add :
 
vec4 fog=vec4(1,1,1,0.05); // R,G,B,strength
#define LOG2 1.442695
float z = gl_FragCoord.z / gl_FragCoord.w;
float fogFactor = clamp(exp2(-fog.w*fog.w*z*z*LOG2),0.0,1.0);
outcolor = mix(vec4(fog.xyz,1.0), outcolor, fogFactor);
 
//A more elegant way would be to add vec4 fog as a uniform and send color and density from your app using SetVec4
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License