# Vertex Optimizations

Posted Friday, 27 December, 2013 - 22:08 by Seven inI'm still grasping exactly how OpenGL works under the hood, and I was curious about the vertex transformations in particular. Does the built in "ftransform()" funciton (in the vertex shader) do entire matrix multiplications (project * model * vertex)? Since the projection matrix typically includes multiple zero values, you should be able to break down the multiplications and only do the known-to-be non-zero multiplications.

If ftransform() does all those possibly unnecessary multiplications, would it not be more efficient to pass in the transform matrices as uniform variables an only do the necessary multiplications? Besides just saving a few multiplications, I wanted to make sure that OpenGL pre-computes the (project * model) transformation during an entire vertex buffer, so that it is not re-computed per vertex. If that is the case, you could save nearly 16 multiplications per vertex, but I assumed OpenGL was not that inefficient.

If using the uniform variables could be faster, this would make a huge difference when considering it happens for every single vertex. Please let me know if you have speed tested this topic. Thanks.

## Comments

## Re: Vertex Optimizations

Matrix multiplication is very fast and optimized on the GPU. 2 matrix multiplications per vertex is not going to bottleneck you. Yes you can precompute a worldViewProj on the CPU per model but the extra load on the CPU might actually slow you down. In pactice you cant physically push so many vertices that the GPU matrices would make a measurable slowdown.

As a very hard rule of the thumb don't worry about optimizations(I insist) before there is even a slight hint of bottlenecking. Don't get misleaded if something halves your fps at 5000. When you get 100-200+ fps on your build machine, think about optimizations only after you have the whole game/level completed.