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;
|
|
|
|
|
|
|
|
uniform float visibility;
|
2014-04-25 06:40:32 +00:00
|
|
|
uniform bool use_clouds;
|
2014-05-05 12:27:32 +00:00
|
|
|
uniform bool use_cloud_shadows;
|
2015-03-29 10:16:19 +00:00
|
|
|
uniform bool use_overlay;
|
2014-04-24 07:37:41 +00:00
|
|
|
uniform sampler2D texture;
|
|
|
|
uniform sampler2D shadowtex;
|
2015-03-29 10:16:19 +00:00
|
|
|
uniform sampler2D grain_texture;
|
2014-04-24 07:37:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float luminance(vec3 color)
|
|
|
|
{
|
|
|
|
return dot(vec3(0.212671, 0.715160, 0.072169), color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
vec3 n;
|
|
|
|
float NdotL, NdotHV;
|
|
|
|
vec4 color = gl_Color;
|
|
|
|
vec3 lightDir = gl_LightSource[0].position.xyz;
|
2015-03-29 10:16:19 +00:00
|
|
|
|
2014-04-24 07:37:41 +00:00
|
|
|
vec3 halfVector = normalize(normalize(lightDir) + normalize(ecViewDir));
|
|
|
|
vec4 texel;
|
2015-03-29 10:16:19 +00:00
|
|
|
vec4 shadowTexel;
|
|
|
|
vec4 grainTexel;
|
2014-04-24 07:37:41 +00:00
|
|
|
vec4 fragColor;
|
|
|
|
vec4 specular = vec4(0.0);
|
|
|
|
|
|
|
|
// If gl_Color.a == 0, this is a back-facing polygon and the
|
|
|
|
// normal should be reversed.
|
|
|
|
n = (2.0 * gl_Color.a - 1.0) * normal;
|
|
|
|
n = normalize(n);
|
|
|
|
|
|
|
|
vec3 VBinormal;
|
|
|
|
VBinormal = cross(normal, VTangent);
|
|
|
|
|
|
|
|
float xOffset = -0.005 * dot(normalize(lightDir), normalize(VTangent));
|
|
|
|
float yOffset = -0.005 * dot(normalize(lightDir), normalize(VBinormal));
|
|
|
|
|
2014-05-05 12:27:32 +00:00
|
|
|
if ((use_cloud_shadows)&&(use_clouds))
|
2014-04-25 06:40:32 +00:00
|
|
|
{shadowTexel = texture2D(shadowtex, vec2(gl_TexCoord[0].s-xOffset, gl_TexCoord[0].t-yOffset));}
|
|
|
|
else
|
2014-05-05 12:27:32 +00:00
|
|
|
{shadowTexel = vec4 (0.0,0.0,0.0,0.0);}
|
|
|
|
|
2014-04-25 06:40:32 +00:00
|
|
|
texel = texture2D(texture, gl_TexCoord[0].st);
|
2015-03-29 10:16:19 +00:00
|
|
|
grainTexel = texture2D(grain_texture, gl_TexCoord[0].st * 40.0);
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-24 07:37:41 +00:00
|
|
|
|
|
|
|
vec3 light_specular = vec3 (1.0, 1.0, 1.0);
|
|
|
|
NdotL = dot(n, lightDir);
|
2015-03-29 10:16:19 +00:00
|
|
|
// due to atmosphere scattering, we should make this harder
|
|
|
|
NdotL = smoothstep(-0.2,0.2,NdotL);
|
|
|
|
|
2014-04-25 06:40:32 +00:00
|
|
|
float intensity = length(diffuse_term);
|
|
|
|
vec4 dawn = intensity * normalize (vec4 (1.0,0.4,0.4,1.0));
|
|
|
|
vec4 diff_term = mix(dawn, diffuse_term, smoothstep(0.0, 0.2, NdotL));
|
|
|
|
|
|
|
|
intensity = length(light_specular);
|
|
|
|
light_specular = mix(dawn.rgb, light_specular, smoothstep(0.0, 0.2, NdotL));
|
2015-03-29 10:16:19 +00:00
|
|
|
|
|
|
|
float oceanness = smoothstep(0.0, 0.1,length(texel.rgb - vec3 (0.007,0.019, 0.078)));
|
|
|
|
float specular_enhancement = 4.0 * (1.0 - oceanness);
|
2014-04-25 06:40:32 +00:00
|
|
|
|
2015-03-29 10:16:19 +00:00
|
|
|
if (use_overlay) {texel.rgb = mix(texel.rgb, grainTexel.rgb, 0.4* grainTexel.a * oceanness);}
|
2014-04-25 06:40:32 +00:00
|
|
|
|
2014-04-24 07:37:41 +00:00
|
|
|
if (NdotL > 0.0) {
|
|
|
|
color += diffuse_term * NdotL * (1.0-shadowTexel.a);
|
|
|
|
NdotHV = max(dot(n, halfVector), 0.0);
|
|
|
|
if (gl_FrontMaterial.shininess > 0.0)
|
2014-04-25 06:40:32 +00:00
|
|
|
specular.rgb = (gl_FrontMaterial.specular.rgb * specular_enhancement
|
2014-04-24 07:37:41 +00:00
|
|
|
* light_specular * (1.0-shadowTexel.a)
|
|
|
|
* pow(NdotHV, gl_FrontMaterial.shininess));
|
|
|
|
}
|
|
|
|
color.a = diffuse_term.a;
|
|
|
|
// This shouldn't be necessary, but our lighting becomes very
|
|
|
|
// saturated. Clamping the color before modulating by the texture
|
|
|
|
// is closer to what the OpenGL fixed function pipeline does.
|
|
|
|
color = clamp(color, 0.0, 1.0);
|
2014-04-25 06:40:32 +00:00
|
|
|
|
2014-04-24 07:37:41 +00:00
|
|
|
fragColor = color * texel + specular;
|
|
|
|
//fragColor = fragColor * (1.0 - 0.5 * shadowTexel.a);
|
|
|
|
//fragColor = mix(fragColor, shadowTexel, shadowTexel.a);
|
|
|
|
|
|
|
|
float angle = dot(normalize(ecViewDir), normalize(normal));
|
|
|
|
float distance_through_atmosphere = 10.0 / ((angle)+0.001);
|
|
|
|
|
2015-03-29 10:16:19 +00:00
|
|
|
vec4 fogColor = vec4 (0.83,0.9,1.0,1.0) * clamp(length(diffuse_term.rgb/1.73 * clamp(NdotL,0.01, 0.99)),0.0,1.0);
|
2014-04-24 07:37:41 +00:00
|
|
|
//float visibility = 80.0;
|
|
|
|
float fogFactor = exp(-distance_through_atmosphere/(visibility/1000.0));
|
|
|
|
|
|
|
|
fragColor = mix(fogColor, fragColor, fogFactor);
|
|
|
|
|
|
|
|
gl_FragColor = fragColor;
|
|
|
|
}
|