2014-11-20 10:52:14 +00:00
|
|
|
|
|
|
|
// Ambient light calculation
|
|
|
|
|
2014-12-28 14:07:42 +00:00
|
|
|
#ifdef HAVE_LIGHT
|
2014-11-20 10:52:14 +00:00
|
|
|
uniform sampler2D ambientTex;
|
|
|
|
|
2014-11-23 21:29:51 +00:00
|
|
|
uniform mat3x2 ambientTransform;
|
2014-11-19 16:18:07 +00:00
|
|
|
uniform float ambientBrightness;
|
2014-12-28 14:07:42 +00:00
|
|
|
#endif
|
2014-11-20 10:52:14 +00:00
|
|
|
|
2014-12-05 01:43:07 +00:00
|
|
|
slice(texture+6)
|
2014-11-20 10:52:14 +00:00
|
|
|
{
|
2014-12-28 14:07:42 +00:00
|
|
|
#ifdef HAVE_LIGHT
|
2014-11-20 10:52:14 +00:00
|
|
|
// Ambient light
|
2014-11-23 21:29:51 +00:00
|
|
|
float ambient = texture2D(ambientTex, ambientTransform * vec3(gl_FragCoord.xy, 1.0)).r * ambientBrightness;
|
2014-12-28 14:07:42 +00:00
|
|
|
#else
|
|
|
|
// Lighting disabled: Ambient light everywhere
|
|
|
|
float ambient = 1.0;
|
|
|
|
#endif
|
2014-11-20 10:52:14 +00:00
|
|
|
}
|
|
|
|
|
2014-12-05 01:43:07 +00:00
|
|
|
slice(light+1)
|
2014-11-20 10:52:14 +00:00
|
|
|
{
|
|
|
|
// Add ambience to brightness
|
2014-11-24 19:50:05 +00:00
|
|
|
#ifdef LANDSCAPE
|
|
|
|
// For landscape, ambient brightness is coming from top
|
2014-11-20 10:52:14 +00:00
|
|
|
vec3 ambientDir = vec3(0.0, -1.0, 0.0);
|
|
|
|
light = mix(light, 1.0 + 1.0 * dot(normal, ambientDir), ambient);
|
|
|
|
#ifdef HAVE_2PX
|
|
|
|
light2 = mix(light2, 1.0 + 1.0 * dot(normal2, ambientDir), ambient);
|
|
|
|
#endif
|
2014-11-24 19:50:05 +00:00
|
|
|
#else
|
|
|
|
// For objects, ambient brightness is coming from the front
|
|
|
|
vec3 ambientDir = vec3(0.0, 0.0, 1.0);
|
|
|
|
light = mix(light, max(dot(normal, ambientDir), 0.0), ambient);
|
|
|
|
#endif
|
2014-11-20 10:52:14 +00:00
|
|
|
}
|