Just started reading the shader wiki and noticed that vertex potions are represented by a float4 variable.
I can guess the first 3 are XYZ but what’s the 4th float component for?
Wikipedia tells me that it’s common to represent a vertex with XYZ plus a 4th “homogeneous coordinate”
But the wikipedia page on homogenous coordinates is heavy on math
and does not directly explain what it means in the context of a vertex coordinate.
I am not sure this is more readable, but the OpenGL redbook says:
“After transformation, all transformed vertices are clipped so that x, y, and z are in the range [-w, w] (assuming w > 0). Note that this range corresponds in euclidean space to [-1.0, 1.0].”
So W determines the clip space range.
Generally you set this to 1.0 so you can the correct (clip space) values when multiplying with a float4x4 matrix such as the world matrix.
I haven’t tried, but I think the vertex would move to or away from the origin if you change this value.
I don’t think it is very easy to explain in a simpler way since the math behind 3d transformations and projections back to 2d screen aren’t all that simple
Asked around and found some other explanations.
the simplest one that made sense is:
Adding a 4th homogeneous coordinate to XYZ makes allows rotation, scaling and esp translation to use a single 4x4 matrix multiplication operation. Without it, Translation would require a seperate operation.