如何使用 OpenGL 进行 3D 选择/拾取

发布于 2024-11-30 23:49:56 字数 574 浏览 0 评论 0原文

我的场景中有一些物体,有些可能会遮挡其他物体。当我单击鼠标或拖动选择以获得选择矩形时,我只想选择/拾取从这个角度可以看到的对象。应用程序当前使用 GL_SELECT 渲染模式,但正如我们所知,这也会选择被遮挡的对象。另外,我读到这在 OpenGL 3 中已被弃用。

目前有两种方法对我很有吸引力。首先是使用后台缓冲区进行对象选择(红皮书,第 14 章):将每个对象的颜色设置为其对象 ID,并从后台帧缓冲区读取像素的颜色。第二个是遮挡查询(superbible,第 4 版,第 13 章)。

我排除的其他方法是查看选择缓冲区中的最小/最大 z 值,并在 GL 之外进行自定义光线/对象检测。

我有一些问题: 1) 如果 GL_SELECT 在最近的 OpenGL 中被弃用,开发人员应该使用哪些替代方案? 2)我只读过有关使用遮挡查询来加速渲染的信息。它们可以用于选择/挑选吗?有缺点吗? 3) 现有应用程序有少量 glColorXXX 调用。如果我选择后台缓冲区路线,并使用 glColorMask(FALSE,FALSE,FALSE,FALSE),这是否会有效地将 glColourXXX 调用变成无效的调用,从而让我在选择模式下渲染时在单个位置控制颜色? 4)哪条路线最好/规范?

I have some objects in the scene, some may occlude others. When I click the mouse or drag-select to get a selection rectangle, I want to select/pick only the objects that I can see from this perspective. The application currently uses GL_SELECT render mode but as we know, this selects occluded objects too. Also, I read that this is deprecated in OpenGL 3.

There are two methods that are currently appealing to me. First is Object Selection using the Back Buffer (Red book, chapter 14): setting the colour of each object to it's object id and reading the colour of pixels from the back frame buffer. The second is occlusion queries (superbible, 4th ed, chap 13).

Other approaches I have ruled out are looking at the min/max z values in the selection buffer and doing custom ray/object detection outside of GL.

I have some questions:
1) If GL_SELECT is deprecated in recent OpenGL, what alternatives are developers supposed to be using?
2) I've only ever read about occlusion queries being employed to speed up rendering. Can they be used for selection/picking, and are there drawbacks?
3) The existing application has a handful of glColorXXX calls. If I went the back buffer route, and used glColorMask(FALSE,FALSE,FALSE,FALSE), will this effectively turn the glColourXXX calls into calls that have no effect, thereby letting me control the colour in a single place when rendering in select mode?
4) Which route is best/canonical?

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

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

发布评论

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

评论(1

野の 2024-12-07 23:49:56

我决定使用后台缓冲区来实现选择。我尝试回答以下问题:

如果 GL_SELECT 在最近的 OpenGL 中被弃用,开发人员应该使用哪些替代方案?
我认为最好不要使用 OpenGL 来完成此任务,而是使用空间加速结构,正如用户chamber85 在对原始问题的评论中建议的那样。

我只读过有关使用遮挡查询来加速渲染的内容。它们可以用于选择/挑选吗?有缺点吗?
我确信他们可以,但在绘制之前需要知道他们想要查询遮挡的所有对象。使用后台缓冲区和颜色选择,人们可以只看到光标下方或矩形区域内的内容,并从那里进行过滤。

现有应用程序有少量 glColorXXX 调用。如果我选择后台缓冲区路线,并使用 glColorMask(FALSE,FALSE,FALSE,FALSE),这是否会有效地将 glColorXXX 调用转换为无效的调用,从而让我在选择模式下渲染时在单个位置控制颜色?
答案是否定的。使用所有 GL_FALSE 参数调用 glColorMask() 将意味着 glColor3ub() 调用(例如)将不会被执行。它只是在将颜色写入颜色缓冲区之前指定颜色的过滤器/掩码。最初的想法是将颜色设置为对象id,然后调用glColorMask()来忽略所有后续的glColorXXX()调用。这种策略是注定失败的,因为代表对象 ID 的颜色也将被屏蔽。

4)哪条路线最好/规范?
我想说,后台缓冲区颜色选择通常是最好的,因为它不需要在绘制之前/期间设置遮挡查询。

I decided to implement the selection using the back buffer. Here's my attempt to answer my questions:

If GL_SELECT is deprecated in recent OpenGL, what alternatives are developers supposed to be using?
I think it's best to not employ OpenGL to do this task but to use spatial acceleration structures as user chamber85 suggested in comments to the original question.

I've only ever read about occlusion queries being employed to speed up rendering. Can they be used for selection/picking, and are there drawbacks?
I'm sure they could but one would need to know all the objects they want to query for occlusion before the draw. Using back buffer and colour selection, one can just see what is under the cursor or within a rectangular region and filter from there.

The existing application has a handful of glColorXXX calls. If I went the back buffer route, and used glColorMask(FALSE,FALSE,FALSE,FALSE), will this effectively turn the glColorXXX calls into calls that have no effect, thereby letting me control the colour in a single place when rendering in select mode?
The answer is no. Calling glColorMask() with all GL_FALSE parameters will not mean that glColor3ub() calls (for example) will not be honoured. It simply specifies a filter/mask for colours just before they are written to the colour buffer. The original thought was to set the colour to the object id, then call glColorMask() to ignore all subsequent glColorXXX() calls. This strategy is doomed as the colour representing the object id would also be masked out.

4) Which route is best/canonical?
I would say the back buffer colour selection is generally best as it doesn't require setting up the occlusion queries before/during the draw.

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