Update shader to react to global weather conditions
This commit is contained in:
parent
9808ca5616
commit
980c1d7926
1 changed files with 37 additions and 30 deletions
|
@ -7,16 +7,16 @@ 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;
|
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;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
float MixFactor, NdotL, NdotHV, fogFactor, slope, L1, L2, wetness;
|
float MixFactor, NdotL, NdotHV, fogFactor, cover, slope, L1, L2, wetness;
|
||||||
|
|
||||||
vec3 n, lightDir, halfVector;
|
vec3 n, lightDir, halfVector;
|
||||||
vec4 texel, fragColor, color, specular, Noise; // GNoise;
|
vec4 texel, fragColor, color, specular, Noise;
|
||||||
|
|
||||||
lightDir = gl_LightSource[0].position.xyz;
|
lightDir = gl_LightSource[0].position.xyz;
|
||||||
halfVector = gl_LightSource[0].halfVector.xyz;
|
halfVector = gl_LightSource[0].halfVector.xyz;
|
||||||
|
@ -24,14 +24,14 @@ void main()
|
||||||
color = gl_Color;
|
color = gl_Color;
|
||||||
specular = vec4(0.0);
|
specular = vec4(0.0);
|
||||||
|
|
||||||
Noise = texture3D(NoiseTex, RawPos.xyz*0.0011);
|
cover = min(min(min(min(CloudCover0, CloudCover1),CloudCover2),CloudCover3),CloudCover4);
|
||||||
//GNoise = texture3D(NoiseTex, RawPos.xyz*0.00011);
|
|
||||||
|
|
||||||
|
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
|
||||||
//AddedNoise = GNoise.r * GNoise.g * GNoise.b; //Some added Noise to break the evenness on some textures
|
MixFactor *= 300;
|
||||||
MixFactor *= 50.0;
|
MixFactor = clamp(MixFactor, 0.0, 1.0);
|
||||||
L1 = 0.88 - 0.04 * MixFactor; //first transition slope
|
L1 = 0.90 - 0.02 * MixFactor; //first transition slope
|
||||||
L2 = 0.80 + 0.04 * MixFactor; //Second transition slope
|
L2 = 0.78 + 0.04 * MixFactor; //Second transition slope
|
||||||
|
|
||||||
// If gl_Color.a == 0, this is a back-facing polygon and the
|
// If gl_Color.a == 0, this is a back-facing polygon and the
|
||||||
// Vnormal should be reversed.
|
// Vnormal should be reversed.
|
||||||
|
@ -62,22 +62,23 @@ void main()
|
||||||
if (InverseSlope == 0.0) {
|
if (InverseSlope == 0.0) {
|
||||||
//Do we do an intermediate transition
|
//Do we do an intermediate transition
|
||||||
if (Transitions >= 1.5) {
|
if (Transitions >= 1.5) {
|
||||||
if (slope > L1) {
|
if (slope >= L1) {
|
||||||
texel = mix(texture2D(SecondTex, gl_TexCoord[0].st), texture2D(BaseTex, gl_TexCoord[0].st), smoothstep(L1, L1 + 0.003*MixFactor, slope));
|
//texel = mix(texture2D(SecondTex, gl_TexCoord[0].st), texture2D(BaseTex, gl_TexCoord[0].st), smoothstep(L1, L1 + 0.03 * MixFactor, slope));
|
||||||
|
texel = texture2D(BaseTex, gl_TexCoord[0].st);
|
||||||
}
|
}
|
||||||
if (slope > L2 && slope <= L1){
|
if (slope >= L2 && slope < L1){
|
||||||
texel = mix(texture2D(SecondTex, gl_TexCoord[0].st), texture2D(BaseTex, gl_TexCoord[0].st), smoothstep(L2 + 0.01 * MixFactor, L1, slope));
|
texel = mix(texture2D(SecondTex, gl_TexCoord[0].st), texture2D(BaseTex, gl_TexCoord[0].st), smoothstep(L2, L1 - 0.06 * MixFactor, slope));
|
||||||
}
|
}
|
||||||
if (slope <= L2){
|
if (slope < L2){
|
||||||
texel = mix(texture2D(ThirdTex, gl_TexCoord[0].st), texture2D(SecondTex, gl_TexCoord[0].st), smoothstep(L2 - 0.1 * MixFactor, L2, slope));
|
texel = mix(texture2D(ThirdTex, gl_TexCoord[0].st), texture2D(SecondTex, gl_TexCoord[0].st), 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 = texture2D(BaseTex, gl_TexCoord[0].st);
|
texel = texture2D(BaseTex, gl_TexCoord[0].st);
|
||||||
}
|
}
|
||||||
if (slope <= L1) {
|
if (slope < L1) {
|
||||||
texel = mix(texture2D(ThirdTex, gl_TexCoord[0].st), texture2D(BaseTex, gl_TexCoord[0].st), smoothstep(L2 - 0.1 * MixFactor, L1, slope));
|
texel = mix(texture2D(ThirdTex, gl_TexCoord[0].st), texture2D(BaseTex, gl_TexCoord[0].st), smoothstep(L2 - 0.13 * MixFactor, L1, slope));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,22 +86,22 @@ void main()
|
||||||
} 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.16) {
|
if (slope >= L1 + 0.1) {
|
||||||
texel = texture2D(ThirdTex, gl_TexCoord[0].st);
|
texel = texture2D(ThirdTex, gl_TexCoord[0].st);
|
||||||
}
|
}
|
||||||
if (slope > L2 && slope <= L1 + 0.16){
|
if (slope >= L2 && slope < L1 + 0.1){
|
||||||
texel = mix(texture2D(SecondTex, gl_TexCoord[0].st), texture2D(ThirdTex, gl_TexCoord[0].st), smoothstep(L2 + 0.01 * MixFactor, L1, slope));
|
texel = mix(texture2D(SecondTex, gl_TexCoord[0].st), texture2D(ThirdTex, gl_TexCoord[0].st), smoothstep(L2 + 0.06 * MixFactor, L1 + 0.1, slope));
|
||||||
}
|
}
|
||||||
if (slope <= L2){
|
if (slope <= L2){
|
||||||
texel = mix(texture2D(BaseTex, gl_TexCoord[0].st), texture2D(SecondTex, gl_TexCoord[0].st), smoothstep(L2 - 0.05 * MixFactor, L2, slope));
|
texel = mix(texture2D(BaseTex, gl_TexCoord[0].st), texture2D(SecondTex, gl_TexCoord[0].st), 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.16) {
|
if (slope > L1 + 0.1) {
|
||||||
texel = texture2D(ThirdTex, gl_TexCoord[0].st);
|
texel = texture2D(ThirdTex, gl_TexCoord[0].st);
|
||||||
}
|
}
|
||||||
if (slope <= L1 + 0.16){
|
if (slope <= L1 + 0.1){
|
||||||
texel = mix(texture2D(BaseTex, gl_TexCoord[0].st), texture2D(ThirdTex, gl_TexCoord[0].st), smoothstep(L2 - 0.05 * MixFactor, L1 + 0.16, slope));
|
texel = mix(texture2D(BaseTex, gl_TexCoord[0].st), texture2D(ThirdTex, gl_TexCoord[0].st), smoothstep(L2 - 0.06 * MixFactor, L1 + 0.1, slope));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,17 +109,23 @@ void main()
|
||||||
//darken textures with wetness
|
//darken textures with wetness
|
||||||
wetness = 1.0 - 0.3 * RainNorm;
|
wetness = 1.0 - 0.3 * RainNorm;
|
||||||
texel.rgb = texel.rgb * wetness;
|
texel.rgb = texel.rgb * wetness;
|
||||||
//texel.r = texel.r * wetness;
|
|
||||||
//texel.g = texel.g * wetness;
|
|
||||||
//texel.b = texel.b * wetness;
|
|
||||||
|
|
||||||
//Snow texture for areas higher than SnowLevel
|
//Snow texture for areas higher than SnowLevel
|
||||||
if (RawPos.z >= SnowLevel - 6000.0 * MixFactor && slope > L2 - 0.4) {
|
if (RawPos.z >= SnowLevel - (1000.0 * slope + 300 * MixFactor) && slope > L2 - 0.12) {
|
||||||
texel = mix(texel, mix(texel, texture2D(SnowTex, gl_TexCoord[0].st), smoothstep(L2 - 0.4 * MixFactor, L2, slope)), smoothstep(SnowLevel - 6000.0 * slope * MixFactor, SnowLevel - 1400.0 * slope * MixFactor, RawPos.z));
|
texel = mix(texel, mix(texel, texture2D(SnowTex, gl_TexCoord[0].st * 2), 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){
|
||||||
|
fragColor.rgb = fragColor.rgb * 1.2;
|
||||||
|
} else {
|
||||||
|
fragColor.rg = fragColor.rg * (0.6 + 0.2 * cover);
|
||||||
|
fragColor.b = fragColor.b * (0.5 + 0.25 * cover);
|
||||||
|
}
|
||||||
|
|
||||||
fogFactor = exp(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord);
|
fogFactor = exp(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord);
|
||||||
gl_FragColor = mix(gl_Fog.color, fragColor, fogFactor);
|
gl_FragColor = mix(gl_Fog.color, fragColor, fogFactor);
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue