Simple question, hopefully a simple answer.
Attribute data sent to Vertex Shaders are represented as a 4-dimension vector. In regards to representing positional data, the fields are typically named X, Y, Z, and W. My question concerns W.
By default, if no information is provided, an attribute contains:
[ 0, 0, 0, 1 ]
Why is there the difference in the fourth field with it defaulting to 1 and not 0 like the rest? Is it stylistic, mathematical, or some other reasoning?
There is no real cause of this question other than curiosity. Thank you for your time.
Because it’s the most generally useful value it could have.
If you’re sending a 3-element color (RGB), having the fourth component automatically filled in with 1 is really helpful. Similarly, if you’re sending a 3-vector position, the fourth component being 1 is useful for multiplying with 4×4 matrices.
The only time it’s a liability is with normals (or similar directions like tangents and bitangents) when you try to use them with 4×4 matrices.