Reflection
[opengl.git] / texturevertex.glsl
1 #version 330
2 in vec3 pos;
3 in vec4 vColor;
4 in vec3 unscaledNormal;
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, worldNormal;
14 out vec2 texCoord;
15
16 uniform vec3 vLightPos;
17 uniform vec3 vViewPos;
18
19 out vec3 lightPos, viewPos, fragPos;
20 out vec3 worldViewPos, worldFragPos;
21
22 void main() {
23         vec4 worldPos = model * vec4(pos, 1.f);
24         texCoord = vTexCoord;
25
26         //tangent space stuff
27         vec3 T = normalize(vec3(model * vec4(tangent,   0.0)));
28         vec3 B = normalize(vec3(model * vec4(bitangent, 0.0)));
29         vec3 N = normalize(vec3(model * vec4(unscaledNormal,    0.0)));
30         // convert TBN to world->tangent space
31         mat3 TBN = transpose(mat3(T, B, N));
32
33         lightPos = TBN * vLightPos;
34         viewPos = TBN * vViewPos;
35         fragPos = TBN * vec3(worldPos);
36
37         worldViewPos = vViewPos;
38         worldFragPos = vec3(worldPos);
39
40         vec3 normal = mat3(transpose(inverse(model))) * unscaledNormal;
41
42         defNormal = TBN * normal;
43         worldNormal = normal;
44         
45         gl_Position = projection * view * worldPos;
46 }