i have a problem displaying an md5mesh. I believe, that the loading code is functional. My clue is, that my shadercode is wrong or the vertexinputlayout.
Here is the code, in which i am creating the buffers, the inputlayout and vertexbinding.
public void PreRender(Device device) { // ====== Need to be optimized ======= /* * * * * * * * * * * * * * * * * * * */ /* create index buffer */ /* * * * * * * * * * * * * * * * * * * */ int counter = 0; int[] tmpIndices = new int[m_Mesh.Triangles.Length * 3]; for (int i = 0; i < m_Mesh.Triangles.Length; ++i) { tmpIndices[counter++] = m_Mesh.Triangles.vertIndex0; tmpIndices[counter++] = m_Mesh.Triangles.vertIndex1; tmpIndices[counter++] = m_Mesh.Triangles.vertIndex2; } using (var data = new DataStream(tmpIndices, true, false)) { indices = new Buffer(device, data, new BufferDescription() { BindFlags = BindFlags.IndexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = tmpIndices.Length * 4, Usage = ResourceUsage.Default }); } /* * * * * * * * * * * * * * * * * * * */ /* create vertex buffer */ /* * * * * * * * * * * * * * * * * * * */ using (var data = new DataStream(m_Mesh.Vertices, true, false)) { vertices = new Buffer(device, data, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = m_Mesh.Vertices.Length * Marshal.SizeOf(typeof(SMD5Vertex)), Usage = ResourceUsage.Default }); } elements = new InputElement[] { new InputElement("INDEX", 0, Format.R32_SInt, 0, 0), new InputElement("UVCOORD", 0, Format.R32G32_Float, 0, 1), new InputElement("STARTWEIGHT", 0, Format.R32_SInt, 0, 2), new InputElement("COUNTWEIGHT", 0, Format.R32_SInt, 0, 3), new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 4), new InputElement("COLOR", 0, Format.R8G8B8A8_UNorm, 0, 5), }; effect = Effect.FromFile(device, "MD5Model.fx", "fx_4_0", ShaderFlags.None, EffectFlags.None, null, null); layout = new InputLayout(device, effect.GetTechniqueByIndex(0).GetPassByIndex(0).Description.Signature, elements); binding = new[] { new VertexBufferBinding(vertices, Marshal.SizeOf(typeof(SMD5Vertex)), 0), }; }
The Vertex struct:
[StructLayout(LayoutKind.Sequential)]struct SMD5Vertex{ public int index; public SUVCoord UVCoord; public int startWeight; public int countWeight; /// <summary> /// Is calculated later /// </summary> public Vector3 FinalPosition; public int Color;}
And here is the shader-code:
float4x4 view;float4x4 proj;float4x4 world;float4 defaultColor;struct VS_IN{ int index : INDEX; float2 UVCoord : UVCOORD; int startWeight : STARTWEIGHT; int countWeight : COUNTWEIGHT; float3 pos : POSITION; float4 col : COLOR;};struct PS_IN{ float4 pos : SV_POSITION; float4 col : COLOR;};PS_IN VS( VS_IN input ){ PS_IN output = (PS_IN)0; float4x4 worldViewProj = mul(mul(world, view), proj); output.pos = mul(input.pos, worldViewProj); return output;}float4 PS( PS_IN input ) : SV_Target{ return defaultColor;}technique10 RenderSolid{ pass P0 { SetGeometryShader( 0 ); SetVertexShader( CompileShader( vs_4_0, VS() ) ); SetPixelShader( CompileShader( ps_4_0, PS() ) ); }}
Thanks in advance