aboutsummaryrefslogtreecommitdiff
path: root/data/light-pp.frag
blob: ca969900aa47ae6c3f31738d21e5dfce13aadec1 (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
/*
 * light-pp.frag
 *
 * Lighting per pixel
 *
 * (c) 2007 Thomas White <taw27@cam.ac.uk>
 *
 *  dtr - Diffraction Tomography Reconstruction
 *
 */

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

varying vec3 normal;
varying vec3 halfvc;

void main() {
	
	vec4 ambi;
	vec4 diff;
	vec4 spec;
	
	/* Ambient contribution */
	ambi = col_ambi * gl_LightModel.ambient;
	ambi += col_ambi * gl_LightSource[0].ambient;
	
	/* Diffuse contribution */
	diff = col_diff * clamp(dot( vec3(normalize(gl_LightSource[0].position)), normal ), 0.0, 1.0);
	
	/* Specular contribution */
	spec = col_spec * clamp(pow(dot( vec3(normal), halfvc ), shininess), 0.0, 1.0);
	
	gl_FragColor = vec4(min(col_emit.r + ambi.r + diff.r + spec.r, 1.0),
			    min(col_emit.g + ambi.g + diff.g + spec.g, 1.0),
			    min(col_emit.b + ambi.b + diff.b + spec.b, 1.0),
			    min(col_emit.a + ambi.a + diff.a + spec.a, 1.0));
	
}