Archived

This topic is now archived and is closed to further replies.

kovacsp

How can this work? (BumpSelfShadow example)

Recommended Posts

Hi, This is a snippet from the BumpSelfShadow example of the DirectX SDK.
    D3DVERTEXELEMENT9 decl[] =
    {
        { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },  // v0

        { 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },   // v3

        { 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, // v7

        { 0, 32, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },  // v8

        D3DDECL_END()
    };
How can this work? I mean, why does offset 24 equals to v7? The vertex shader then realyy uses v7. I think this 24 should be 4*7= 28 instead. ( like 0*4=0, 3*4=12 and 8*4=32). But I must be wrong, because it does not work that way. So, how come this 24 <-> v7? Thanks for your help, kp

Share this post


Link to post
Share on other sites
The v register has nothing to do with the offset. The offset describes where in the vertex structure this data is.

You''ll notice that offset2 = offset1 + sizeof(type1)

In DX8 the register also goes in the declaration. In DX9 the register binding is part of the shader. Nothing in this declaration causes the use of v7. It''s either a comment meant as an aid to someone reading the shader, or it''s left over from the ancient times, or it''s the v register that the fixed pipe would have used back in DX8 for that data item. No matter what the reason the comment exists, you can ignore it.

Share this post


Link to post
Share on other sites
You mean this is the declaration that binds the texcoord to v7?
(This is from the vertex shader)

dcl_position v0
dcl_normal v3
dcl_texcoord v7
dcl_tangent v8


kp

Share this post


Link to post
Share on other sites