After having a look at libraries like glm, and seeing that the OpenGL 3.2 tutorials also use a ‘utils.c’ that implements some matrix manipulation routines for basic stuff like rotation etc, Im wondering what the general wisdom around here is:
Send matrices to the shader and manipulate in there, or do it outside via glm etc and send the results to the shader?
I always thought rotation etc should be done via passing an ‘angle’ variable and letting the shaders do the rest but I see people doing otherwise.
“it depends”
Sometimes it is better to precompute as much as you can on CPU, taking advantage of double precision and no extra computation on the realtime shader.
I think for me it depends on how many times I have to do it. For example, calculating one rotation matrix via an angle and sending it down is simple. One a GPU shader, it would have to be recalculated thousands of times for all the vertices. Millions if it’s in the fragment shader. CPU libraries also provide much more powerful functions and easier debugging.
I guess in the end though, it’s all about benchmarking. If you’re doing a lot of shading calculations anyway and that isn’t the bottleneck of your application, it’s not a big deal either way.