PDA

View Full Version : Safe to use only one matrix?



Ilian Dinev
03-16-2009, 07:28 PM
DX has 3 matrices, GL has 2, and it seems to me that I can simply use only one matrix: something like the gl_ModelViewProjection.
I've long since replaced all fixed-func GLSL symbols, doing the maths myself - but keeping 2 matrices (project and mview) then multiplying them once per object to send the updated value to shaders.
In the math-correction tests I did, I noticed the difference between the two approaches is only one bit in the floats[6], the least significant bit in the mantissa.

My question is: can I simply use/provide only one "matrix stack", on which to first apply projection, then camera, then object transforms? If I need to transform a vertex from to world-space, I think multiplication with inverse-matrix of projection or camera should suffice (when I cannot simply redo the transformation-sequence starting from identity). Those projection and camera matrices get updated just once per camera per frame, after all.

This is mostly about coding-convenience and optimization.

martinsm
03-17-2009, 03:48 AM
Yes, you can use only one matrix. But sometimes you need also world coordinates in your vertex shader - then you will need gl_ModelViewMatrix, not only gl_MVPMatrix.

Ilian Dinev
03-17-2009, 06:51 AM
Thanks.
Yes, for those cases I'll probably rebuild a MV matrix, or try using inverse of projection.