2013-12-24 10:48:06 +00:00
|
|
|
uniform vec4 waterColor;
|
2014-01-05 19:37:51 +00:00
|
|
|
uniform sampler2D simplexSampler;
|
2014-01-05 21:20:15 +00:00
|
|
|
uniform float waterReflection;
|
2013-12-24 10:48:06 +00:00
|
|
|
|
2014-01-05 20:52:09 +00:00
|
|
|
vec4 applyLighting(vec3 location, vec3 normal, vec4 color, float shininess)
|
|
|
|
{
|
|
|
|
// TEMP phong lighting implementation for testing
|
|
|
|
vec3 N = normalize(normal);
|
|
|
|
vec3 L = sunDirection;
|
|
|
|
vec3 E = normalize(cameraLocation - location);
|
|
|
|
vec3 R = normalize(-reflect(L, N));
|
|
|
|
|
|
|
|
//calculate Ambient Term:
|
|
|
|
vec4 Iamb = vec4(0.1, 0.1, 0.1, 1.0);
|
|
|
|
|
|
|
|
//calculate Diffuse Term:
|
|
|
|
vec4 Idiff = vec4(3.0, 3.0, 3.0, 1.0) * color * max(dot(N, L), 0.0);
|
|
|
|
|
|
|
|
// calculate Specular Term:
|
|
|
|
vec4 Ispec = vec4(3.0, 3.0, 3.0, 1.0) * pow(max(dot(R,E),0.0),0.3*shininess);
|
|
|
|
|
|
|
|
// write Total Color:
|
|
|
|
return Iamb + Idiff + Ispec;
|
|
|
|
}
|
|
|
|
|
2013-12-21 23:41:19 +00:00
|
|
|
void main(void)
|
|
|
|
{
|
2014-01-05 20:52:09 +00:00
|
|
|
vec3 normal = vec3(0.0, 0.0, 0.0);
|
2014-01-05 21:20:15 +00:00
|
|
|
for (float scaling = 1.0; scaling < 400.0; scaling *= 1.5)
|
2014-01-05 20:52:09 +00:00
|
|
|
{
|
|
|
|
normal += texture2D(simplexSampler, unprojected.xz * 0.01 * scaling).xyz;
|
|
|
|
}
|
2014-01-05 21:20:15 +00:00
|
|
|
normal = normalize(normal);
|
2014-01-05 20:52:09 +00:00
|
|
|
|
2014-01-05 21:20:15 +00:00
|
|
|
gl_FragColor = applyLighting(unprojected, normal, waterColor, 100.0);
|
|
|
|
|
|
|
|
gl_FragColor += getSkyColor(unprojected, reflect(unprojected - cameraLocation, normal)) * waterReflection;
|
2013-12-22 00:17:57 +00:00
|
|
|
|
2013-12-24 14:00:32 +00:00
|
|
|
gl_FragColor = applyAerialPerspective(gl_FragColor);
|
2013-12-22 00:17:57 +00:00
|
|
|
|
2013-12-24 14:00:32 +00:00
|
|
|
gl_FragColor = applyToneMapping(gl_FragColor);
|
2013-12-22 00:17:57 +00:00
|
|
|
|
2013-12-24 14:00:32 +00:00
|
|
|
gl_FragColor.a = distanceFadeout();
|
2013-12-21 23:41:19 +00:00
|
|
|
}
|