0
\$\begingroup\$

For some reason, only back-faces are rendering, even if I set the rasterizer and stencil buffer and state to any values. Setting D3D11_CULL_NONE, D3D11_CULL_FRONT, D3D11_CULL_BACK in the rasterizer structure has the same result.

This is how rendering is supposed to look (The code somehow works in the side project that was made using the Direct3D Win32 Game Visual Studio template):

The model I'm rendering is loaded using DirectX::Model::CreateFromCMO(). I'm using left hand projection and view matrices.

Cup model that's properly rendered

This is how it looks inside my project:

Cup model that seems to have backfaces being rendered

I'm using the DirectXTK library to draw the sup model itself in both projects. I'm pretty sure that the graphics device, context and swap chain are properly created. I tried copying code from the second project to the first project but I somehow still managed not to fix it.

I'm also sure that the DirectX::CommonStates does contain it's own rasterizer and stencil state, but I don't understand how rendering doesn't work on my own project.

The debug layer is not displaying any errors or warnings at run-time related to the creating of the rendertargets, device, texture buffers, etc.

My only idea remaining is that the stencil buffer is wrongly configured, but I can't find what I did wrong here. The stencil state description is taken from MSDN (this link): https://docs.microsoft.com/en-us/windows/win32/direct3d11/d3d10-graphics-programming-guide-depth-stencil

The main project source is here (I won't post pieces of the code because that would take a lot of time and space, there are like 300+ lines of code related to the rendering pipeline) : https://github.com/NicusorN5/3D_Rad_Space/tree/master/3DRadSpace

To mention that you can't compile the project by your own because Resources.rc is set to load files from a non-local (i.e some folder on my secondary HDD) path, and because of some dependencies that are also located in non-local paths. Sorry for that.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

The Model draw method is setting the Rasterizer state as part of the standard setup. If you want to override the state at draw time, you can use custom drawing callbacks per the wiki.

You didn't mention if this model is CMO or SDKMESH or if you are using right-handed or left-handed viewing coordinates. You look like you've mixed those up in some fashion.

For DirectX Tool Kit for DX11 the way to control the winding of Model is to provide a ModelLoaderFlag to Model::CreateFrom*.

You are likely using the defaulted parameter. Try the opposite flag:

static std::unique_ptr<Model> CreateFromCMO(
    ID3D11Device* device,
    const wchar_t* szFileName,
    IEffectFactory& fxFactory,
    ModelLoaderFlags flags = ModelLoader_CounterClockwise,
    size_t* animsOffset = nullptr
static std::unique_ptr<Model> CreateFromSDKMESH(
    ID3D11Device* device,
    const wchar_t* szFileName,
    IEffectFactory& fxFactory,
    ModelLoaderFlags flags = ModelLoader_Clockwise);

These are setup assuming right-handed viewing and the model was exported with 'traditional winding' (SDKMESH usually assumes left-handed viewing). If you are using left-handed viewing, then you need to flip them. Again, see the wiki.

\$\endgroup\$
2
  • \$\begingroup\$ I updated the post. Indeed, I'm using the CMO format and I'm using left hand matrices for rendering. I didn't know that the nature of the rendering matrices would affect rendering that way. I updated the code to use right hand matrices and now it seems to work. I think you nailed it! Thanks! \$\endgroup\$
    – NicusorN5
    Oct 26, 2021 at 0:04
  • \$\begingroup\$ You can use left-handed matrices, but with CMO you'd need to pass ModelLoader_Clockwise. That said, if your model textures have any text on them it would look backward. \$\endgroup\$ Oct 26, 2021 at 1:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .