cyborg/shaders/mesh_skinning.wgsl
2022-09-17 09:34:52 -06:00

44 lines
1.1 KiB
WebGPU Shading Language

#include oct_encoding.wgsl
#include skin.wgsl
struct SkinningUniform {
transform: mat4x4<f32>,
src_offset: u32,
dst_offset: u32,
count: u32,
};
@group(0) @binding(0)
var<storage,read> skinning_ubo: SkinningUniform;
@group(0) @binding(1)
var<storage,write> dst_vertices: SkinnedVertexArray;
@group(0) @binding(2)
var<storage,read> src_vertices: SkinnedVertexArray;
@compute
@workgroup_size(64)
fn cs_main(
@builtin(global_invocation_id) global_invocation_id: vec3<u32>,
) {
let vertex_index = global_invocation_id.x;
if (vertex_index >= skinning_ubo.count) {
return;
}
let src_index = skinning_ubo.src_offset + vertex_index;
let dst_index = skinning_ubo.dst_offset + vertex_index;
let ptf = src_vertices.data[src_index].ptf;
let position = ptf.xyz;
let tan_frame = bitcast<u32>(ptf.w);
let transform = skinning_ubo.transform;
let position = transform * vec4<f32>(position, 1.0);
let tan_frame = tan_frame_transform(tan_frame, transform);
let dst_ptf = vec4<f32>(position.xyz, bitcast<f32>(tan_frame));
dst_vertices.data[dst_index].ptf = dst_ptf;
}