3 hours ago, bmarci said:
But most of the cases, even in AAA games, we had everything in 4x4 matrices because the sacred GPU likes that way, and the game code looked like a mess. Full with matrix decompose and inverses. But at least the engine/render guys could blame the game coders because the overall bad performance ![:D :D](https://uploads.gamedev.net/emoticons/medium.biggrin.webp)
In my experience, if code looks like a mess it is usually because there was no effort put into optimizations. The reason for that might be time restrictions. But often, especially if mathematics and physics are involved, people just don't know enough about the things they are dealing with. They just keep trying until it works and then they don't touch it anymore because they fear it might stop working. ?
Also, if you need to "undo" transformations a lot, I would also put some effort into optimizing my transformation orders. The only "inverse" transformation I see a lot is the inverse-transpose to adjust the normals. In my opinion, this is also unnecessary, since you can calculate the normal matrix during the calculation of the model-world matrix with minimal effort. But that's another story...
4 hours ago, bmarci said:
Somehow it works for me, and exactly that's what I'm doing with my rotate + translate combo, and before I pass it to the render I pack them into a 4x4 matrix.
I think you got me wrong what I meant with stacking. If you have more than one transformation sequence which includes rotations and translation and don't need the intermediate space after the first sequence, then you can combine both sequences in one matrix by just multiplying 2 4x4 matrices only once on the CPU. So you have to multiply your vertices by only a single matrix to get to the final destination. You can't do that with 3x3 matrixes. You always need to do something like this:
Final = R2 * (R1 * vert + T1) + T2
So you have to store 2 rotation matrices and 2 translation vectors and apply them to every single vertex. Therefore, you have to manage more data (even if you pack stuff in 4x4 matrices) and more computational effort when compared to a single 4x4 multiplication. Also, the code gets more bloated.
4 hours ago, bmarci said:
Yes, but why would I keep a copy if I can have everything at hand? ![:/ :/](https://uploads.gamedev.net/emoticons/medium.unsure.webp)
Usually, I don't store the copy but the actual inverse that I need. I just meant you don't need to keep everything separated just because you might want to do some inverse transformations.
4 hours ago, bmarci said:
With a pure 4x4 rotation matrix half of the operations will be multiplying numbers by zeros and adding them together.
You are right, that it is sometimes beneficial to use just 3x3 matrices if a 4x4 matrix doesn't give you any benefit. The best example is the normal-transformation matrix since normals need no translations. However, the performance gain is not as high as you might expect since vectorization gives you a lot of the necessary additional operations (really) for free. Usually, the small performance gain of 3x3 matrices is not relevant when compared to the savings of "stacking" multiple transformations in a single 4x4 matrix.
4 hours ago, bmarci said:
As I saw in the past, the performance doesn't always depend on the 2x faster low level function. I try to keep everything as simple as possible, that always helped me in the valley of darkness ![:) :)](https://uploads.gamedev.net/emoticons/medium.smile.webp)
As I said, if you don't need maximal performance for your game, it is totally fine to use whatever suits your needs. However, I have a different opinion on some things you mentioned. If you don't want to bother with the mathematical details of matrix operations, I can understand that. But I have to disagree that using 3x3 matrices produces less messy code or has any real advantage over 4x4 matrices. YMMV ![;) ;)](https://uploads.gamedev.net/emoticons/medium.wink.webp)
Greetings.