#version 450

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

layout(set = 0, binding = 1) uniform entity {
    mat4 model;
    vec3 color;
};

layout(std430, set = 1, binding = 0) readonly buffer JointBuffer {
    mat4 jointMatrices[];
};

layout(location = 0) in vec3 aVertexPos;
layout(location = 1) in vec3 aVertexNormal;
layout(location = 2) in vec2 aVertexCoord;
layout(location = 3) in vec4 aVertexJoint;
layout(location = 4) in vec4 aVertexWeight;

layout(location = 0) out vec3 oColor;
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;
    oColor = aVertexWeight.rgb;

    mat4 skinMat =
		aVertexWeight.x * jointMatrices[int(aVertexJoint.x)] +
		aVertexWeight.y * jointMatrices[int(aVertexJoint.y)] +
		aVertexWeight.z * jointMatrices[int(aVertexJoint.z)] +
		aVertexWeight.w * jointMatrices[int(aVertexJoint.w)];

    gl_Position = proj * view * skinMat * vec4(aVertexPos, 1);
    oFragTexCoord = aVertexCoord;
}
