Chapter 13 matrix order confusion

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?

Thanks,
~chuck

1 Like

@cocheret - yes - you’re absolutely right!

Thank you so much for picking that up and letting us know.

No problem. Glad I was not misunderstanding something. One of the easiest mistakes to make during a repetitive change to a bunch of lines.