#version 330 core // Vertex shader decides where each vertex is in 3D space // --- INPUTS --- // Comes directly from the vertex buffer layout(location = 0) in vec3 aPosition; // Raw 3D position layout(location = 1) in vec3 aNormal; // The direction perpendicular to the surface layout(location = 2) in vec2 aTexCoord; // The U,V texture coordinates layout(location = 3) in vec3 aTangent; // Tangent vector for normal mapping layout(location = 4) in vec3 aBitangent; // Bitangent vector for normal mapping // --- OUTPUTS --- // We can pass data to the fragment shader through these out vec3 FragPos; out vec3 Normal; out vec2 TexCoord; out mat3 vTBN; // --- UNIFORMS --- // These are matrices that help transform our vertices uniform mat4 model; uniform mat4 view; uniform mat4 projection; void main(void) { vec3 T = normalize(vec3(model * vec4(aTangent, 0.0))); vec3 B = normalize(vec3(model * vec4(aBitangent, 0.0))); vec3 N = normalize(vec3(model * vec4(aNormal, 0.0))); vTBN = mat3(T, B, N); // 1. Calculate World Position FragPos = vec3(model * vec4(aPosition, 1.0)); // 2. Calculate Normal Normal = mat3(transpose(inverse(model))) * aNormal; // 3. Pass Texture Coordinates TexCoord = aTexCoord; // 4. Calculate Final Position gl_Position = projection * view * vec4(FragPos, 1.0); }