paysages3d/src/render/opengl/shaders/water.frag

39 lines
1.1 KiB
GLSL
Raw Normal View History

2013-12-24 10:48:06 +00:00
uniform vec4 waterColor;
uniform float waterReflection;
2013-12-24 10:48:06 +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-21 20:41:15 +00:00
vec3 normal = noiseNormal2d(unprojected.xz, 0.001);
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
}