2023-07-16 14:15:14 +08:00
|
|
|
#version 310 es
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2023-07-16 14:15:14 +08:00
|
|
|
layout(location = 0) in vec3 a_position;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2023-07-16 14:15:14 +08:00
|
|
|
layout(location = 1) in vec4 a_blendWeight;
|
|
|
|
layout(location = 2) in vec4 a_blendIndex;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2023-07-16 14:15:14 +08:00
|
|
|
layout(location = 3) in vec2 a_texCoord;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
const int SKINNING_JOINT_COUNT = 60;
|
|
|
|
// Uniforms
|
|
|
|
|
|
|
|
// Varyings
|
2023-07-16 14:15:14 +08:00
|
|
|
layout(location = 0) out vec2 TextureCoordOut;
|
|
|
|
|
2023-07-16 22:10:48 +08:00
|
|
|
layout(std140) uniform vs_ub {
|
2023-07-16 14:15:14 +08:00
|
|
|
vec4 u_matrixPalette[SKINNING_JOINT_COUNT * 3];
|
|
|
|
mat4 u_MVPMatrix;
|
|
|
|
};
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
vec4 getPosition()
|
|
|
|
{
|
|
|
|
float blendWeight = a_blendWeight[0];
|
|
|
|
|
|
|
|
int matrixIndex = int (a_blendIndex[0]) * 3;
|
|
|
|
vec4 matrixPalette1 = u_matrixPalette[matrixIndex] * blendWeight;
|
|
|
|
vec4 matrixPalette2 = u_matrixPalette[matrixIndex + 1] * blendWeight;
|
|
|
|
vec4 matrixPalette3 = u_matrixPalette[matrixIndex + 2] * blendWeight;
|
|
|
|
|
|
|
|
|
|
|
|
blendWeight = a_blendWeight[1];
|
|
|
|
if (blendWeight > 0.0)
|
|
|
|
{
|
|
|
|
matrixIndex = int(a_blendIndex[1]) * 3;
|
|
|
|
matrixPalette1 += u_matrixPalette[matrixIndex] * blendWeight;
|
|
|
|
matrixPalette2 += u_matrixPalette[matrixIndex + 1] * blendWeight;
|
|
|
|
matrixPalette3 += u_matrixPalette[matrixIndex + 2] * blendWeight;
|
|
|
|
|
|
|
|
blendWeight = a_blendWeight[2];
|
|
|
|
if (blendWeight > 0.0)
|
|
|
|
{
|
|
|
|
matrixIndex = int(a_blendIndex[2]) * 3;
|
|
|
|
matrixPalette1 += u_matrixPalette[matrixIndex] * blendWeight;
|
|
|
|
matrixPalette2 += u_matrixPalette[matrixIndex + 1] * blendWeight;
|
|
|
|
matrixPalette3 += u_matrixPalette[matrixIndex + 2] * blendWeight;
|
|
|
|
|
|
|
|
blendWeight = a_blendWeight[3];
|
|
|
|
if (blendWeight > 0.0)
|
|
|
|
{
|
|
|
|
matrixIndex = int(a_blendIndex[3]) * 3;
|
|
|
|
matrixPalette1 += u_matrixPalette[matrixIndex] * blendWeight;
|
|
|
|
matrixPalette2 += u_matrixPalette[matrixIndex + 1] * blendWeight;
|
|
|
|
matrixPalette3 += u_matrixPalette[matrixIndex + 2] * blendWeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vec4 _skinnedPosition;
|
|
|
|
vec4 position = vec4(a_position, 1.0);
|
|
|
|
_skinnedPosition.x = dot(position, matrixPalette1);
|
|
|
|
_skinnedPosition.y = dot(position, matrixPalette2);
|
|
|
|
_skinnedPosition.z = dot(position, matrixPalette3);
|
|
|
|
_skinnedPosition.w = position.w;
|
|
|
|
|
|
|
|
return _skinnedPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
vec4 position = getPosition();
|
|
|
|
gl_Position = u_MVPMatrix * position;
|
|
|
|
|
|
|
|
TextureCoordOut = a_texCoord;
|
|
|
|
TextureCoordOut.y = 1.0 - TextureCoordOut.y;
|
|
|
|
}
|
|
|
|
|