Skip to content

Commit

Permalink
Fixed bug where texcoords were not being loaded in, even though they …
Browse files Browse the repository at this point in the history
…are not used, which caused interpretation errors with the joints and weights 🤦
  • Loading branch information
cmhhelgeson committed Jan 25, 2024
1 parent 4895e1d commit c7f7fb5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/sample/skinnedMesh/glbUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,15 @@ export class GLTFPrimitive {
attributes: [
{
format: this.attributeMap[attr].vertexType,
offset: this.attributeMap[attr].byteOffset, //this.attributeMap[attr].byteOffset
offset: this.attributeMap[attr].byteOffset,
shaderLocation: idx,
},
],
};
}
);

console.log(vertexBuffers);
const vertexState: GPUVertexState = {
// Shader stage info
module: vertexShaderModule,
Expand Down
22 changes: 13 additions & 9 deletions src/sample/skinnedMesh/gltf.wgsl
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// Whale.glb Vertex attributes
// POSTION, NORMAL, TEXCOORD_0, JOINTS_0, WEIGHTS_0
// f32x3 f32x3 f32x2 u8x4 f32x4
struct VertexInput {
@location(0) position: vec3<f32>,
@location(1) normal: vec3<f32>,
@location(2) joints: vec4<f32>,
@location(3) weights: vec4<u32>,
@location(2) texcoord: vec2<f32>,
@location(3) joints: vec4<u32>,
@location(4) weights: vec4<f32>,
}

struct VertexOutput {
Expand Down Expand Up @@ -35,15 +39,15 @@ struct NodeUniforms {
fn vertexMain(input: VertexInput) -> VertexOutput {
var output: VertexOutput;
let skin_matrix =
joint_matrices[u32(input.joints[0])] * f32(input.weights[0]) +
joint_matrices[u32(input.joints[1])] * f32(input.weights[1]) +
joint_matrices[u32(input.joints[2])] * f32(input.weights[2]) +
joint_matrices[u32(input.joints[3])] * f32(input.weights[3]);
output.Position = camera_uniforms.projMatrix * camera_uniforms.viewMatrix * camera_uniforms.modelMatrix * vec4<f32>(input.position.x, input.position.y, input.position.z, 1.0);
joint_matrices[input.joints[0]] * input.weights[0] +
joint_matrices[input.joints[1]] * input.weights[1] +
joint_matrices[input.joints[2]] * input.weights[2] +
joint_matrices[input.joints[3]] * input.weights[3];
output.Position = camera_uniforms.projMatrix * camera_uniforms.viewMatrix * skin_matrix * vec4<f32>(input.position.x, input.position.y, input.position.z, 1.0);
output.normal = input.normal;
output.joints = input.joints;
output.joints = vec4<f32>(f32(input.joints[0]), f32(input.joints[1]), f32(input.joints[2]), f32(input.joints[3]));
// Convert to f32 to avoid flat interpolation error
output.weights = vec4<f32>(f32(input.weights.x), f32(input.weights.y), f32(input.weights.z), f32(input.weights.w));
output.weights = input.weights;
return output;
}

Expand Down
5 changes: 5 additions & 0 deletions src/sample/skinnedMesh/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ const init: SampleInit = async ({
[cameraBGCluster.bindGroupLayout, generalUniformsBGCLuster.bindGroupLayout, nodeUniformsBindGroupLayout, GLTFSkin.skinBindGroupLayout],
);

//const standingGridScene = await fetch('../assets/gltf/simpleSkin.glb')
// .then((res) => res.arrayBuffer())
// .then((buffer) => convertGLBToJSONAndBinary(buffer, device));


// Create grid resources
const skinnedGridVertexBuffers = createSkinnedGridBuffers(device);
//const skinnedGridBoneArrayBuffer = new Float32Array(4 * 16);
Expand Down
Empty file.

0 comments on commit c7f7fb5

Please sign in to comment.