DirectX:“透视”多边形
我创建了一个简单的 DirectX 应用程序来渲染顶点字段。顶点渲染如下(如果从顶部查看):
|\|\|\|\|
|\|\|\|\|
每个三角形渲染如下:
1
|\
2 3
这应该意味着多边形是逆时针的并且不会被渲染,但它确实如此。无论如何,从顶部看,飞机是完美的。
然而,当从另一个层面观察时,某些多边形是透明的,您可以看到它们后面的几何图形。我已经强调了一些发生这种情况的地方。
我认为这是一些基本的初学者问题。我缺少什么?我的光栅器描述是这样的:
new RasterizerStateDescription
{
CullMode = CullMode.Front,
IsAntialiasedLineEnabled = true,
IsMultisampleEnabled = true,
IsDepthClipEnabled = true,
IsFrontCounterclockwise = false,
IsScissorEnabled = true,
DepthBias = 1,
DepthBiasClamp = 1000.0f,
FillMode = FillMode.Wireframe,
SlopeScaledDepthBias = 1.0f
};
I've created a simple DirectX app that renders a field of vertices. Vertices are rendered like this (if viewed from top):
|\|\|\|\|
|\|\|\|\|
Each triangle is rendered like this:
1
|\
2 3
Which should mean that the polygon is counterclockwise and not be rendered, but it is. Anyway when viewed from top the plane is perfect.
However, when viewed from another level some polygons are sort of transparent and you can see geometry behind them. I've highlighted some of the place where this is happening.
I am thinking this is some of the basic, beginner problems. What am I missing? My rasterizer description is such:
new RasterizerStateDescription
{
CullMode = CullMode.Front,
IsAntialiasedLineEnabled = true,
IsMultisampleEnabled = true,
IsDepthClipEnabled = true,
IsFrontCounterclockwise = false,
IsScissorEnabled = true,
DepthBias = 1,
DepthBiasClamp = 1000.0f,
FillMode = FillMode.Wireframe,
SlopeScaledDepthBias = 1.0f
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是设计使然。
FillMode.Wireframe
仅将每个三角形的边缘绘制为线。就这样。使用实体填充模式和深度写入以及颜色遮罩(D3D11 术语中的 RenderTargetWriteMask)执行第一遍,并使用深度测试(但深度写入关闭)和线框模式执行第二遍。您可能还需要深度偏差,因为直线和三角形的光栅化方式不同(并且它们的 z 在相同的片段位置可能不同)。
顺便说一句,这种技术称为隐藏线去除。您可以检查 此演示文稿了解更多详细信息。
This is by design.
FillMode.Wireframe
only draws edges of each triangle as lines. That's all.Do a first pass with a solid fill mode and depth writes on and a color mask (
RenderTargetWriteMask
in D3D11 terminology), and a second one with depth test on (but depth writes off) and wireframe mode on. You will probably need depth bias too since lines and triangles are not rasterized the same way (and their z can differ at equal fragment position).BTW, this technique is known as hidden line removal. You can check this presentation for more details.
结果我只是没有设置深度模板缓冲区。那好吧。
Turned out I just had no depth-stencil buffer set up. Oh well.