#version 330 in vec3 vPosition; in vec4 vColor; in vec3 vNormal; in vec3 tangent; in vec3 bitangent; in vec2 vTexCoord; uniform mat4 model; uniform mat4 view; uniform mat4 projection; out vec3 defNormal; out vec2 texCoord; uniform vec3 vLightPos; uniform vec3 vViewPos; out vec3 lightPos; out vec3 viewPos; out vec3 fragPos; struct Material { vec3 ambient; vec3 diffuse; sampler2D diffuseMap; vec3 specular; sampler2D specularMap; float shininess; bool hasTexture; bool hasSpecularMap; sampler2D normalMap; bool hasNormalMap; }; uniform Material material; void main() { vec4 pos = model * vec4(vPosition, 1.f); defNormal = mat3(transpose(inverse(model))) * vNormal; texCoord = vTexCoord; //tangent space stuff if (material.hasNormalMap) { vec3 T = normalize(vec3(model * vec4(tangent, 0.0))); vec3 B = normalize(vec3(model * vec4(bitangent, 0.0))); vec3 N = normalize(vec3(model * vec4(vNormal, 0.0))); // convert TBN to world->tangent space mat3 TBN = transpose(mat3(T, B, N)); lightPos = TBN * vLightPos; viewPos = TBN * vViewPos; fragPos = TBN * vec3(pos); } else { lightPos = vLightPos; viewPos = vViewPos; fragPos = vec3(pos); } gl_Position = projection * view * pos; }