What is the difference between doing these two operations? Don't the first transform the vector from model space to view space? Then what does the second operation do?

gl_ModelViewMatrix * vec4(vector, 0.0)

gl_ModelViewMatrixTranspose * vec4(vector, 0.0)

  • 2
    \$\begingroup\$ Transposition makes column-major matrix row-major and vice versa. \$\endgroup\$
    – Ocelot
    Sep 6 '19 at 0:02

Transpose of a matrix is the same as inverting the matrix, as long as the matrix is orthogonal.

So if your gl_ModelView matrix transforms from model space to view space, then the transpose (inverse) of that matrix will transform from view space to model space.

  • \$\begingroup\$ Thanks, but why sometimes use that instead of gl_ModelViewMatrixInverse? \$\endgroup\$
    – Invariant
    Sep 6 '19 at 7:25
  • \$\begingroup\$ added further explanation to answer. \$\endgroup\$ Sep 6 '19 at 7:29
  • \$\begingroup\$ You're wrong, transpose = inverse only in case of rotation and reflection matrices. \$\endgroup\$
    – Ocelot
    Sep 6 '19 at 8:45
  • \$\begingroup\$ Invariant - using transpose is much cheaper than inverse, so in cases where it makes sense (such as when you have an orthogonal matrix) using transpose saves a bit of time \$\endgroup\$ Sep 6 '19 at 14:30
  • \$\begingroup\$ Ocelot - Yes, thank you for pointing that out . I qualified my statement in the edit. Matrix must be orthogonal. \$\endgroup\$ Sep 6 '19 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.