1uniform mat4 projection;
2uniform mat4 modelview;
3uniform mat3 normalMatrix;
4varying vec3 vertex_normal;
5varying vec4 vertex_position;
6varying vec3 eye_direction;
7attribute vec3 vertex;
8attribute vec3 normal;
9
10vec3 unitvec(vec4 v1, vec4 v2)
11{
12    if (v1.w == 0.0 && v2.w == 0.0)
13        return vec3(v2 - v1);
14    if (v1.w == 0.0)
15        return vec3(-v1);
16    if (v2.w == 0.0)
17        return vec3(v2);
18    return v2.xyz/v2.w - v1.xyz/v1.w;
19}
20
21void main()
22{
23    vec4 curVertex = vec4(vertex.x, vertex.y, vertex.z, 1.0);
24    gl_Position = projection * modelview * curVertex;
25    vertex_normal = normalMatrix * normal;
26    vertex_position = modelview * curVertex;
27    eye_direction = normalize(unitvec(vertex_position, vec4(0.0, 0.0, 0.0, 1.0)));
28}
29