OpenGL:3D 中的粗而光滑/无断线* [英] OpenGL : thick and smooth/non-broken lines *in 3D*

查看:18
本文介绍了OpenGL:3D 中的粗而光滑/无断线*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似 3D CAD 的应用程序,为此我使用了 OpenGL 包装器库 (OpenSceneGraph).对于应用程序,我正在尝试提出如何在 3D 中渲染粗而平滑的线条的最佳策略.

I have a 3D CAD-like application for which I use OpenGL wrapper library (OpenSceneGraph). For the application I am trying to come up with the best strategy on how to render thick and smooth lines in 3D.

厚实和光滑我的意思是:

  • 线宽可以大于 OpenGL 的最大线宽值(在我的机器上似乎是 10.f)
  • 在组合多段线时,我想避免出现断线"(见下图示例)

目前我使用 GL_LINE_STRIP_ADJACENCY 渲染我的折线.

At the moment I render my polylines by using GL_LINE_STRIP_ADJACENCY.

我发现有很多关于如何在 2D 中渲染漂亮的线条和曲线的不同资源.不需要太多思考的最简单方法是将线渲染为一组四边形 (GL_QUAD_STRIP).这个解决方案的好处是它同时解决了我的两个问题.

I found there are many different resources on how to render nice looking lines and curves in 2D. The simplest approach that does not require much thinking is to render the line as a set of quads (GL_QUAD_STRIP). The good thing about this solution is that it solves both of my problems at the same time.

举个例子,我还发现了这个 不错的库,它允许实现广泛的线和曲线看起来.它使用三角形进行渲染.

As an example, I also found this nice library that allows to achieve wide range of line and curve looks. It uses triangles for rendering.

注意:我不寻求像逐顶点着色或类似画笔的笔触之类的奇特效果,只是一条 3D 线段,它可以具有很大的厚度并且与另一条线段很好地连接而没有任何他们之间的差距.

Note: I do not seek for fancy effects like per-vertex coloring or brush-like strokes, just a 3D line segment that can have large thickness and that connects well with another line segment without any gaps between them.

问题 那些 2D 方法的问题在于它们是 2D 的.当我改变视点时,很明显我的线几何不是线,而是位于某些 3D 平面中的 2D丝带".我希望它们看起来像 3D 线条.

The problem with those 2D approaches is that they are 2D. When I change the view point, it is obvious my line geometries are not lines but rather 2D "ribbons" lying in certain 3D planes. And I want them to look like 3D lines.

在思考这个问题时,我只能想出以下方法:

When thinking about the problem, I could only come up the the following approaches:

  1. 将线渲染为一组 2D 四边形(三角形),然后使它们始终面向相机
  2. 使用一些 3D 形状(如圆柱体)来表示线段

我不确定这两种解决方案中的任何一种的可行性(我是 OpenGL 的初学者).我的场景中可能有数百甚至数千条折线.我也想知道是否有更好、更聪明的方法来解决这个问题?我对任何事情都持开放态度,并对最有效的方式感兴趣.谢谢.

I am not sure how feasible any of the two solutions are (I am beginner in OpenGL). I might have hundreds or even thousands of polylines on the scene. I am also wondering if there is a better, smarter way to approach the problem? I am open to anything and interested in the most efficient way. Thank you.

编辑:正如用户@rickyviking 所指出的,我没有明确说明我要追求 2D 外观(就像在任何类似 CAD 的应用程序中一样),这意味着:线不取决于相机离它们多远/多近.

EDIT: as pointed by user @rickyviking, I didn't clarify explicitly that I am going after a 2D look (like in any CAD-like app) which would mean: the thickness of the lines does not depend on how far/near the camera is located from them.

更新:感谢@rickyviking 的回答,我选择了移动方向 - 几何着色器.我仍然没有完整的解决方案,但可能会在达到结果时发布最终更新和最少代码,请点击此处.

UPDATE: thanks for answer of @rickyviking, I chose the direction to move with - geometry shaders. I still do not have a complete solution, but might post a final update and minimal code when the result is achieved, here.

推荐答案

首先,您需要明确自己所追求的结果应该看起来"2D 还是 3D.

First of all you need clarify yourself whether the result you're after should "look" 2D or 3D.

当您提到圆柱体时,它们肯定会具有3D 效果"(距离较远的几何图形比靠近视点的几何图形更薄/更小),但这不是类似 CAD 的应用程序通常的样子.
我相信您追求的是 2D 外观效果,其中线条的宽度与它们与视点的距离无关.

When you mention cylinders, they will certainly have a "3D effect" (geometries farther away thinner/smaller than geometries closer to the viewpoint), but that is not what CAD-like applications normally looks like.
I believe you're after a 2D looking result, where the width of your lines is independent from their distance from viewpoint.

当使用一个库就像你提到的那个时,你应该在每次改变你的视点(可能是每一帧)以使它们始终面向屏幕平面.

When using a library like the one you mention, you should recompute the geometries every time you change your viewpoint (possibly every frame) to have them always face the screen plane.

另一种性能更好的方法是使用实体线框"技术,这里是 来自 NVidia 的实现,它使用几何着色器(您可以在 OpenSceneGraph 中找到有关如何使用它们的几个示例).
其他类似技术如下所示:https://forum.libcinder.org/topic/smooth-thick-lines-using-geometry-shader

An alternative and better performing approach would be to use the "solid wireframe" technique, here is an implementation from NVidia, which uses geometry shaders (you can find several examples on how to use them in OpenSceneGraph).
Other similar techniques are shown here: https://forum.libcinder.org/topic/smooth-thick-lines-using-geometry-shader

这篇关于OpenGL:3D 中的粗而光滑/无断线*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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