aboutsummaryrefslogtreecommitdiff
path: root/data/light-pp.frag
blob: c40b302ebb158e12d28e0ad01862906ba612b26e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * light-pp.frag
 *
 * Lighting per pixel
 *
 * (c) 2007 Thomas White <taw27@cam.ac.uk>
 *
 *  dtr - Diffraction Tomography Reconstruction
 *
 */

varying vec3 col_ambi;
varying vec3 col_diff;
varying vec3 col_spec;
varying vec3 col_emit;
varying float shininess;

varying vec3 normal;
varying vec3 lightvc;
varying vec3 lighthvc;

void main() {
	
	vec3 ambi;
	vec3 emit;
	vec3 diff;
	vec3 spec;
	
	vec3 norm = normalize(normal);
	
	/* Ambient contribution */
	ambi = col_ambi * gl_LightModel.ambient.rgb;
	
	/* Emission */
	emit = col_emit;
	
	/* Diffuse contribution */
	diff = col_diff * gl_LightSource[0].diffuse.rgb * max(dot(normalize(lightvc).xyz, norm), 0.0);
	
	/* Specular contribution */
	if ( col_spec.r > 0.0 ) {
		float ndothv = max(dot(norm, normalize(lighthvc)), 0.0);
		spec = col_spec * gl_LightSource[0].specular.rgb * pow(ndothv, shininess);
	}
	
	gl_FragColor = vec4(min(emit.r + ambi.r + diff.r + spec.r, 1.0),
			    min(emit.g + ambi.g + diff.g + spec.g, 1.0),
			    min(emit.b + ambi.b + diff.b + spec.b, 1.0),
			    1.0);
	
}