OpenGL轮廓和折痕渲染

发布于 2025-02-01 17:08:52 字数 1170 浏览 2 评论 0原文

我想用OpenGL渲染大纲 +折痕,但这并不是我想要的。有人可以帮我解决这个问题吗? 到目前为止,大纲是这样渲染的。

此刻我正在做的是: 弗里斯特我这样做:

GL.Enable(EnableCap.PolygonOffsetFill);
GL.PolygonOffset(0, -1f);
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
GL.DepthFunc(DepthFunction.Lequal);
GL.DrawArrays(PrimitiveType.Triangles, 0, verticesList.Count);
GL.Disable(EnableCap.PolygonOffsetFill);

然后我再次呈现这样的渲染:

GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
GL.LineWidth(5f);
GL.DepthFunc(DepthFunction.Less);
GL.DrawArrays(PrimitiveType.Triangles, 0, verticesList.Count);

我也想渲染那些绿线:

“我想如何渲染它”

填充形状上的线框看起来像:

提前致谢!

I want to render the outlines + creases with opengl but it's not going as I wish. Can someone, please help me to solve this problem?
So far the outline it's rendered like this.

How it's rendered now

At this moment what I'm doing is:
Frist I do this:

GL.Enable(EnableCap.PolygonOffsetFill);
GL.PolygonOffset(0, -1f);
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
GL.DepthFunc(DepthFunction.Lequal);
GL.DrawArrays(PrimitiveType.Triangles, 0, verticesList.Count);
GL.Disable(EnableCap.PolygonOffsetFill);

Then I render again like this:

GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
GL.LineWidth(5f);
GL.DepthFunc(DepthFunction.Less);
GL.DrawArrays(PrimitiveType.Triangles, 0, verticesList.Count);

I want to render those green lines as well:

How I want to render it

The wireframe over the filled shape looks like this:

How the wireframe looks

Thanks in advance!

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

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

发布评论

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

评论(2

守护在此方 2025-02-08 17:08:53

@rabbid76是对的。
但是有很多方法可以实现它:
大纲:
大纲可以通过OpenGL中的另一个通行证渲染器(您会在此找到许多教程)
折痕
您所说的“折痕”也称为“尖锐边缘”,您可能需要在不同的网格上渲染它们。
如果您可以访问网格拓扑(这意味着不同的面/顶点/边缘之间的连接),则很容易进行。
为此,您可以:

  • 与rendermode.line创建另一个网格,并用所有边缘填充它,相邻面向正态dotproduct超过一定阈值。
  • 将另一个“ in array”添加到着色器中作为vec3 [](如果仅渲染三角形),然后根据面顶点/边缘订单选择x,y,z坐标的订单,然后用任何一个更新此VEC3 [] 1(如果边缘锋利)或0(如果不是锋利的边缘),然后根据片段着色器中的颜色进行一些着色。
    (我从未测试过第二种方法,这似乎有点过分杀伤,但最终只会有一个网格)

这将是第一个实现的结果:

  • 红色:勾勒
  • 绿色:尖锐的边缘(30°角阈值)

@Rabbid76 is right.
there are many ways to achieve it though :
Outlines :
The outline can be renderer via another pass in OpenGL (you'll find many tutorial on this)
Creases
What you call "crease" is also known as "sharp edges" and you may need to render them on different mesh.
It is quite easy to go about it if you have access to your mesh topology (meaning the connectivity between your different faces/vertices/edges).
For that you could either :

  • Create another mesh with RenderMode.Line and populate it with all edges for which the adjacent face normals dotproduct exceed a certain threshold.
  • Add another "in array" to your shader as a vec3[] (if you render only trianlge), then choose an ordering for your x,y,z coordinates according to the faces vertices/edge order and update this vec3[] with either 1 (if sharp edge) or 0 (if not sharp edge) and then do some coloring according to that in your fragment shader.
    (I never tested this second method, it would seem a little overkill, but you'll end up with only one mesh)

this would be a result for the first implementation :

  • red: outline
  • green: sharp edge (30° angle threshold)
    enter image description here
樱花细雨 2025-02-08 17:08:52

您无法使用gl.polygonmode(材料face.frontandback,polygonmode.line);来实现此目标。 polygonmode.line模式不会呈现网格的轮廓,而是构图的大纲(三角形)。没有任何功能会立即为您提供您想要的东西。如果要在坚固的网格上绘制这些线,则需要禁用深度测试并使用线原始。您可以为此几何使用相同的顶点坐标,但是必须以不同的顺序绘制它们。 OpenGL只是图形驱动程序实现的低级API,可让您访问GPU,但这不是渲染,游戏或CAD引擎。您必须实现引擎,并且可以使用OpenGL进行操作。

You cannot achieve this with GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);. The PolygonMode.Line mode does not render the outlines of the mesh, but the outlines of the primitives (triangles). There is no feature that will give you what you want right away. If you want to draw these lines on a solid mesh, you need to disable the depth test and create a separate geometry with Line primitives. You can use the same vertex coordinates for this geometry, but you must draw them in a different order. OpenGL is just a low-level API implemented by the graphics driver that gives you access to the GPU, but it's not a render, game, or CAD engine. You have to implement the engine and you can do it with OpenGL.

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