OpenGL 光照问题?

发布于 2024-09-29 20:59:48 字数 372 浏览 7 评论 0原文

大家好,

如图所示,我使用 GL_LINE_STRIP 绘制了很多轮廓。 但轮廓看起来一团糟,我想知道如何让它看起来不错。(看看深度……等) 我必须渲染轮廓,所以我必须坚持使用 GL_LINE_STRIP。我想知道如何为此启用照明?

预先感谢

原始图片

http://oi53.tinypic.com/287je40.jpg

http://oi53.tinypic.com/287je40.jpg

Greetings all,

As seen in the image , I draw lots of contours using GL_LINE_STRIP.
But the contours look like a mess and I wondering how I can make this look good.(to see the depth..etc )
I must render contours so , i have to stick with GL_LINE_STRIP.I am wondering how I can enable lighting for this?

Thanks in advance

Original image

http://oi53.tinypic.com/287je40.jpg

http://oi53.tinypic.com/287je40.jpg

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情话难免假 2024-10-06 20:59:48

照明轮廓不会有太大作用,但您可以使用雾或根据距离(甚至高度)手动设置线条颜色以产生深度效果。

Lighting contours isn't going to do much good, but you could use fog or manually set the line colors based on distance (or even altitude) to give a depth effect.

记忆之渊 2024-10-06 20:59:48

更新:

umanga,起初我认为照明不起作用,因为照明是基于表面法线向量的 - 而且你没有表面。然而@roe 指出,法线向量实际上是 OpenGL 中的每个顶点,因此,任何 POLYLINE 都可以有法线。所以这将是一个选择。

正如 @Julien 所说,目前尚不完全清楚 3D 线的法线应该是什么。问题是如何定义轮廓线的法线,以便产生的照明具有视觉意义并有助于阐明深度?

如果每个轮廓中的所有顶点都共面(例如在 XY 平面中),则可以将 3D 法线设置为 2D 法线,其中 0 作为 Z 坐标。由此产生的照明将给人一种形状的视觉感,尽管可能没有深度感。

如果您知道沿线的每个点处的曲面斜率(假设存在曲面),则可以使用曲面法线并更好地显示深度;这本质上就像仅应用于等高线的山体阴影。那么问题是为什么不显示整个表面呢?

更新结束

+1 Ben 建议根据海拔高度(是地形轮廓吗?)或根据与观看者的距离设置线条颜色。您还可以使用相似的颜色填充每个轮廓包围的多边形,如 http:// en.wikipedia.org/wiki/File:IsraelCVFRtopography.jpg

另一种使线条更清晰的方法是减少线条的数量...您可以调整轮廓的密度吗?例如,每 5 英尺高度差一条轮廓线,而不是每 1 英尺,或者无论单位是什么。取决于您要绘制轮廓的内容。

其他阐明深度的技术包括立体透视,以及在观看者观看时以 3D 方式旋转图像。

Updated:

umanga, at first I thought lighting wouldn't work because lighting is based on surface normal vectors - and you have no surfaces. However @roe pointed out that normal vectors are actually per vertex in OpenGL, and as such, any POLYLINE can have normals. So that would be an option.

It's not entirely clear what the normal should be for a 3D line, as @Julien said. The question is how to define normals for the contour lines such that the resulting lighting makes visual sense and helps clarify the depth?

If all the vertices in each contour are coplanar (e.g. in the XY plane), you could set the 3D normal to be the 2D normal, with 0 as the Z coordinate. The resulting lighting would give a visual sense of shape, though maybe not of depth.

If you know the slope of the surface (assuming there is a surface) at each point along the line, you could use the surface normal and do a better job of showing depth; this is essentially like a hill-shading applied only to the contour lines. The question then is why not display the whole surface?

End of update

+1 to Ben's suggestion of setting the line colors based on altitude (is it topographic contours?) or based on distance from viewer. You could also fill the polygon surrounded by each contour with a similar color, as in http://en.wikipedia.org/wiki/File:IsraelCVFRtopography.jpg

Another way to make the lines clearer would be to have fewer of them... can you adjust the density of the contours? E.g. one contour line per 5ft height difference instead of per 1ft, or whatever the units are. Depending on what it is you're drawing contours of.

Other techniques for elucidating depth include stereoscopy, and rotating the image in 3D while the viewer is watching.

原谅我要高飞 2024-10-06 20:59:48

如果您需要阴影,那么您通常会将轮廓转换为实体。通常的方法是通过在边界或边界之外的零高度处设置 4 个角点来构建网格,然后将轮廓放入网格中并让网格对坐标进行三角测量。完成后,您就得到了一个三角实体您可以找到船体的法线并将其平滑到相邻的面上以创建平滑的地形。

为了对网格进行三角测量,通常使用 Delaunay 算法,该算法有点复杂,但确实存在用于执行此操作的库。我所知道的最好的是基于 Guibas 的 Stolfi 论文,因为它相当理想。

要生成法线,您需要执行简单的叉积并确保面正确,并在输入 glNormal 之前手动重新标准化它们。

过去,您常常根据结果创建 glList,但较新的方法是创建顶点数组。如果您想要额外的闪光,那么您可以寻找重合的平面并向下优化网格以加快重绘速度,但这有点像黑魔法 - 对游戏有利,但对 CAD 不太有利。

(谢谢上次的奖金)

If your looking for shading then you would normally convert the contours to a solid. The usual way to do that is to build a mesh by setting up 4 corner points at zero height at the bounds or beyond then dropping the contours into the mesh and getting the mesh to triangulate the coords in. Once done you then have a triangulated solid hull for which you can find the normals and smooth them over adjacent faces to create smooth terrain.

To triangulate the mesh one normally uses the Delaunay algorithm which is a bit of a beast but there does exist libraries for doing it. The best of which I know of is the ones based on Guibas as Stolfi papers since its pretty optimal.

To generate the normals you do a simple cross product and ensure the facing is correct and manually renormalize them before feeding into the glNormal.

The in the old days you used to make a glList out of the result but the newer way is to make a vertex array. If you want to be extra flash then you can look for coincident planar faces and optimize the mesh down for faster redraw but thats a bit of a black art - good for games, not so good for CAD.

(thx for bonus last time)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文