1
votes

It doesn't look like any operation can make the bottom row something else then [0 0 0 1] and vertex position come with vec3 which need to be upgraded to vec4 before transform. Yet I constantly see shaders using mat4 for projection/view/modeltoworld. Considering that, why is the standard to use mat4 and not mat3x4 ? We could save the transfer of 16 bytes and 1/4 of a mat4xvec4 multiplication.

1
What you're talking about would still require a vec4 (you need that W=1), and the matrix in question would need to be a mat4x3 (4 columns, 3 rows). Otherwise, position translations just don't work.Nicol Bolas

1 Answers

3
votes

Perspective projection transformations, for instance, have a bottom row of [0 0 -1 0], which affects the w coordinate of the vertex. So, if you used a vec3 to represent the vertex in a shader, OpenGL (and pretty much all other rendering APIs) would automatically insert a value of 1.0 for the w coordinate after applying your mat3x4 transformation, which would effectively disable the perspective divide step (i.e., when the graphics system divides each x, y, and z coordinate by w), which is the magic that allows objects to seem smaller as they get farther from the eye.

And in general, saving 16 bytes per uniform update (which is what you'd do to update your projection transformation matrix, and likely occurs once per shader program binding) is nothing as compared optimizing vertex attributes or texture uploads, or virtually anything else graphics related.