开发者

DirectX: "see through" polygons

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,
                                    I开发者_如何学PythonsScissorEnabled = true,
                                    DepthBias = 1,
                                    DepthBiasClamp = 1000.0f,
                                    FillMode = FillMode.Wireframe,
                                    SlopeScaledDepthBias = 1.0f
                                };

DirectX: "see through" polygons


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜