2022-06-14 00:32:33 +00:00
|
|
|
// If using this WGSL snippet as an #import, a dedicated
|
2022-03-29 18:31:13 +00:00
|
|
|
// "joint_matricies" uniform of type SkinnedMesh must be added in the
|
|
|
|
// main shader.
|
|
|
|
|
|
|
|
#define_import_path bevy_pbr::skinning
|
|
|
|
|
|
|
|
fn skin_model(
|
|
|
|
indexes: vec4<u32>,
|
|
|
|
weights: vec4<f32>,
|
|
|
|
) -> mat4x4<f32> {
|
2022-07-14 21:17:16 +00:00
|
|
|
return weights.x * joint_matrices.data[indexes.x]
|
|
|
|
+ weights.y * joint_matrices.data[indexes.y]
|
|
|
|
+ weights.z * joint_matrices.data[indexes.z]
|
|
|
|
+ weights.w * joint_matrices.data[indexes.w];
|
2022-03-29 18:31:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn inverse_transpose_3x3(in: mat3x3<f32>) -> mat3x3<f32> {
|
2022-06-18 07:41:54 +00:00
|
|
|
let x = cross(in[1], in[2]);
|
|
|
|
let y = cross(in[2], in[0]);
|
|
|
|
let z = cross(in[0], in[1]);
|
|
|
|
let det = dot(in[2], z);
|
2022-03-29 18:31:13 +00:00
|
|
|
return mat3x3<f32>(
|
|
|
|
x / det,
|
|
|
|
y / det,
|
|
|
|
z / det
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn skin_normals(
|
|
|
|
model: mat4x4<f32>,
|
|
|
|
normal: vec3<f32>,
|
|
|
|
) -> vec3<f32> {
|
2022-11-11 03:31:57 +00:00
|
|
|
return normalize(
|
|
|
|
inverse_transpose_3x3(
|
|
|
|
mat3x3<f32>(
|
|
|
|
model[0].xyz,
|
|
|
|
model[1].xyz,
|
|
|
|
model[2].xyz
|
|
|
|
)
|
|
|
|
) * normal
|
|
|
|
);
|
2022-03-29 18:31:13 +00:00
|
|
|
}
|