0

I am having alot of struggles trying to follow Frank Luna's book for DirectX 11 3D Programming, and I am currently up to chapter 7 section 2. I have imported the Skull model file and I have begun to render it. The strange thing is that when I am rendering it, it appears to be rendering the back faces over the front facing faces. I am pretty sure this is the case of what is happening. But I am putting forth this question for help and guidance on where I may be going wrong. I will edit this post with inclusions of my code if required to help me figure out where I am going wrong, Thanks alot! (photo's attached)

Photo - Facing the Skull, Slightly to the Left

Photo - Above the Skull, Facing Downwards

EDIT: I have set a breakpoint in my code for after the first draw call loop and it does not show any faces which are behind the fronts ones, so issue is solved at this frame, but when I continue to the next frame, this is when the problems start.

Sharpie
  • 113
  • 8
  • Does that model look the same when you modify it's z transformation (move it further)? What value did you specify for near plane and far plane of your frustum? – Asesh Sep 08 '17 at 08:59
  • It looks like you've set incorrect culling mode when configuring [rasterizer description](https://msdn.microsoft.com/en-us/library/windows/desktop/ff476198(v=vs.85).aspx). – user7860670 Sep 08 '17 at 09:03
  • I am using XMMatrixLookAtLH, should I implement XMMatrixPerspectiveLH? – Sharpie Sep 08 '17 at 09:04
  • @VTT I have tried to change the rasterizer description but those pictures are default with no rasterizer state changes – Sharpie Sep 08 '17 at 09:05
  • After you create rasterizer state you need to apply it for rending pipeline by calling `RSSetState` before drawing mesh. Culling mode switches should be clearly visible. On the other hand this also looks like no depth testing is being performed: look from above suggests that you draw skull first and then teeth on top - if there was a depth test then teeth wouldn't be visible even with incorrect culling. – user7860670 Sep 08 '17 at 09:10
  • @VTT well thats the thing i have not even implemented a rasterizer desc to change the rasterization process at all. Those pictures are completely default in relation to the rasterization process. – Sharpie Sep 08 '17 at 09:12
  • I have a depth buffer which has been set and every draw call is cleared with: mDevContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); – Sharpie Sep 08 '17 at 09:14
  • But are you binding it correctly to make depth test to work? You may want to take a look at [Configuring Depth-Stencil Functionality](https://msdn.microsoft.com/en-us/library/windows/desktop/bb205074(v=vs.85).aspx). – user7860670 Sep 08 '17 at 09:18

2 Answers2

0

These kinds of problems are sometimes related to the setup of the CullMode in the D3D11_RASTERIZER_DESC. Try changing from D3D11_CULL_BACK to D3D11_CULL_FRONT or vice versa. Also have a look at the FrontCounterClockwise option of the D3D11_RASTERIZER_DESC.

nh_
  • 2,211
  • 14
  • 24
0

I figured out what had been causing my grief. I have been using DirectXToolKits SpriteFont and SpriteBatch class's to use the function DrawString to display an FPS counter at the top left corner of the screen, and it must have been messing around with the ID3D11DeviceContext::DrawIndexed calls. Thankyou for all your input and brainstorming!!

Sharpie
  • 113
  • 8
  • You should look at the [wiki](https://github.com/Microsoft/DirectXTK/wiki/SpriteBatch#state-management) for exactly which states ``SpriteBatch`` sets. You should make sure to set any state you rely on, and clear any 'uncleared' stated that would cause problems. – Chuck Walbourn Sep 09 '17 at 23:46
  • Thanks for the input I'm currently trying to work on a solution – Sharpie Sep 10 '17 at 14:25