Jump to content
  • Advertisement
Sign in to follow this  
PeterV

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
An OpenGL matrix looks like this:


R R R T
R R R T
R R R T
0 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 V
R R R T * V
R R R T V
0 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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!