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

This topic is 3794 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
3. 3
Rutin
15
4. 4
5. 5

• 10
• 9
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
633682
• Total Posts
3013314
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!