OpenGL:3D *中的粗线,平滑线/不间断线* [英] OpenGL : thick and smooth/non-broken lines *in 3D*

查看:287
本文介绍了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.

一种更好的替代方法是使用实体线框"技术,此处为 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天全站免登陆