blob: 9a83ba81be68fcb4df2b7046b4f80febb676e66c (
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
|
#version 120
uniform mat4 mvp; // object -> world -> eye -> screen
uniform mat4 mv; // object -> world -> eye
uniform vec4 eye; // Eye position in world space
uniform vec4 light_pos_es; // Light position in world-space.
// These two are in object space
attribute vec4 normal;
attribute vec4 tangent;
attribute vec2 uv;
// Vector from the light to the vertex transformed to surface space.
varying vec3 light_ss;
// ???
varying vec3 eye_ss;
void main(void)
{
gl_Position = mvp * gl_Vertex;
vec3 tangent_es = vec3(mv * tangent);
vec3 normal_es = vec3(mv * normal);
vec3 bitangent_es = cross(normal_es, tangent_es);
mat3 tbn = mat3(tangent_es, bitangent_es, normal_es);
vec3 vertex_pos_es = vec3(mv * gl_Vertex);
vec3 light_direction_es = vec3(light_pos_es) - vertex_pos_es;
/* Surface space vectors for lighting */
light_ss = normalize(light_direction_es * tbn);
eye_ss = -normalize(vertex_pos_es * tbn);
}
|