I have never been able to find an explanation of transformation matrices in 3D graphics that doesn't use specialised libraries and doesn't use coding practices of questionable efficiency.
So I tried making my own, but it makes no sense, yet it almost works.
Anyone on /g/ thinks it's redeemable?
Every frame:
>create camera matrix, starting with a translation matrix
>multiply by z rotation matrix, then x, then y
>translate by (0, 0, -1) (so that when the camera rotates, it doesn't rotate around a point in front of the camera)
>multiply by projection matrix, which is as shown
Every frame, per object:
>create object matrix, starting with a scale matrix
>multiply by x rotation matrix, then y, then z
>multiply by translation matrix
>multiply with camera matrix to get the transformation matrix
In vertex shader:
>create vec4 "position" by multiplying the transformation matrix with the vertex position (since it's a vec3, 1.0 is tacked on the end)
>define gl_Position in either of the following ways
>gl_Position = vec4(position.xy/position.w, position.z, 1.0) (causes layering issues and vertices behave weirdly as they go offscreen)
>gl_Position = position (cutoffs are no longer the near and far defined by the camera)
It sounds pretty close. It's been a while since I've touched graphics so this is mostly just a bump but I wonder how much of that per frame per object stuff can be cached and how good time/space savings would be.
>>58858968
If I get this fully working, I could test that.
By the way, I should add that "questionable efficiency" includes stuff like passing three matrices into the vertex shader.
That's promoting a per-frame multiplication (camera x projection) to per-vertex, and a per-object multiplication (object x whatever) to per-vertex.
Maybe I should look up Vulkan tutorials, since it's rather new it shouldn't be full of bad practices that have been passed from person to person.
>>58857102
Everything you posted sounds fine. What are you having trouble with? The projection?
Projection isn't a linear transform so the 4x4 matrix thing is a bit of a hack to make it work. You don't actually have to do it with a matrix, the simplest projection is just to divide x and y by z at the end.
The w coordinate is called the homogeneous vertex coordinate. It's kind of a hack to be able to put translation and projection in, which are both not linear transforms on Euclidean geometry.
You're using 4x4 matrices everywhere, right?
Also, the correct normalization for a vec4 is to divide all components by w, including z. This might explain your layering issues.
Aren't you supposed to use quaternions for rotation?
>>58864824
Yes, but you can't compose them with translation, scale, and projection like you can with a 4x4 matrix.
lol, low level 3d coding, good luck doing the work for anything that matters unless you have a team of 200,000 people.