Constant SKIN_WGSL
Source pub const SKIN_WGSL: &str = r#"
@group(0) @binding(4) var<storage, read> skin_data: array<vec4u>;
fn skin_joint(palette: u32, joint: u32) -> mat4x4f {
let at = palette + joint * 4u;
return mat4x4f(
bitcast<vec4f>(skin_data[at]),
bitcast<vec4f>(skin_data[at + 1u]),
bitcast<vec4f>(skin_data[at + 2u]),
bitcast<vec4f>(skin_data[at + 3u]),
);
}
fn skin_blend(skin: vec4u, vertex: u32, palette: u32) -> mat4x4f {
let record = skin.x + vertex * 2u;
let packed = skin_data[record];
let weights = bitcast<vec4f>(skin_data[record + 1u]);
var blended = skin_joint(palette, packed.x & 0xffffu) * weights.x;
blended = blended + skin_joint(palette, packed.x >> 16u) * weights.y;
blended = blended + skin_joint(palette, packed.y & 0xffffu) * weights.z;
blended = blended + skin_joint(palette, packed.y >> 16u) * weights.w;
return blended;
}
fn skin_unit(v: vec3f) -> vec3f {
let length = sqrt(dot(v, v));
return select(v, v / length, length > 0.0);
}
fn skin_position(position: vec3f, vertex: u32, skin: vec4u) -> vec3f {
return (skin_blend(skin, vertex, skin.y) * vec4f(position, 1.0)).xyz;
}
fn skin_shape(position: vec3f, normal: vec3f, tangent: vec4f, vertex: u32, skin: vec4u) -> DeformedVertex {
let current = skin_blend(skin, vertex, skin.y);
let previous = skin_blend(skin, vertex, skin.z);
var out: DeformedVertex;
out.position = (current * vec4f(position, 1.0)).xyz;
out.normal = skin_unit((current * vec4f(normal, 0.0)).xyz);
out.tangent = vec4f(skin_unit((current * vec4f(tangent.xyz, 0.0)).xyz), tangent.w);
out.previous_position = (previous * vec4f(position, 1.0)).xyz;
return out;
}
"#;