Search across packages, versions, files, declarations, and comments. Use multiple terms to narrow results (AND), and add @vertex, @fragment, or @compute to filter by shader stage.
1#define_import_path bevy_pbr::skinning
3#import bevy_pbr::mesh_types::SkinnedMesh
5#ifdef SKINNED
7@group(1) @binding(1) var<uniform> joint_matrices: SkinnedMesh;
9// An array of matrices specifying the joint positions from the previous frame.
10//
11// This is used for motion vector computation.
12//
13// If this is the first frame, or we're otherwise prevented from using data from
14// the previous frame, this is simply the same as `joint_matrices` above.
15@group(1) @binding(6) var<uniform> prev_joint_matrices: SkinnedMesh;
17fn skin_model(
18 indexes: vec4<u32>,
19 weights: vec4<f32>,
20) -> mat4x4<f32> {
21 return weights.x * joint_matrices.data[indexes.x]
22 + weights.y * joint_matrices.data[indexes.y]
23 + weights.z * joint_matrices.data[indexes.z]
24 + weights.w * joint_matrices.data[indexes.w];
27// Returns the skinned position of a vertex with the given weights from the
28// previous frame.
29//
30// This is used for motion vector computation.
31fn skin_prev_model(
32 indexes: vec4<u32>,
33 weights: vec4<f32>,
34) -> mat4x4<f32> {
35 return weights.x * prev_joint_matrices.data[indexes.x]
36 + weights.y * prev_joint_matrices.data[indexes.y]
37 + weights.z * prev_joint_matrices.data[indexes.z]
38 + weights.w * prev_joint_matrices.data[indexes.w];
41fn inverse_transpose_3x3m(in: mat3x3<f32>) -> mat3x3<f32> {
42 let x = cross(in[1], in[2]);
43 let y = cross(in[2], in[0]);
44 let z = cross(in[0], in[1]);
45 let det = dot(in[2], z);
46 return mat3x3<f32>(
47 x / det,
48 y / det,
49 z / det
50 );
53fn skin_normals(
54 world_from_local: mat4x4<f32>,
55 normal: vec3<f32>,
56) -> vec3<f32> {
57 return normalize(
58 inverse_transpose_3x3m(
59 mat3x3<f32>(
60 world_from_local[0].xyz,
61 world_from_local[1].xyz,
62 world_from_local[2].xyz
63 )
64 ) * normal
65 );
68#endif
Contents