/////////////////////////////////////////////////////////////////////////
// Vertex shader for lighting
//
// Copyright 2013 DigiPen Institute of Technology
////////////////////////////////////////////////////////////////////////
#version 330 core

uniform mat4 WorldView, WorldProj, ModelTr, NormalTr;
uniform mat4 gBones[128];
uniform int  useSkinning; 

layout(location = 0) in vec4 vertex;
layout(location = 1) in vec3 vertexNormal;
layout(location = 2) in vec2 vertexTexture;
layout(location = 3) in vec3 vertexTangent;
layout(location = 4) in ivec4 boneIds;
layout(location = 5) in vec4  weight;

out vec3 normalVec;
out vec2 texCoord;
out vec4 worldPos;

void main()
{
    mat4 skin = mat4(1.0);
    if (useSkinning == 1) {
        skin =
          gBones[boneIds.x] * weight.x +
          gBones[boneIds.y] * weight.y +
          gBones[boneIds.z] * weight.z +
          gBones[boneIds.w] * weight.w;
    }
    vec4 pos = skin * vertex;
    gl_Position = WorldProj * WorldView * ModelTr * pos;

    worldPos  = ModelTr * pos;
    normalVec = mat3(NormalTr) * vertexNormal;
    texCoord  = vertexTexture;
}