ToyEngine/Demo/Engine/Shaders/model_shadow.vert

48 lines
1.1 KiB
GLSL

#version 450 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
layout (location = 2) in vec2 aTexCoords;
layout (location = 3) in ivec4 boneIds;
layout (location = 4) in vec4 weights;
out vec2 vTexCoords;
uniform mat4 model;
const int MAX_BONES = 100;
const int MAX_BONE_INFLUENCE = 4;
layout (std140, binding = 1) uniform FinalBonesMatrices
{
mat4 finalBonesMatrices[MAX_BONES];
};
void main()
{
vec4 totalPosition = vec4(0.0f);
vec3 totalNormal = vec3(0);
int boneCount = 0;
for(int i = 0 ; i < MAX_BONE_INFLUENCE ; i++)
{
if(boneIds[i] == -1)
continue;
if(boneIds[i] >= MAX_BONES)
{
totalPosition = vec4(aPos,1.0f);
break;
}
boneCount++;
vec4 localPosition = finalBonesMatrices[boneIds[i]] * vec4(aPos,1.0f);
totalPosition += localPosition * weights[i];
vec3 localNormal = mat3(finalBonesMatrices[boneIds[i]]) * aNormal;
totalNormal += localNormal * weights[i];
}
if(boneCount == 0)
{
totalPosition = vec4(aPos, 1);
totalNormal = vec3(aNormal);
}
vTexCoords = aTexCoords;
gl_Position = model * totalPosition;
}