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 Sup Forums 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)
Sorry for recreating this thread, I got some responses that would have been useful with some elaboration last time, but my laptop briefly died and so did the thread.
Charles Mitchell
bump, i want a nice 3D programming thread too
Gavin Brooks
Canonical 3D graphics code seems to use projective geometry, which is no longer taught as a working subject. I believe this is done so as to enable translations to be performed as matrix rotations, but it feels like a bit of a hack.
I'm sure someone in the 1970s thought this was a good idea, but the rest of us are stuck with no real theory as to why we must do things this way.
Ryan Torres
Read up on linear algebra, affine geometry and projective geometry, in this order.
You should be able to understand most stuff afterwards
Ethan King
What's wrong with glm?
Hudson Lewis
So that's why no one seems to know how it's supposed to work?
It's a bad habit to apply something without learning it. If things like GLM didn't exist then the knowledge for how to do all this without libraries would be abundant, and GLM wouldn't be necessary. Really, whoever made GLM should have just made a tutorial instead, it's not like so much code goes into matrix transformations that a library is necessary. It's just that it's very hard to learn what to do.
Christopher Jackson
So what's what you don't understand, OP?
Luis Scott
Largely, what the vertex shader should look like if there is only one matrix passed into it (most people pass in three, which makes no sense performance-wise)
Julian King
If the question is about performance, then passing more uniform parameters is not too bad
If the question is about why three matrices, then it's because that's the way the model works. You have your projection, your view and your model. Passing in three matrices allows you to operate at the appropriate coordinate system (if you need to)
Benjamin Cox
I could definitely help but I don't want to do your homework. I took courses in uni that touched on this issue 100% hence how I know it's homework.
Julian Jackson
The question isn't about either, it's about how to do it with only one matrix passed into the vertex shader. Like, I'm pretty sure my way of setting gl_Position is wrong.
Luke Gray
That looks like an old shader variable...
Anyway, gl_Position = position.xyz/position.w should do it if your matrix is ok
Juan Campbell
Do you mean (position.xyz/position.w, 1.0)? And am I mistaken if I think that simply doing (position) is identical? Because I thought that gl_Position.xyz was divided by gl_Position.w, though that may be wrong.
Jose Diaz
oh I can't remember if gl_Position is a vec3 or a vec4
If it's a vec4, then simply doing gl_Position = YourMatrix * vec4(position, 1.0f); should do it
Jason Price
It's a vec4. And position is a vec4 too, a 1.0 is tacked onto the vertex position so it can be multiplied by the matrix since you can't multiply a mat4 with a vec3.
Jack Wright
STOP HELPING OP WITH HIS HOMEWORK! OMG GUYS, HOW THE FUCK ARE WE SUPPOSED TO GET SMARTER IF YOU KEEP HELPING US?
Jacob Powell
It's only really rotations and length that can be tricky. And it's not that tricky if you passed high school math.
Brandon Gomez
If I was taking this in university, I would have study notes available that would solve all my problems.
Easton Gonzalez
Just understand conceptually how a vector in 3d space can be rotated by multiplying the individual Cartesian components,
Then realise that an object in 3d space can be represented by multiple points as vectors,
The same individual rotation of a vector applies to all vectors in total rotating the object
Ryan Stewart
>let me explain to you the most basic details of the thing you have almost fully implemented Please consider deleting your Sup Forums account
Jonathan Peterson
I really don't know what this is supposed to mean, even as sarcasm.