Vertex Winding Order in DX11

断了今生、忘了曾经 提交于 2019-12-24 05:49:10

问题


I'm trying to draw a simple square with dx11, but the order of the indices of each triangle determines whether or not it shows up. I set the cull mode to none in the rasterizer state, but it doesn't seem to change anything.

If I specify the vertices of the first triangle to be 0, 1, 2 instead of 2, 1, 0 then the triangle doesn't show up. So my question is, do I need to order the vertices of a triangle in a specific way regardless of the cull mode?

P.S. I'm drawing a triangle list and not a strip.

UINT indices[] = {2, 1, 0, 
                  1, 3, 0};


MeshVertex vertices[] = 
{
    { Vector3(1.0f, 1.0f, 0.0f)}, //Top Right
    { Vector3(-1.0f, -1.0f, 0.0f)}, //Bottom Left
    { Vector3(1.0f, -1.0f, 0.0f)}, //Bottom Right
    { Vector3(-1.0f, 1.0f, 0.0f)} //Top Left
};

mesh = new Mesh(vertices, indices, 4, 6, shader);

回答1:


So my question is, do I need to order the vertices of a triangle in a specific way regardless of the cull mode?

** Define/Draw your vertices in clockwise order, and don't change the default the cull mode.**

To determine whether a triangle can be displayed, you have to considering 2 factors

  1. The front face, or you call it winding order, by default Direct3D treat a vertices defined in clockwise order as a front face, and all faces other than front faces are back faces.
  2. The culling mode, by default, Direct3D will cull the back faces(the faces which vertices defined in counter-clockwise order).

You can set the front face and culling mode in D3D11_RASTERIZER_DESC structure

The reason why you didn't see difference when you change the culling mode to NONE is because both triangle were in the same order and D3D11_CULL_NONE means didn't cull any faces.

If triangle 1 is in clockwise order and triangle 2 is in counter clockwise order, you will only see one triangle when you set the cull mode to D3D11_CULL_FRONT or D3D11_CULL_BACK, and see both when you set it to D3D11_CULL_NONE.



来源:https://stackoverflow.com/questions/23790272/vertex-winding-order-in-dx11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!