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.
1import package::render::mesh_types::SkinnedMesh;
2import package::render::mesh_bindings::mesh;
4@if(SKINNED && SKINS_USE_UNIFORM_BUFFERS)
5@group(2) @binding(1) var<uniform> joint_matrices: SkinnedMesh;
6@if(SKINNED && !SKINS_USE_UNIFORM_BUFFERS)
7@group(2) @binding(1) var<storage> joint_matrices: array<mat4x4<f32>>;
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@if(SKINNED && SKINS_USE_UNIFORM_BUFFERS)
16@group(2) @binding(6) var<uniform> prev_joint_matrices: SkinnedMesh;
17@if(SKINNED && !SKINS_USE_UNIFORM_BUFFERS)
18@group(2) @binding(6) var<storage> prev_joint_matrices: array<mat4x4<f32>>;
20@if(SKINNED)
21fn skin_model(
22 indexes: vec4<u32>,
23 weights: vec4<f32>,
24 instance_index: u32,
25) -> mat4x4<f32> {
26@if(SKINS_USE_UNIFORM_BUFFERS)
27 return weights.x * joint_matrices.data[indexes.x]
28 + weights.y * joint_matrices.data[indexes.y]
29 + weights.z * joint_matrices.data[indexes.z]
30 + weights.w * joint_matrices.data[indexes.w];
31@if(!SKINS_USE_UNIFORM_BUFFERS)
32 var skin_index = mesh[instance_index].current_skin_index;
33@if(!SKINS_USE_UNIFORM_BUFFERS)
34 return weights.x * joint_matrices[skin_index + indexes.x]
35 + weights.y * joint_matrices[skin_index + indexes.y]
36 + weights.z * joint_matrices[skin_index + indexes.z]
37 + weights.w * joint_matrices[skin_index + indexes.w];
40/// Returns the skinned position of a vertex with the given weights from the
41/// previous frame.
42///
43/// This is used for motion vector computation.
44@if(SKINNED)
45fn skin_prev_model(
46 indexes: vec4<u32>,
47 weights: vec4<f32>,
48 instance_index: u32,
49) -> mat4x4<f32> {
50@if(SKINS_USE_UNIFORM_BUFFERS)
51 return weights.x * prev_joint_matrices.data[indexes.x]
52 + weights.y * prev_joint_matrices.data[indexes.y]
53 + weights.z * prev_joint_matrices.data[indexes.z]
54 + weights.w * prev_joint_matrices.data[indexes.w];
55@if(!SKINS_USE_UNIFORM_BUFFERS)
56 let skin_index = mesh[instance_index].current_skin_index;
57@if(!SKINS_USE_UNIFORM_BUFFERS)
58 return weights.x * prev_joint_matrices[skin_index + indexes.x]
59 + weights.y * prev_joint_matrices[skin_index + indexes.y]
60 + weights.z * prev_joint_matrices[skin_index + indexes.z]
61 + weights.w * prev_joint_matrices[skin_index + indexes.w];
64@if(SKINNED)
65fn inverse_transpose_3x3m(in: mat3x3<f32>) -> mat3x3<f32> {
66 let x = cross(in[1], in[2]);
67 let y = cross(in[2], in[0]);
68 let z = cross(in[0], in[1]);
69 let det = dot(in[2], z);
70 return mat3x3<f32>(
71 x / det,
72 y / det,
73 z / det
74 );
77@if(SKINNED)
78fn skin_normals(
79 world_from_local: mat4x4<f32>,
80 normal: vec3<f32>,
81) -> vec3<f32> {
82 return normalize(
83 inverse_transpose_3x3m(
84 mat3x3<f32>(
85 world_from_local[0].xyz,
86 world_from_local[1].xyz,
87 world_from_local[2].xyz
88 )
89 ) * normal
90 );
Contents