summaryrefslogtreecommitdiff
path: root/src/phong.frag
blob: 95eaaa7dc49ff7d16c25460b8c30426e3e3abc6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
varying vec4 normal_es;
varying vec4 position_es;

const vec4 diffuse_color = vec4(1.0, 0.0, 0.0, 1.0);
/* Specular exponent.
 */
uniform float s;

/* Position of the light in eye-space.
 */
const vec4 light_es = vec4(0.0, 3.0, 0.0, 1.0);

void main(void)
{
	vec3 l = normalize((light_es - position_es).xyz);
	vec3 v = normalize(-position_es.xyz);
	vec3 h = normalize(l + v);
	float n_dot_l = dot(normal_es.xyz, l);
	vec4 diff = diffuse_color * n_dot_l;
	float spec = pow(dot(normal_es.xyz, h), s);

	gl_FragColor = step(0.0, n_dot_l) * vec4(diff.xyz + vec3(spec), 1.0);
}