# Chapter 13 matrix order confusion

**URL:** <https://forums.kodeco.com/t/chapter-13-matrix-order-confusion/54792>\
**Category:** Metal by Tutorials\
**Created:** [November 6, 2018, 9:44pm UTC](https://forums.kodeco.com/t/chapter-13-matrix-order-confusion/54792 "2018-11-06T21:44:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cocheret](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/cocheret/32/105841_2.png) [@cocheret](https://forums.kodeco.com/u/cocheret)\
**Post date:** [November 6, 2018, 9:44pm UTC](https://forums.kodeco.com/t/chapter-13-matrix-order-confusion/54792/1 "2018-11-06T21:44:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![caroline](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/caroline/32/110937_2.png) [@caroline](https://forums.kodeco.com/u/caroline)\
**Post date:** [November 7, 2018, 9:45am UTC](https://forums.kodeco.com/t/chapter-13-matrix-order-confusion/54792/2 "2018-11-07T09:45:35Z")

</div>

@cocheret - yes - you’re absolutely right!

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

---

<div class="post-metadata">

**Author:** ![cocheret](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/cocheret/32/105841_2.png) [@cocheret](https://forums.kodeco.com/u/cocheret)\
**Post date:** [November 7, 2018, 7:29pm UTC](https://forums.kodeco.com/t/chapter-13-matrix-order-confusion/54792/3 "2018-11-07T19:29:57Z")

</div>

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