Sign in to follow this  
davidx9

Understanding D3DVERTEXELEMENT9

Recommended Posts

I am building a rendering engine, and need to take advantage of multiple vertex streams. I have two vertex buffers, one with x and z coords, and one with y(height) and normal data. My two vertex formts are struct xGridVertex { D3DXVECTOR2 pos; //XZ coords FLOAT tu, tv; }; #define D3DFVF_GRIDVERTEX (D3DDECLTYPE_FLOAT2|D3DFVF_TEX1) struct xSectionVertex { FLOAT height; // Y coord D3DXVECTOR3 normal; }; #define D3DFVF_SECTIONVERTEX (D3DDECLTYPE_FLOAT1|D3DFVF_NORMAL) and my D3DVERTEXDECLARATION9 is static D3DVERTEXELEMENT9 vertex_description[] = { {0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, {0, 8, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0}, {1, 0, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 1}, {1, 4, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0}, D3DDECL_END() }; Now my main question is... How do I instruct the pipeline to convert the xy data in stream 0 into xz data, and then combine the solitary height value in stream 1 as the y component? Secondly, is this the correct way to render such a situation? hr = pDevice->SetVertexDeclaration(vertex_dec); hr = pDevice->SetStreamSource(0, vb_grid, 0, sizeof(xGridVertex)); hr = pDevice->SetStreamSource(1, vb_heights, 0, sizeof(xSectionVertex)); hr = pDevice->SetIndices(ib_section_grid); D3DXMATRIXA16 matWorld; D3DXMatrixIdentity(&matWorld); pDevice->SetTransform(D3DTS_WORLD, &matWorld); hr = pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP, 0, 0, 32*32, 0, 32*32*2);

Share this post


Link to post
Share on other sites
Quote:
Original post by Zipster
I believe you'll need to write a simple vertex shader in order to accomplish what you want. At least, if you have any special usages (as you do with a second position element).


Thank you very much, I had a feeling that might be the solution, but I was trying the old fixed function method.

Vertex shader will give me more flexibility anyway. Thanx.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this