I'm trying to learn DirectX programming. Looking at different tutorials there is something about vertices that I find a bit confusing.

I know that DirectX uses vertices with four elements (x, y, z, w). I saw many tutorials (example http://msdn.microsoft.com/en-us/library/ff729721(v=VS.85).aspx) passing XMFLOAT3 as vertices positions omitting the w component.

How does this works? Assuming that passing XMFLOAT3 or XMFLOAT4 doesn't change DirectX behavior (true?) should I set the w to 1 in the vertex shader or does DirectX assume it to be 1 by default?

  • 1
    \$\begingroup\$ Duplicate of this stack overflow question. \$\endgroup\$ Commented Jan 13, 2015 at 23:58

1 Answer 1


Very good post thats explain it:


Just in few words: 3x3 matrix is not enough to represent translation (move vector to new place), it just enough for rotation, just for it every one using 4x4 matrices, and w term should be 1.0 if you want translation affect your vertex , otherwise only rotation will be applied.

Usually w term is omitted just assumed it 1.0 (not worth storing it for every vertex in mesh)

  • \$\begingroup\$ Yes but in the shader the vertex has till 4 components. Does directX initializes w to 1? \$\endgroup\$
    – Frabu
    Commented Jan 11, 2015 at 15:18
  • \$\begingroup\$ thats not really , vertex shader inputs can be very different, and you must decide how it use, just see: vertexShader is place where you must decide where on screen vertex to be shown. Actualy it can be any data. for lighting you will need even more vertex,normal,texture coordinats , and even more for bump mapping and rig. \$\endgroup\$ Commented Jan 11, 2015 at 15:26
  • \$\begingroup\$ VS_OUTPUT VS( float4 Pos : POSITION, float4 Color : COLOR ) it just example , you can supply any data you required, ommiting w is also leaves to shader \$\endgroup\$ Commented Jan 11, 2015 at 15:36
  • \$\begingroup\$ The question is two-fold: partly about how the API extends float3 vertex data to float4 variables; partly about how to extend float3->float3 data himself to be used with a 4x4 matrix. \$\endgroup\$ Commented Oct 9, 2015 at 14:51
  • \$\begingroup\$ Answers mostly consisting of a link are bad form on these sites. Make your question stand on its own so it survives the inevitable destruction of the linked content. \$\endgroup\$ Commented Oct 9, 2015 at 14:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .