ReoTempo
ReoTempo

Reputation: 324

DirectX - dimension of vertices passed to the vertex shader

I'm tryingto learn directX programming. Looking at different tutorials there is something about Vertices that i find a bit counfusing.

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 this works ? Assuming that passin XMFLOAT3 or XMFLOAT4 doesn't change DirectX behaviour (true? ) should i set the w to 1 in the vertex shader or DirectX assumes it to be 1 by default?

Upvotes: 1

Views: 92

Answers (1)

Chuck Walbourn
Chuck Walbourn

Reputation: 41077

The memory format of vertices is described by the Input Layout. To save space, one usually provides position as a 3-vector rather than a 4-vector with .w always set to 1.

D3D11_INPUT_ELEMENT_DESC[] =
{
    { "SV_Position", 0, DXGI_FORMAT_R32G32B32_FLOAT,    0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
...
};

Any element not specified by the input layout is usually assumed to be 0, but in HLSL the macros for things like mul(float3,float4x4) already know to make the .w an implicit 1.

You should take a look at VertexTypes.h in the DirectX Tool Kit for various examples.

Upvotes: 1

Related Questions