In the section where Shaders.metal is modified the first time to handle instances there is one line that confuses me…
Instances instance = instances[instanceID]; out.position = uniforms.projectionMatrix * uniforms.viewMatrix * uniforms.modelMatrix * instance.modelMatrix * vertexIn.position; // The following line seems wrong to me out.worldPosition = (uniforms.modelMatrix * vertexIn.position * instance.modelMatrix).xyz; out.worldNormal = uniforms.normalMatrix * instance.normalMatrix * vertexIn.normal; out.worldTangent = uniforms.normalMatrix * instance.normalMatrix * vertexIn.tangent; out.worldBitangent = uniforms.normalMatrix * instance.normalMatrix * vertexIn.bitangent;
Shouldn’t the calculation of out.worldPosition look like…
out.worldPosition = (uniforms.modelMatrix * instance.modelMatrix * vertexIn.position).xyz;
In other words, aren’t instance.modeMatrix and vertexIn.position backwards on that line in the book?