diff --git a/src/sample/skinnedMesh/glbUtils.ts b/src/sample/skinnedMesh/glbUtils.ts index 51758843..28b5650a 100644 --- a/src/sample/skinnedMesh/glbUtils.ts +++ b/src/sample/skinnedMesh/glbUtils.ts @@ -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, diff --git a/src/sample/skinnedMesh/gltf.wgsl b/src/sample/skinnedMesh/gltf.wgsl index 25a3c029..220a539a 100644 --- a/src/sample/skinnedMesh/gltf.wgsl +++ b/src/sample/skinnedMesh/gltf.wgsl @@ -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, @location(1) normal: vec3, - @location(2) joints: vec4, - @location(3) weights: vec4, + @location(2) texcoord: vec2, + @location(3) joints: vec4, + @location(4) weights: vec4, } struct VertexOutput { @@ -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(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(input.position.x, input.position.y, input.position.z, 1.0); output.normal = input.normal; - output.joints = input.joints; + output.joints = vec4(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(input.weights.x), f32(input.weights.y), f32(input.weights.z), f32(input.weights.w)); + output.weights = input.weights; return output; } diff --git a/src/sample/skinnedMesh/main.ts b/src/sample/skinnedMesh/main.ts index 53ba1baa..c78a9f34 100644 --- a/src/sample/skinnedMesh/main.ts +++ b/src/sample/skinnedMesh/main.ts @@ -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); diff --git a/src/sample/skinnedMesh/standGrid.wgsl b/src/sample/skinnedMesh/standGrid.wgsl new file mode 100644 index 00000000..e69de29b