尝试使用TriangleStrip Topologu创建三角形时的奇怪行为 [英] Odd behaviour when trying to create triangle using TriangleStrip Topologu

查看:194
本文介绍了尝试使用TriangleStrip Topologu创建三角形时的奇怪行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在输入装配器设置为三角形条的情况下创建此2D三角形:

I tried to create this 2D triangle in with the Input Assembler set to triangle strip:

1.(0.0f, 0.0f, 0.5f)
2.(-0.5f, 0.0f, 0.5f)
3.(-0.5f, -0.5f, 0.5f)

但是,没有绘制任何三角形,实际上在渲染目标上没有绘制任何内容,甚至没有绘制任何线条.我弄乱了,然后交换了坐标23,它起作用了.三角形是按照我的预期绘制的.这种奇怪行为的原因是什么?

However, no triangle was drawn, in fact nothing was drawn on the render target, not even a single line. I messed around, and then I swapped coordinates 2 and 3, and it worked. The triangle was drawn just as I intended it to be. What is the reason for this odd behaviour?

推荐答案

您以逆时针顺序定义顶点,而Direct3D默认情况下将以逆时针顺序定义剔除面,因此三角形是在背面剔除的剔除,因此您一无所获.

You define your vertex in counter-clockwise order, and Direct3D will cull faces define in counter-clockwise order by default, so your triangle was culled during back-face culling, thus you got nothing rendered.

在DirectX中绘制三角形时,应该考虑两件事.

You should consider two things when you drawing a triangle in DirectX.

  1. 您定义顶点的顺序.
  2. 当前使用的剔除模式.

定义顶点的顺序决定了正面和背面.正面是按顺时针顺序定义顶点的面,请尝试按顺时针顺序定义顶点.

The order how you defined your vertices determines the front face and the back face. A front face is one in which vertices are defined in clockwise order, try to define your vertex in clockwise order.

正面和顶点法线

剔除模式指定如何剔除背面三角形,请尝试使用D3D11_CULL_NONE来测试您的代码,这将确保无论顶点的定义顺序如何,都会渲染每个三角形.

The culling mode specifies how back-facing triangles are culled, try using D3D11_CULL_NONE to test your code, this will make sure every triangle will be render regardless the definition order of the vertices.

消隐状态

为DirectX11

绘制三角形带时应格外小心,因为在偶数三角形上背面剔除标记会自动翻转.考虑下图.对于第一个三角形v1v2v3,消隐模式是逆时针的,它将被渲染;对于第二个三角形v2v3v4,消隐模式是逆时针的,也将被渲染.对于第三个三角形,消隐模式又变回以此类推.如果要渲染这样的三角带,则应按以下顺序定义顶点:v1,v2,v3,v4,... vn.

You should take care when drawing triangle strips, since the backface-culling flag is automatically flipped on even-numbered triangles. consider the following picture. for the first triangle v1v2v3, the culling mode is counterclock-wise, it will be rendered, for the second triangle v2v3v4, the culling mode flipped to clockwise, it will be rendered too. and for the third triangle, the culling mode change back again, and so on. if you want to render such a triange strip, you should define the vertices in this order: v1, v2, v3, v4, ... vn.

三角形条

这篇关于尝试使用TriangleStrip Topologu创建三角形时的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆