Standardized fog
Signed-off-by: Vivian Meazza <vivian.meazza@lineone.net>
This commit is contained in:
parent
eec1b7626a
commit
4f4a918064
2 changed files with 86 additions and 74 deletions
|
@ -1,19 +1,25 @@
|
||||||
// -*-C++-*-
|
// -*-C++-*-
|
||||||
// Texture switching based on face slope and snow level,with ideas from crop.frag, forest.frag
|
// Texture switching based on face slope and snow level
|
||||||
// © 2011 - Frederic Bouvier, Emilian Huminiuc, Tim Moore, Yves Sablonier
|
// based on earlier work by Frederic Bouvier, Tim Moore, and Yves Sablonier.
|
||||||
|
// © Emilian Huminiuc 2011
|
||||||
|
|
||||||
// Ambient term comes in gl_Color.rgb.
|
// Ambient term comes in gl_Color.rgb.
|
||||||
#version 120
|
|
||||||
varying vec4 diffuse_term, RawPos;
|
varying vec4 diffuse_term, RawPos;
|
||||||
varying vec3 Vnormal, normal;
|
varying vec3 Vnormal, normal;
|
||||||
varying float fogCoord;
|
//varying float fogCoord;
|
||||||
|
|
||||||
uniform float SnowLevel, Transitions, InverseSlope, RainNorm, CloudCover0, CloudCover1, CloudCover2, CloudCover3, CloudCover4;
|
uniform float SnowLevel, Transitions, InverseSlope, RainNorm, CloudCover0, CloudCover1, CloudCover2, CloudCover3, CloudCover4;
|
||||||
uniform sampler2D BaseTex, SecondTex, ThirdTex, SnowTex;
|
uniform sampler2D BaseTex, SecondTex, ThirdTex, SnowTex;
|
||||||
uniform sampler3D NoiseTex;
|
uniform sampler3D NoiseTex;
|
||||||
|
|
||||||
|
////fog "include" /////
|
||||||
|
uniform int fogType;
|
||||||
|
|
||||||
|
vec3 fog_Func(vec3 color, int type);
|
||||||
|
//////////////////////
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
float MixFactor, NdotL, NdotHV, fogFactor, cover, slope, L1, L2, wetness;
|
float MixFactor, NdotL, NdotHV, fogFactor, cover, slope, L1, L2, wetness;
|
||||||
|
|
||||||
vec3 n, lightDir, halfVector;
|
vec3 n, lightDir, halfVector;
|
||||||
|
@ -29,7 +35,7 @@ void main()
|
||||||
|
|
||||||
Noise = texture3D(NoiseTex, RawPos.xyz*0.0011);
|
Noise = texture3D(NoiseTex, RawPos.xyz*0.0011);
|
||||||
MixFactor = Noise.r * Noise.g * Noise.b; //Mixing Factor to create a more organic looking boundary
|
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);
|
MixFactor = clamp(MixFactor, 0.0, 1.0);
|
||||||
L1 = 0.90 - 0.02 * MixFactor; //first transition slope
|
L1 = 0.90 - 0.02 * MixFactor; //first transition slope
|
||||||
L2 = 0.78 + 0.04 * MixFactor; //Second transition slope
|
L2 = 0.78 + 0.04 * MixFactor; //Second transition slope
|
||||||
|
@ -47,7 +53,7 @@ void main()
|
||||||
specular.rgb = (gl_FrontMaterial.specular.rgb
|
specular.rgb = (gl_FrontMaterial.specular.rgb
|
||||||
* gl_LightSource[0].specular.rgb
|
* gl_LightSource[0].specular.rgb
|
||||||
* pow(NdotHV, gl_FrontMaterial.shininess));
|
* pow(NdotHV, gl_FrontMaterial.shininess));
|
||||||
}
|
}
|
||||||
|
|
||||||
color.a = diffuse_term.a;
|
color.a = diffuse_term.a;
|
||||||
// This shouldn't be necessary, but our lighting becomes very
|
// This shouldn't be necessary, but our lighting becomes very
|
||||||
|
@ -63,7 +69,7 @@ void main()
|
||||||
vec4 baseTexel = texture2D(BaseTex, gl_TexCoord[0].st);
|
vec4 baseTexel = texture2D(BaseTex, gl_TexCoord[0].st);
|
||||||
vec4 secondTexel = texture2D(SecondTex, gl_TexCoord[0].st);
|
vec4 secondTexel = texture2D(SecondTex, gl_TexCoord[0].st);
|
||||||
vec4 thirdTexel = texture2D(ThirdTex, 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).
|
//Normal transition. For more abrupt faces apply another texture (or 2).
|
||||||
if (InverseSlope == 0.0) {
|
if (InverseSlope == 0.0) {
|
||||||
//Do we do an intermediate transition
|
//Do we do an intermediate transition
|
||||||
|
@ -71,46 +77,46 @@ void main()
|
||||||
if (slope >= L1) {
|
if (slope >= L1) {
|
||||||
//texel = mix(texture2D(SecondTex, gl_TexCoord[0].st), texture2D(BaseTex, gl_TexCoord[0].st), smoothstep(L1, L1 + 0.03 * MixFactor, slope));
|
//texel = mix(texture2D(SecondTex, gl_TexCoord[0].st), texture2D(BaseTex, gl_TexCoord[0].st), smoothstep(L1, L1 + 0.03 * MixFactor, slope));
|
||||||
texel = baseTexel;
|
texel = baseTexel;
|
||||||
}
|
}
|
||||||
if (slope >= L2 && slope < L1){
|
if (slope >= L2 && slope < L1){
|
||||||
texel = mix(secondTexel, baseTexel, smoothstep(L2, L1 - 0.06 * MixFactor, slope));
|
texel = mix(secondTexel, baseTexel, smoothstep(L2, L1 - 0.06 * MixFactor, slope));
|
||||||
}
|
}
|
||||||
if (slope < L2){
|
if (slope < L2){
|
||||||
texel = mix(thirdTexel, secondTexel, smoothstep(L2 - 0.13 * MixFactor, L2, slope));
|
texel = mix(thirdTexel, secondTexel, smoothstep(L2 - 0.13 * MixFactor, L2, slope));
|
||||||
}
|
}
|
||||||
// Just one transition
|
// Just one transition
|
||||||
} else if (Transitions < 1.5) {
|
} else if (Transitions < 1.5) {
|
||||||
if (slope >= L1) {
|
if (slope >= L1) {
|
||||||
texel = baseTexel;
|
texel = baseTexel;
|
||||||
|
}
|
||||||
|
if (slope < L1) {
|
||||||
|
texel = mix(thirdTexel, baseTexel, smoothstep(L2 - 0.13 * MixFactor, L1, slope));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (slope < L1) {
|
|
||||||
texel = mix(thirdTexel, baseTexel, smoothstep(L2 - 0.13 * MixFactor, L1, slope));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Invert the transition: keep original texture on abrupt slopes and switch to another on flatter terrain
|
//Invert the transition: keep original texture on abrupt slopes and switch to another on flatter terrain
|
||||||
} else if (InverseSlope > 0.0) {
|
} else if (InverseSlope > 0.0) {
|
||||||
//Interemdiate transition ?
|
//Interemdiate transition ?
|
||||||
if (Transitions >= 1.5) {
|
if (Transitions >= 1.5) {
|
||||||
if (slope >= L1 + 0.1) {
|
if (slope >= L1 + 0.1) {
|
||||||
texel = thirdTexel;
|
texel = thirdTexel;
|
||||||
}
|
}
|
||||||
if (slope >= L2 && slope < L1 + 0.1){
|
if (slope >= L2 && slope < L1 + 0.1){
|
||||||
texel = mix(secondTexel, thirdTexel, smoothstep(L2 + 0.06 * MixFactor, L1 + 0.1, slope));
|
texel = mix(secondTexel, thirdTexel, smoothstep(L2 + 0.06 * MixFactor, L1 + 0.1, slope));
|
||||||
}
|
}
|
||||||
if (slope <= L2){
|
if (slope <= L2){
|
||||||
texel = mix(baseTexel, secondTexel, smoothstep(L2 - 0.06 * MixFactor, L2, slope));
|
texel = mix(baseTexel, secondTexel, smoothstep(L2 - 0.06 * MixFactor, L2, slope));
|
||||||
}
|
}
|
||||||
//just one
|
//just one
|
||||||
} else if (Transitions < 1.5) {
|
} else if (Transitions < 1.5) {
|
||||||
if (slope > L1 + 0.1) {
|
if (slope > L1 + 0.1) {
|
||||||
texel = thirdTexel;
|
texel = thirdTexel;
|
||||||
}
|
}
|
||||||
if (slope <= L1 + 0.1){
|
if (slope <= L1 + 0.1){
|
||||||
texel = mix(baseTexel, thirdTexel, smoothstep(L2 - 0.06 * MixFactor, L1 + 0.1, slope));
|
texel = mix(baseTexel, thirdTexel, smoothstep(L2 - 0.06 * MixFactor, L1 + 0.1, slope));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//darken textures with wetness
|
//darken textures with wetness
|
||||||
wetness = 1.0 - 0.3 * RainNorm;
|
wetness = 1.0 - 0.3 * RainNorm;
|
||||||
|
@ -121,20 +127,19 @@ void main()
|
||||||
//Snow texture for areas higher than SnowLevel
|
//Snow texture for areas higher than SnowLevel
|
||||||
if (RawPos.z >= SnowLevel - (1000.0 * slope + 300 * MixFactor) && slope > L2 - 0.12) {
|
if (RawPos.z >= SnowLevel - (1000.0 * slope + 300 * MixFactor) && slope > L2 - 0.12) {
|
||||||
texel = mix(texel, mix(texel, snowTexel, smoothstep(L2 - 0.09 * MixFactor, L2, slope)), smoothstep(SnowLevel - (1000.0 * slope + 300 * MixFactor), SnowLevel - (1000 * slope - 150 * MixFactor), RawPos.z));
|
texel = mix(texel, mix(texel, snowTexel, smoothstep(L2 - 0.09 * MixFactor, L2, slope)), smoothstep(SnowLevel - (1000.0 * slope + 300 * MixFactor), SnowLevel - (1000 * slope - 150 * MixFactor), RawPos.z));
|
||||||
}
|
}
|
||||||
|
|
||||||
fragColor = color * texel + specular;
|
fragColor = color * texel + specular;
|
||||||
|
|
||||||
if(cover >= 2.5){
|
if(cover >= 2.5){
|
||||||
fragColor.rgb = fragColor.rgb * 1.2;
|
fragColor.rgb = fragColor.rgb * 1.2;
|
||||||
} else {
|
} else {
|
||||||
fragColor.rg = fragColor.rg * (0.6 + 0.2 * cover);
|
fragColor.rg = fragColor.rg * (0.6 + 0.2 * cover);
|
||||||
fragColor.b = fragColor.b * (0.5 + 0.25 * cover);
|
fragColor.b = fragColor.b * (0.5 + 0.25 * cover);
|
||||||
|
}
|
||||||
|
|
||||||
|
//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;
|
||||||
}
|
}
|
||||||
|
|
||||||
fogFactor = exp(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord);
|
|
||||||
gl_FragColor = mix(gl_Fog.color, fragColor, fogFactor);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,13 +19,19 @@
|
||||||
// bugs with gl_FrontFacing in the fragment shader.
|
// bugs with gl_FrontFacing in the fragment shader.
|
||||||
varying vec4 diffuse_term, RawPos;
|
varying vec4 diffuse_term, RawPos;
|
||||||
varying vec3 normal, Vnormal;
|
varying vec3 normal, Vnormal;
|
||||||
varying float fogCoord;
|
//varying float fogCoord;
|
||||||
uniform int colorMode;
|
uniform int colorMode;
|
||||||
|
|
||||||
|
////fog "include"////////
|
||||||
|
uniform int fogType;
|
||||||
|
|
||||||
|
void fog_Func(int type);
|
||||||
|
/////////////////////////
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
RawPos = gl_Vertex;
|
RawPos = gl_Vertex;
|
||||||
vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
|
//vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
|
||||||
gl_Position = ftransform();
|
gl_Position = ftransform();
|
||||||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||||||
normal = normalize(gl_Normal);
|
normal = normalize(gl_Normal);
|
||||||
|
@ -34,25 +40,26 @@ void main()
|
||||||
if (colorMode == MODE_DIFFUSE) {
|
if (colorMode == MODE_DIFFUSE) {
|
||||||
diffuse_color = gl_Color;
|
diffuse_color = gl_Color;
|
||||||
ambient_color = gl_FrontMaterial.ambient;
|
ambient_color = gl_FrontMaterial.ambient;
|
||||||
} else if (colorMode == MODE_AMBIENT_AND_DIFFUSE) {
|
} else if (colorMode == MODE_AMBIENT_AND_DIFFUSE) {
|
||||||
diffuse_color = gl_Color;
|
diffuse_color = gl_Color;
|
||||||
ambient_color = gl_Color;
|
ambient_color = gl_Color;
|
||||||
} else {
|
} else {
|
||||||
diffuse_color = gl_FrontMaterial.diffuse;
|
diffuse_color = gl_FrontMaterial.diffuse;
|
||||||
ambient_color = gl_FrontMaterial.ambient;
|
ambient_color = gl_FrontMaterial.ambient;
|
||||||
|
}
|
||||||
|
diffuse_term = diffuse_color * gl_LightSource[0].diffuse;
|
||||||
|
vec4 constant_term = gl_FrontMaterial.emission + ambient_color *
|
||||||
|
(gl_LightModel.ambient + gl_LightSource[0].ambient);
|
||||||
|
// Super hack: if diffuse material alpha is less than 1, assume a
|
||||||
|
// transparency animation is at work
|
||||||
|
if (gl_FrontMaterial.diffuse.a < 1.0)
|
||||||
|
diffuse_term.a = gl_FrontMaterial.diffuse.a;
|
||||||
|
else
|
||||||
|
diffuse_term.a = gl_Color.a;
|
||||||
|
// Another hack for supporting two-sided lighting without using
|
||||||
|
// 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);
|
||||||
|
fog_Func(fogType);
|
||||||
}
|
}
|
||||||
diffuse_term = diffuse_color * gl_LightSource[0].diffuse;
|
|
||||||
vec4 constant_term = gl_FrontMaterial.emission + ambient_color *
|
|
||||||
(gl_LightModel.ambient + gl_LightSource[0].ambient);
|
|
||||||
// Super hack: if diffuse material alpha is less than 1, assume a
|
|
||||||
// transparency animation is at work
|
|
||||||
if (gl_FrontMaterial.diffuse.a < 1.0)
|
|
||||||
diffuse_term.a = gl_FrontMaterial.diffuse.a;
|
|
||||||
else
|
|
||||||
diffuse_term.a = gl_Color.a;
|
|
||||||
// Another hack for supporting two-sided lighting without using
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue