Hey Guys,

I've come across a strange problem in DirectX 10 that I would really appreciate some help with:

When trying to render ID3DX10Mesh objects that use a particular input layout, the vertex data seems to alter slightly before the object is passed to the vertex shader. I have been trying to pinpoint the exact location of the data alteration but with no luck.

Now for the strange part!
When the exact same data is used with a different input layout OR the same layout but manually creating ID3D10Buffers, everything works fine :o

I know that this is not an issue with my shader file because Pix shows the mesh data incorrect before it even reaches the vertex shader. I also ensured that I changed the CreateMesh function to account for the change of input layout.

Here is the layout that doesn't work:

D3D10_INPUT_ELEMENT_DESC vertexDesc[] = 
{
    { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0,  0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
    { "NORMAL",   0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 },
    { "DIFFUSE", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0 },
    { "SPECULAR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 36, D3D10_INPUT_PER_VERTEX_DATA, 0 }
};

Here is the layout that does work:

D3D10_INPUT_ELEMENT_DESC vertexDesc[] = 
{   
    { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
    { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }
};

Finally, here is an example snippet of code (for a cube object) that stops working correctly when using the first input layout:

m_numVertices = 8;
m_numFacets = 12;

/* Setup cube vertex data */
Vertex vertices[8];

vertices[0] = Vertex( TVec3f( -1, 1, -1 ), PURPLE);
vertices[1] = Vertex( TVec3f(1,1,-1),PURPLE);           //front top right
vertices[2] = Vertex( TVec3f(-1,-1,-1),PURPLE);         //front bottom left
vertices[3] = Vertex( TVec3f(1,-1,-1),PURPLE);          //front bottom right
vertices[4] = Vertex( TVec3f(-1,1,1),PURPLE);           //back top left
vertices[5] = Vertex( TVec3f(1,1,1),PURPLE);            //back top right
vertices[6] = Vertex( TVec3f(-1,-1,1),PURPLE);          //back bottom left
vertices[7] = Vertex( TVec3f(1,-1,1),PURPLE );          //back bottom right

UINT indices[36] = { 2,0,3,0,1,3,                           
                     3,1,7,1,5,7,                           
                     6,4,2,4,0,2,                       
                     7,5,6,5,4,6,                           
                     0,4,1,4,5,1,                           
                     6,2,7,2,3,7 };

// Create mesh
HR( D3DX10CreateMesh( m_pd3dDevice, vertexDesc, 4, "POSITION", 8, 12, D3DX10_MESH_32_BIT, &m_pMeshData ) );
HR( m_pMeshData->SetVertexData( 0, vertices ) );
HR( m_pMeshData->SetIndexData( indices, m_numFacets*3 ) );
HR( m_pMeshData->CommitToDevice() );

Any help would be greatly appreciated :)

Try D3DXMatrixRotationY, it works for me, or D3DXMatrixRotationAxis, if u don't want rotation on
rotAxis then put angle 0.0f, hope this helps.

I you mean alter as a loop, I had that problem to, try D3DXMatrixTranslation oh yaa it also works with cameras, define a constant point(if you want him to move use float x,y,z instead of 0.0f,0.0f,0.0f)

`D3DXMatrix mov;`
`D3DXMatrixTranslation(&mov,0.0f,0.0f,0.0f);
`matWorld = mov * matWorld;``

It could be your camera thats moving too, so you should be alert.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.