#version 450

layout(binding = 0) uniform global {
    mat4 view;
    mat4 proj;
};

layout(binding = 1) uniform entity {
    mat4 model;
    vec3 color;
    vec4 material;
};

layout(location = 0) in vec3 aVertexPos;
layout(location = 1) in vec3 aVertexNormal;
layout(location = 2) in vec2 aVertexCoord;

layout(location = 0) out vec3 oFragPos;
layout(location = 1) out vec3 oNormal;
layout(location = 2) out vec2 oFragTexCoord;

void main() {
    // oColor = (aVertexNormal + 1) / 2;
    // oColor = pow(oColor, vec3(2.2)) * color;
    // float bw = dot(aVertexNormal, vec3(0.3, 0.3, 0.3));
    // oColor = vec3(bw) * color;

    // compute fragment position in view space
    mat4 modelView = view * model;
    oFragPos = vec3(modelView * vec4(aVertexPos, 1.0));

    // compute normal position in view space
    mat3 normalMatrix = transpose(inverse(mat3(modelView)));
    oNormal = normalize(normalMatrix * aVertexNormal);

    oFragTexCoord = aVertexCoord;

    gl_Position = proj * view * model * vec4(aVertexPos, 1);
}
