blob: 99e9b37f56a7e74091399a8de103c8a8018a112c (
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
53
54
55
56
57
58
59
60
|
/*
* lighting.vert
*
* Lighting calculations
*
* (c) 2007-2008 Thomas White <taw27@cam.ac.uk>
*
* thrust3d - a silly game
*
*/
varying vec3 normal;
varying vec3 col_ambi_diff;
varying vec3 col_emit;
varying vec3 light0vc;
varying vec3 light0half;
varying float light0dist;
varying vec3 light1vc;
varying vec3 light2vc;
vec3 v4conv3(vec4 a) {
vec4 div = a/(a.w);
return div.xyz;
}
void main() {
vec4 vert;
vec3 vert_to_light;
vec3 vert_to_eye;
vert = gl_ModelViewMatrix * gl_Vertex;
normal = gl_NormalMatrix * gl_Normal;
/* Spotlight - positional light */
vert_to_light = v4conv3(gl_LightSource[0].position - vert);
light0dist = length(vert_to_light);
light0vc = normalize(vert_to_light);
vert_to_eye = v4conv3(-vert);
light0half = normalize(vert_to_eye + vert_to_light);
/* Diffuse "background glow" - this can be normalised only once, here, since 'position'
* is really 'direction' and is the same for all vertices. */
light1vc = normalize(v4conv3(gl_LightSource[1].position));
/* Fill-in light */
light2vc = normalize(v4conv3(gl_LightSource[2].position));
/* Material properties */
col_ambi_diff = gl_Color.rgb;
col_emit = gl_FrontMaterial.emission.rgb;
/* Coordinates */
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
gl_Position = ftransform();
}
|