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

43 lines
1.2 KiB
GLSL
Raw Normal View History

2013-12-24 10:48:06 +00:00
uniform vec4 waterColor;
uniform sampler2D simplexSampler;
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)
{
//gl_FragColor = waterColor;
//gl_FragColor = texture2D(simplexSampler, unprojected.xz * 0.01);
vec3 normal = vec3(0.0, 0.0, 0.0);
for (float scaling = 1.0; scaling < 50.0; scaling *= 1.5)
{
normal += texture2D(simplexSampler, unprojected.xz * 0.01 * scaling).xyz;
}
gl_FragColor = applyLighting(unprojected, normalize(normal), waterColor, 100.0);
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
}