1
0
Fork 0

Standardized fog

Signed-off-by: Vivian Meazza <vivian.meazza@lineone.net>
This commit is contained in:
Vivian Meazza 2011-12-01 20:58:14 +00:00
parent eec1b7626a
commit 4f4a918064
2 changed files with 86 additions and 74 deletions

View file

@ -1,17 +1,23 @@
// -*-C++-*-
// Texture switching based on face slope and snow level,with ideas from crop.frag, forest.frag
// © 2011 - Frederic Bouvier, Emilian Huminiuc, Tim Moore, Yves Sablonier
// Texture switching based on face slope and snow level
// based on earlier work by Frederic Bouvier, Tim Moore, and Yves Sablonier.
// © Emilian Huminiuc 2011
// Ambient term comes in gl_Color.rgb.
#version 120
varying vec4 diffuse_term, RawPos;
varying vec3 Vnormal, normal;
varying float fogCoord;
//varying float fogCoord;
uniform float SnowLevel, Transitions, InverseSlope, RainNorm, CloudCover0, CloudCover1, CloudCover2, CloudCover3, CloudCover4;
uniform sampler2D BaseTex, SecondTex, ThirdTex, SnowTex;
uniform sampler3D NoiseTex;
////fog "include" /////
uniform int fogType;
vec3 fog_Func(vec3 color, int type);
//////////////////////
void main()
{
float MixFactor, NdotL, NdotHV, fogFactor, cover, slope, L1, L2, wetness;
@ -29,7 +35,7 @@ void main()
Noise = texture3D(NoiseTex, RawPos.xyz*0.0011);
MixFactor = Noise.r * Noise.g * Noise.b; //Mixing Factor to create a more organic looking boundary
MixFactor *= 300.0;
MixFactor *= 300;
MixFactor = clamp(MixFactor, 0.0, 1.0);
L1 = 0.90 - 0.02 * MixFactor; //first transition slope
L2 = 0.78 + 0.04 * MixFactor; //Second transition slope
@ -63,7 +69,7 @@ void main()
vec4 baseTexel = texture2D(BaseTex, gl_TexCoord[0].st);
vec4 secondTexel = texture2D(SecondTex, gl_TexCoord[0].st);
vec4 thirdTexel = texture2D(ThirdTex, gl_TexCoord[0].st);
vec4 snowTexel = texture2D(SnowTex, gl_TexCoord[0].st * 2.0);
vec4 snowTexel = texture2D(SnowTex, gl_TexCoord[0].st * 2);
//Normal transition. For more abrupt faces apply another texture (or 2).
if (InverseSlope == 0.0) {
//Do we do an intermediate transition
@ -132,9 +138,8 @@ void main()
fragColor.b = fragColor.b * (0.5 + 0.25 * cover);
}
fogFactor = exp(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord);
gl_FragColor = mix(gl_Fog.color, fragColor, fogFactor);
//fogFactor = exp(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord);
fragColor.rgb = fog_Func(fragColor.rgb, fogType);
//gl_FragColor = mix(gl_Fog.color, fragColor, fogFactor);
gl_FragColor = fragColor;
}

View file

@ -19,13 +19,19 @@
// bugs with gl_FrontFacing in the fragment shader.
varying vec4 diffuse_term, RawPos;
varying vec3 normal, Vnormal;
varying float fogCoord;
//varying float fogCoord;
uniform int colorMode;
////fog "include"////////
uniform int fogType;
void fog_Func(int type);
/////////////////////////
void main()
{
RawPos = gl_Vertex;
vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
//vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
normal = normalize(gl_Normal);
@ -54,5 +60,6 @@ void main()
// gl_FrontFacing in the fragment shader.
gl_FrontColor.rgb = constant_term.rgb; gl_FrontColor.a = 1.0;
gl_BackColor.rgb = constant_term.rgb; gl_BackColor.a = 0.0;
fogCoord = abs(ecPosition.z / ecPosition.w);
//fogCoord = abs(ecPosition.z / ecPosition.w);
fog_Func(fogType);
}