@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
42 lines (39 loc) • 1.35 kB
JavaScript
var skinTexVS = `
attribute vec4 vertex_boneWeights;
attribute vec4 vertex_boneIndices;
uniform highp sampler2D texture_poseMap;
uniform vec4 texture_poseMapSize;
void getBoneMatrix(const in float index, out vec4 v1, out vec4 v2, out vec4 v3) {
float i = float(index);
float j = i * 3.0;
float dx = texture_poseMapSize.z;
float dy = texture_poseMapSize.w;
float y = floor(j * dx);
float x = j - (y * texture_poseMapSize.x);
y = dy * (y + 0.5);
v1 = texture2D(texture_poseMap, vec2(dx * (x + 0.5), y));
v2 = texture2D(texture_poseMap, vec2(dx * (x + 1.5), y));
v3 = texture2D(texture_poseMap, vec2(dx * (x + 2.5), y));
}
mat4 getSkinMatrix(const in vec4 indices, const in vec4 weights) {
vec4 a1, a2, a3;
getBoneMatrix(indices.x, a1, a2, a3);
vec4 b1, b2, b3;
getBoneMatrix(indices.y, b1, b2, b3);
vec4 c1, c2, c3;
getBoneMatrix(indices.z, c1, c2, c3);
vec4 d1, d2, d3;
getBoneMatrix(indices.w, d1, d2, d3);
vec4 v1 = a1 * weights.x + b1 * weights.y + c1 * weights.z + d1 * weights.w;
vec4 v2 = a2 * weights.x + b2 * weights.y + c2 * weights.z + d2 * weights.w;
vec4 v3 = a3 * weights.x + b3 * weights.y + c3 * weights.z + d3 * weights.w;
float one = dot(weights, vec4(1.0));
return mat4(
v1.x, v2.x, v3.x, 0,
v1.y, v2.y, v3.y, 0,
v1.z, v2.z, v3.z, 0,
v1.w, v2.w, v3.w, one
);
}
`;
export { skinTexVS as default };