2014-04-24 07:37:41 +00:00
|
|
|
// -*-C++-*-
|
|
|
|
|
|
|
|
// Ambient term comes in gl_Color.rgb.
|
|
|
|
#version 120
|
|
|
|
|
|
|
|
varying vec4 diffuse_term;
|
|
|
|
varying vec3 normal;
|
|
|
|
varying vec3 ecViewDir;
|
|
|
|
varying vec3 VTangent;
|
|
|
|
|
2016-11-17 18:54:32 +00:00
|
|
|
uniform float shade_effect;
|
|
|
|
uniform float sun_angle;
|
|
|
|
uniform float air_pollution;
|
|
|
|
|
2015-03-29 10:16:19 +00:00
|
|
|
uniform bool use_overlay;
|
2016-11-17 18:54:32 +00:00
|
|
|
uniform bool use_cloud_normals;
|
2014-04-24 07:37:41 +00:00
|
|
|
|
|
|
|
uniform sampler2D texture;
|
2015-03-29 10:16:19 +00:00
|
|
|
uniform sampler2D structure_texture;
|
2014-04-24 07:37:41 +00:00
|
|
|
|
2015-04-18 06:29:04 +00:00
|
|
|
float Noise2D(in vec2 coord, in float wavelength);
|
2016-11-17 18:54:32 +00:00
|
|
|
vec3 filter_combined (in vec3 color) ;
|
|
|
|
|
|
|
|
|
|
|
|
float add_cosines (in float cos1, in float cos2, in float sign)
|
|
|
|
{
|
|
|
|
|
|
|
|
float sin1 = sqrt(1.0 - pow(cos1, 2.0));
|
|
|
|
float sin2 = sqrt(1.0 - pow(cos2, 2.0));
|
|
|
|
|
|
|
|
return cos1 * cos2 + sign * sin1 * sin2;
|
|
|
|
|
|
|
|
}
|
2014-04-24 07:37:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
vec3 n;
|
2016-11-17 18:54:32 +00:00
|
|
|
float NdotL, NdotHV, NdotLraw;
|
2014-04-24 07:37:41 +00:00
|
|
|
vec4 color = gl_Color;
|
|
|
|
vec3 lightDir = gl_LightSource[0].position.xyz;
|
|
|
|
|
2016-11-17 18:54:32 +00:00
|
|
|
vec3 halfVector = normalize(normalize(lightDir) + normalize(ecViewDir));
|
2014-04-24 07:37:41 +00:00
|
|
|
vec4 texel;
|
2016-11-17 18:54:32 +00:00
|
|
|
vec4 ref_texel;
|
2015-03-29 10:16:19 +00:00
|
|
|
vec4 structureTexel;
|
2014-04-24 07:37:41 +00:00
|
|
|
|
|
|
|
vec4 fragColor;
|
2016-11-17 18:54:32 +00:00
|
|
|
vec4 specular = vec4(0.0, 0.0, 0.0, 0.0);
|
2014-04-24 07:37:41 +00:00
|
|
|
|
2016-11-17 18:54:32 +00:00
|
|
|
n = normalize(normal);
|
2014-04-24 07:37:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
vec3 light_specular = vec3 (1.0, 1.0, 1.0);
|
2016-11-17 18:54:32 +00:00
|
|
|
NdotL = dot(n, normalize(lightDir));
|
|
|
|
NdotLraw = NdotL;
|
2015-03-29 10:16:19 +00:00
|
|
|
NdotL = smoothstep(-0.2,0.2,NdotL);
|
2014-04-25 06:40:32 +00:00
|
|
|
|
2016-11-17 18:54:32 +00:00
|
|
|
float intensity = length(diffuse_term.rgb);
|
|
|
|
|
|
|
|
vec3 dawn_color = mix (vec3 (1.0,0.7,0.4), vec3 (1.0,0.4,0.2), air_pollution);
|
|
|
|
|
|
|
|
vec3 dawn = intensity * 1.2 * normalize (dawn_color);
|
|
|
|
|
|
|
|
vec4 diff_term = mix(vec4(dawn, 1.0), diffuse_term, smoothstep(0.0, 0.45, NdotL));
|
|
|
|
|
|
|
|
|
|
|
|
vec2 grad_dir = vec2 (1.0, 0.0);
|
|
|
|
|
|
|
|
vec3 tangent = normalize(VTangent);
|
|
|
|
vec3 binormal = cross(n, tangent);
|
|
|
|
float NdotL2 = 0.0;
|
|
|
|
|
|
|
|
if (use_cloud_normals)
|
|
|
|
{
|
|
|
|
vec2 sun2d = vec2 (0.0, 1.0);
|
|
|
|
|
|
|
|
float xOffset = -1.0 * dot(normalize(lightDir), tangent);
|
|
|
|
float yOffset = -1.0 * dot(normalize(lightDir), binormal);
|
|
|
|
|
|
|
|
grad_dir = normalize (vec2 (xOffset, yOffset));
|
|
|
|
|
|
|
|
vec4 comp_texel = texture2D(texture, gl_TexCoord[0].st - 0.0005 * grad_dir);
|
|
|
|
|
|
|
|
float slope = shade_effect * (comp_texel.a - ref_texel.a);
|
|
|
|
float sign = -1.0;
|
|
|
|
if (slope < 0.0) {sign = 1.0;}
|
2014-04-25 06:40:32 +00:00
|
|
|
|
2016-11-17 18:54:32 +00:00
|
|
|
vec2 snormal = normalize(vec2 (slope, 1.0));
|
|
|
|
|
|
|
|
NdotL2 = dot (snormal, sun2d);
|
|
|
|
NdotL = add_cosines(NdotL, NdotL2, sign );
|
|
|
|
}
|
|
|
|
|
|
|
|
color += diff_term * max(NdotL, 0.15) ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
color.rgb *= smoothstep(-0.2, -0.1, NdotLraw);
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-24 07:37:41 +00:00
|
|
|
color.a = diffuse_term.a;
|
|
|
|
color = clamp(color, 0.0, 1.0);
|
|
|
|
texel = texture2D(texture, gl_TexCoord[0].st);
|
2016-11-17 18:54:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ref_texel = texel;
|
2015-03-29 10:16:19 +00:00
|
|
|
structureTexel = texture2D(structure_texture, 20.0 * gl_TexCoord[0].st);
|
2015-04-18 06:29:04 +00:00
|
|
|
|
|
|
|
float noise = Noise2D( gl_TexCoord[0].st, 0.01);
|
|
|
|
noise += Noise2D( gl_TexCoord[0].st, 0.005);
|
|
|
|
noise += Noise2D( gl_TexCoord[0].st, 0.002);
|
|
|
|
|
2016-11-17 18:54:32 +00:00
|
|
|
|
2015-04-18 06:29:04 +00:00
|
|
|
vec4 noiseTexel = vec4 (1.0,1.0,1.0, 0.5* noise * texel.a);
|
|
|
|
structureTexel = mix(structureTexel, noiseTexel,noiseTexel.a);
|
|
|
|
|
|
|
|
|
2016-11-17 18:54:32 +00:00
|
|
|
|
|
|
|
|
2015-04-18 06:29:04 +00:00
|
|
|
if (use_overlay)
|
|
|
|
{
|
2016-11-17 18:54:32 +00:00
|
|
|
texel = vec4(structureTexel.rgb, smoothstep(0.0, 0.5,texel.a) * structureTexel.a);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fragColor = color * texel;
|
|
|
|
fragColor.rgb = filter_combined(fragColor.rgb);
|
|
|
|
|
|
|
|
gl_FragColor = clamp(fragColor, 0.0, 1.0);
|
|
|
|
|
2015-03-29 10:16:19 +00:00
|
|
|
|
2014-04-24 07:37:41 +00:00
|
|
|
}
|