35 lines
860 B
Plaintext
35 lines
860 B
Plaintext
|
#version 460 core
|
||
|
|
||
|
layout (location = 0) in vec3 v_pos;
|
||
|
layout (location = 1) in vec3 v_normal;
|
||
|
layout (location = 2) in vec3 v_tangent;
|
||
|
layout (location = 3) in vec2 v_texcoord;
|
||
|
|
||
|
out VS_OUT {
|
||
|
vec3 viewPos;
|
||
|
vec2 texcoord;
|
||
|
mat3 TBN;
|
||
|
} vs_out;
|
||
|
|
||
|
layout (std140, binding=0) uniform FrameMatrices {
|
||
|
mat4 view;
|
||
|
mat4 projection;
|
||
|
};
|
||
|
layout (location=0) uniform mat4 model;
|
||
|
|
||
|
void main() {
|
||
|
gl_Position = projection * view * model * vec4(v_pos, 1.0);
|
||
|
|
||
|
vs_out.texcoord = v_texcoord;
|
||
|
|
||
|
// Gram-schmidt process for re-orthogonalizing the TBN vectors
|
||
|
vec3 T = normalize(vec3(view * model * vec4(v_tangent, 0.0)));
|
||
|
vec3 N = normalize(vec3(view * model * vec4(v_normal, 0.0)));
|
||
|
T = normalize(T - dot(T, N) * N);
|
||
|
vec3 B = cross(N, T);
|
||
|
vs_out.TBN = mat3(T, B, N);
|
||
|
|
||
|
vs_out.viewPos = (view * model * vec4(v_pos, 1.0)).xyz;
|
||
|
}
|
||
|
|