Jump to content

  • Log In with Google      Sign In   
  • Create Account

MD5 model rendering problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 proanim   Members   -  Reputation: 440

Like
0Likes
Like

Posted 24 October 2012 - 05:03 PM

I menaged to implement md5 models in one of rastertek samples for dx 11, I can load model and animation and update animation. But i can't get it rendered. My rendering function for md5 is

[source lang="cpp"]void MD5ModelClass::Render(ID3D11DeviceContext* deviceContext, Model3D model){ stride = sizeof(Vertex); offset = 0; for(int i = 0; i < Model1.numSubsets; i ++) { deviceContext->IASetIndexBuffer(Model1.subsets[i].indexBuff, DXGI_FORMAT_R32_UINT, 0); deviceContext->IASetVertexBuffers( 0, 1, &Model1.subsets[i].vertBuff, &stride, &offset ); deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); deviceContext->DrawIndexed( Model1.subsets[i].indices.size(), 0, 0 ); } return;}[/source]

no matter where i put DrawIndexed i get 'driver has stopped working and has recoverd' crash, if DrawIndexed is not included i can't get anything to render. In both cases program comiles without warnings or errors.

Can someone help with this, there is not much info on how to correctly implement md5 models with directx 11?

Sponsor:

#2 proanim   Members   -  Reputation: 440

Like
0Likes
Like

Posted 27 October 2012 - 07:33 AM

I still can't fix this problem, should i upload my project or relevant files so somebody can help with this? I have no idea how to fix this. I tried debugging but model and animation load fine and then driver crashes on DrawIndexed, i don't know why is this.

#3 n3Xus   Members   -  Reputation: 704

Like
0Likes
Like

Posted 27 October 2012 - 07:46 AM

Driver crash means that you didn't initialize something correctly, check if your buffers actually have the required amount of data in them.

And use the debug feature of D3D: it probably tells you what went wrong just before the crash in the Output window.

#4 proanim   Members   -  Reputation: 440

Like
0Likes
Like

Posted 27 October 2012 - 11:10 AM

ok this is officially insane Posted Image , i am getting this in debugger

D3D11: WARNING: ID3D11DeviceContext::DrawIndexed: Index buffer has not enough space! [ EXECUTION WARNING #359: DEVICE_DRAW_INDEX_BUFFER_TOO_SMALL ]

now the code i am using is copy/paste from tutorials, the man that wrote md5 tutorials made them functional but entire code is in one file! so i took functions that are relevant for md5 stuff and put them together with rastertek tutorial with 3d cube.

this is creation of the buffers from md5 tutorials

[source lang="cpp"]// Create index buffer D3D11_BUFFER_DESC indexBufferDesc; ZeroMemory(&indexBufferDesc, sizeof(indexBufferDesc)); indexBufferDesc.Usage = D3D11_USAGE_DEFAULT; indexBufferDesc.ByteWidth = sizeof(DWORD) * subset.numTriangles * 3; indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; indexBufferDesc.CPUAccessFlags = 0; indexBufferDesc.MiscFlags = 0; D3D11_SUBRESOURCE_DATA iinitData; iinitData.pSysMem = &subset.indices[0]; device->CreateBuffer(&indexBufferDesc, &iinitData, &subset.indexBuff); //Create Vertex Buffer D3D11_BUFFER_DESC vertexBufferDesc; ZeroMemory(&vertexBufferDesc, sizeof(vertexBufferDesc)); vertexBufferDesc.Usage = D3D11_USAGE_DYNAMIC; // We will be updating this buffer, so we must set as dynamic vertexBufferDesc.ByteWidth = sizeof(Vertex) * subset.vertices.size(); vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; vertexBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; // Give CPU power to write to buffer vertexBufferDesc.MiscFlags = 0; D3D11_SUBRESOURCE_DATA vertexBufferData; ZeroMemory(&vertexBufferData, sizeof(vertexBufferData)); vertexBufferData.pSysMem = &subset.vertices[0]; hr = device->CreateBuffer(&vertexBufferDesc, &vertexBufferData, &subset.vertBuff);[/source]

in rastertek tutorials you render object with shader like this

[source lang="cpp"]// render the model using color shader result = m_ColorShader->Render(m_D3D->GetDeviceContext(), m_md5->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix); if(!result) return false;[/source]

all tutorials were working in their original state and nothing was changed here. how can i get correct number of indices to fix this. I tried with

[source lang="cpp"]int MD5ModelClass::GetIndexCount(){ return sizeof(DWORD) * subset.numTriangles * 3; //return Model1.subsets.size(); //return numVerts;}[/source]

first return is original from md5 tutorial it also returns driver crash and debug warning? please help!

#5 n3Xus   Members   -  Reputation: 704

Like
2Likes
Like

Posted 27 October 2012 - 02:13 PM

That function int MD5ModelClass::GetIndexCount(){...} is wrong: it returns the size of the indices buffer in bytes.

It should return just 'subset.numTriangles * 3' (if you multiply that by DWORD (which is 4) you are trying to draw 4 times as many indices as there actually are).

#6 proanim   Members   -  Reputation: 440

Like
0Likes
Like

Posted 27 October 2012 - 03:08 PM

ok step forward, but now when placing break point on for loop from the first post it breaks with this

D3D11: ERROR: ID3D11DeviceContext::DrawIndexed: A Vertex Shader is always required when drawing, but none is currently bound. [ EXECUTION ERROR #341: DEVICE_DRAW_VERTEX_SHADER_NOT_SET ]
D3D11: ERROR: ID3D11DeviceContext::DrawIndexed: Rasterization Unit is enabled (PixelShader is not NULL or Depth/Stencil test is enabled and RasterizedStream is not D3D11_SO_NO_RASTERIZED_STREAM) but position is not provided by the last shader before the Rasterization Unit. [ EXECUTION ERROR #362: DEVICE_DRAW_POSITION_NOT_PRESENT ]

now the entire shader implementation is rastertek sample nothing is changed except i put together vs and ps files from tutorial into one so it looks like this

[source lang="cpp"]////////////////////////////////////////////////////////////////////////////////// Filename: color.hlsl/////////////////////////////////////////////////////////////////////////////////////////////// GLOBALS ///////////////cbuffer MatrixBuffer{ matrix worldMatrix; matrix viewMatrix; matrix projectionMatrix;};//////////////// TYPEDEFS ////////////////struct VertexInputType{ float4 position : POSITION; float4 color : COLOR;};struct PixelInputType{ float4 position : SV_POSITION; float4 color : COLOR;};////////////////////////////////////////////////////////////////////////////////// Vertex Shader////////////////////////////////////////////////////////////////////////////////PixelInputType ColorVertexShader(VertexInputType input){ PixelInputType output; // change the position vector to be 4 units for proper matrix calculations input.position.w = 1.0f; // calculate the position of the vertex against the world, view, and projection matrices output.position = mul(input.position, worldMatrix); output.position = mul(output.position, viewMatrix); output.position = mul(output.position, projectionMatrix); // store the input color for the pixel shader to use output.color = input.color; return output;}////////////////////////////////////////////////////////////////////////////////// Pixel Shader////////////////////////////////////////////////////////////////////////////////float4 ColorPixelShader(PixelInputType input) : SV_TARGET{ return input.color;}[/source]

i looked around the net there is very little on this some are pointing on missing semantics in the code like : COLOR but the shader works no problem with triangle sample, so how can i fix this?

#7 n3Xus   Members   -  Reputation: 704

Like
0Likes
Like

Posted 27 October 2012 - 05:33 PM

You should look more into Direct3D before you continue to go on with what you're doing now, otherwise you wil be making a lot more posts like this.

For your problem: ID3D11DeviceContext::VSSetShader must be called to set the vertex shader, this is also why you are getting the second warning (..position is not provided by the last shader...)

#8 proanim   Members   -  Reputation: 440

Like
0Likes
Like

Posted 27 October 2012 - 06:30 PM

I have that function, as i said entire shader portion of the program is rastertek tutorial copy/paste see attachment. I know rules of the forum and the things like 'we wont write code for you' but this is different. Take a look at the project to see the problem, hopefully someone will tell me the solution to this?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS