Direct3D线条粗细 [英] Direct3D Line thickness

查看:263
本文介绍了Direct3D线条粗细的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Direct3D绘制线条列表时,如何更改线条的粗细?



此帖子表示不支持线宽,并继续提供解决方法。其他选项?



当我们谈论这个话题时,着色器是否允许用线条画线?

解决方案

您可以使用一个几何着色器,它将输入线段作为输入并输出一个四边形(由两个三角形组成的三角形条),以使四边形的宽度恒定在屏幕空间中,并匹配所需的线条粗细。它可以很好地工作(在CAD 3D引擎中实现它)。



如果几何着色器不是一个选项,解决方法可能是使用顶点着色器,但它会需要你的VB的一些重新工作。请记住,VS必须掌握整个线段的知识,这样您最终会为每个VB元素存储p和p + 1,并且还会存储索引/顶点的重复成本(取决于所使用的拓扑和如果你把你的行渲染为一个索引原语或不)。



如果性能不是问题,那么在CPU上进行展开可能是一种方法。 p>

编辑:

关于短划线样式:您也可以按顺序使用几何着色器模拟 glLineStipple 行为。
如果您有一个 GL_LINES 拓扑结构,也就是说隔离线,则该模式将在每个新线段处重新开始。因此,您只需在几何着色器中计算线段的屏幕空间水平开始(或垂直开始,取决于方向),并将此额外信息传递给像素着色器。然后,像素着色器将负责根据因子图案值丢弃片段(DirectX 10/11 Integer和Bitwise指令使其更容易)。



再说一遍,你可以将它与模拟的宽度线结合起来(使用上面提到的第一种技术)。

现在,如果你有 GL_LINE_STRIP 拓扑结构,该模式在每个新基元重新开始(对每个新的绘制调用都是如此)。这种情况会变得更复杂一些,因为您需要了解之前渲染的像素数量,以及每个线段的像素数量。



您可以实现使用DirectX 10流出功能(VB中的每个元素对应于每个段的屏幕空间长度)在临时VB中呈现线条。然后你必须做一个VB的并行前缀和(又称扫描)(用于累积每个线段长度值)。

最后,你渲染线条像 GL_LINES 但在PS中使用此额外的扫描VB信息。


How do I change the thickness of lines when drawing line lists using Direct3D?

This post says that line width is not supported and goes on to provide a workaround. Other options?

While we are on this topic, do shaders allow one to draw lines with dash patterns?

解决方案

You can use a geometry shader that will take as an input a segment of your line and output a quad (a triangle strip made of two triangles) so that the width of the quad is constant in screen space and matches the desire line thickness. It works perfectly well (for having implemented it in a CAD 3D engine).

If geometry shader is not an option, a workaround could be to use a vertex shader, but it will require some re-work of your VB. Keep in mind that the VS must then have knowledge of the line segment in its whole so you will end up storing p and p+1 for each of your VB elements, plus the cost of duplication of indices/vertices (depending the topology used and if you render your line as an indexed primitive or not).

If performance is not an issue, doing the expand on the CPU is maybe the way to go.

EDIT:

About dash patterns: you can use a geometry shader too in order to emulate glLineStipple behavior. If you have a GL_LINES topology, that is to say isolated lines, the pattern restarts at each new line segment. So you just have to compute in the geometry shader the screen-space horizontal start (or vertical start, depending the orientation) of your line segment and pass this extra infos to the pixel shader. The pixel shader will then be responsible of discarding fragments according to the factor and pattern values (DirectX 10/11 Integer and Bitwise instructions make it easy).

Again this works well, and you can combine it with emulated width lines (with the first technique above mentioned).

Now if you have GL_LINE_STRIP topology, the pattern restarts at each new primitive (so for each new draw call). The situation becomes a bit more complicated since you need to have the knowledge of the number of pixels that have been rendered before, and this for each line segment.

You can achieve that with rendering your line strip in a temporary VB using DirectX 10 stream-out functionality (each element of this VB corresponds to the screen-space length of each segment). Then you have to do a Parallel Prefix Sum (aka Scan) of this VB (for accumulating each line segment length values).

Lastly, you render your line strip like for GL_LINES but use this extra Scan VB informations in the PS.

这篇关于Direct3D线条粗细的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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