Vertex Shader Question, what is the w value for in position?

This topic is 3624 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi, I have a question about vertex shaders. Why is it that the position in a vertex shader is passed in as a float4 and not a float3? What is the w-value for? Reason for this is that I'm trying to pack a position value in a 4 byte color value, this would be possible because the position only has a very limited range. But I'm not sure what the w value should be once I unpack it. I'm getting view-transformation problems and I'm not sure if that's because of the w-value. Thanks in advance, Peter

Share on other sites
An OpenGL matrix looks like this:

R R R TR R R TR R R T0 0 0 1

R is the portion containing the perpendicular basis vectors (how the X, Y and Z axes are rotated), and T is the translation along all three axes.

Since you can not multiply a 4x4 matrix with a 3x1 matrix (vector), you'll need one extra component (called W).

R R R T   VR R R T * VR R R T   V0 0 0 1   1

If you set this fourth component to 0, you'll get no translation. If you set it to 1, you'll get the translation contained in the matrix.

Share on other sites
The math behind it was answered pretty easily above.

The w entry is frequently used to denote vectors rather than points. If you want the tuple to be transformed but not translated, which is the case with a vector which has no origin, set the value to 0.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 15
• 13
• 9
• 12
• 10
• Forum Statistics

• Total Topics
631440
• Total Posts
3000080
×