/*
 * (C) Copyright Ian D. Romanick 2007
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * on the rights to use, copy, modify, merge, publish, distribute, sub
 * license, and/or sell copies of the Software, and to permit persons to whom
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
 * AUTHORS, COPYRIGHT HOLDERS, AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

varying vec3 light_dir;
varying vec3 eye_dir;

uniform vec3 amb_color;

#if defined(lit_shader)
	void main(void)
	{
		vec3 n = vec3(0.0, 0.0, 1.0);
		vec3 r = reflect(-normalize(eye_dir), n);
		vec3 l = normalize(light_dir);
		vec3 specular_color = vec3(1.0, 1.0, 1.0);

		float shininess = 8.0;

		float Ks = pow(max(dot(r, l), 0.0), shininess);
		float Kd =     max(dot(n, l), 0.0);

		vec3 lit_color = (Kd > 0.0) 
			? Ks * specular_color + Kd * gl_Color.rgb + amb_color
			: amb_color;
		gl_FragColor = vec4(lit_color, gl_Color.a);
	}
#endif //lit_shader

#if defined(amb_shader)
	void main(void)
	{
		gl_FragColor = vec4(amb_color, gl_Color.a);
	}
#endif //amb_shader