ToyEngine/Exp2/Engine/Shaders/model_shadow.vert

48 lines
1.1 KiB
GLSL
Raw Normal View History

2023-04-16 17:12:29 +08:00
#version 450 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
layout (location = 2) in vec2 aTexCoords;
2023-04-16 20:56:02 +08:00
layout (location = 3) in ivec4 boneIds;
layout (location = 4) in vec4 weights;
2023-04-16 17:12:29 +08:00
out vec2 vTexCoords;
uniform mat4 model;
2023-04-16 20:56:02 +08:00
const int MAX_BONES = 100;
const int MAX_BONE_INFLUENCE = 4;
layout (std140, binding = 1) uniform FinalBonesMatrices
{
mat4 finalBonesMatrices[MAX_BONES];
};
2023-04-16 17:12:29 +08:00
void main()
{
2023-04-16 20:56:02 +08:00
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);
}
2023-04-16 17:12:29 +08:00
vTexCoords = aTexCoords;
2023-04-16 20:56:02 +08:00
gl_Position = model * totalPosition;
2023-04-16 17:12:29 +08:00
}