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 :)