Tidy up
[opengl.git] / texturevertex.glsl
1 #version 330
2 in vec3 vPosition;
3 in vec4 vColor;
4 in vec3 vNormal;
5 in vec3 tangent;
6 in vec3 bitangent;
7 in vec2 vTexCoord;
8
9 uniform mat4 model;
10 uniform mat4 view;
11 uniform mat4 projection;
12
13 out vec3 defNormal;
14 out vec2 texCoord;
15
16 uniform vec3 vLightPos;
17 uniform vec3 vViewPos;
18
19 out vec3 lightPos;
20 out vec3 viewPos;
21 out vec3 fragPos;
22
23 void main() {
24         vec4 pos = model * vec4(vPosition, 1.f);
25         texCoord = vTexCoord;
26
27         //tangent space stuff
28         vec3 T = normalize(vec3(model * vec4(tangent,   0.0)));
29         vec3 B = normalize(vec3(model * vec4(bitangent, 0.0)));
30         vec3 N = normalize(vec3(model * vec4(vNormal,    0.0)));
31         // convert TBN to world->tangent space
32         mat3 TBN = transpose(mat3(T, B, N));
33
34         lightPos = TBN * vLightPos;
35         viewPos = TBN * vViewPos;
36         fragPos = TBN * vec3(pos);
37         defNormal = TBN * mat3(transpose(inverse(model))) * vNormal;
38         
39         gl_Position = projection * view * pos;
40 }