3D OpenGL Transformations: what is the difference between multiply by an uniform scale matrix and divide w?

Viewed 80

In OpenGL, we can scale an object by multiplying it by a scale matrix of the form

x 0 0 0
0 y 0 0
0 0 z 0
0 0 0 1

Now let's suppose I want to have an uniform scaling (which is quite often the case), so the transformation matrix A is of the form:


A = s 0 0 0
    0 s 0 0
    0 0 s 0
    0 0 0 1

The scale by a factor s. But since OpenGL divide the vector coordinates (x, y, z, w) by w, can I, and isn't it more efficient (less computations to do) to instead of multiplying by A, divide w by s ? Do engines use it, and if not why not ?

1 Answers

You are asking the wrong question.

Engines don't do this because engines generally don't multiply things by a "scale matrix". They multiply things by a matrix, whose contents the shader neither knows nor cares about. It might include scaling; it might not. Either way, the vertex shader could not care less. It's just doing matrix math.

Your way would require that the VS be explicitly aware that "scaling" is a special transformation, distinct from rotation, positioning, or others, and to use special math to compute it. The standard way doesn't require a special "scaling" uniform or anything of the like. It's just a part of the matrix. It also composes better with other transformations, since it's just another transformation stored in the same kind of object, using the same math for composition.

Indeed, composition almost certainly would not work correctly in the [3,3] component of the matrix.

Related