OpenGL 从大集合中选取

发布于 2024-11-27 10:28:15 字数 765 浏览 0 评论 0原文

我试图在 JOGL 中从一大组渲染的四边形中进行选择(数千个)。有人有什么建议吗?

为了向您提供更多详细信息,我将大量数据绘制为具有程序创建的纹理的广告牌。

我看过这篇文章OpenGL GL_SELECT 或手动碰撞检测? 并发现它很有帮助。然而,我的程序可能需要长达几分钟的时间才能完成全套渲染,因此我不认为绘制 2x(用于颜色选择)是一种选择。

我目前正在通过调用 glBegin/glVertex.../glEnd 进行绘图。鉴于我使用 vao 和 vbo 在 GPU 上切换到批量渲染,您认为我会获得足够大的加速以促进颜色选择吗?

如果没有,鉴于所有反对使用 GL_SELECT 的建议,您认为值得我使用它吗?

我研究了多线程 CPU 方法来选择这些完全避开 OpenGL 的四边形。 您认为无 OpenGL CPU 解决方案是正确的选择吗?

对于所有问题,我们深表歉意。 我的主要问题仍然是,使用 OpenGL (JOGL) 从一大组四边形中进行选择的好方法是什么?

I'm trying to, in JOGL, pick from a large set of rendered quads (several thousands). Does anyone have any recommendations?

To give you more detail, I'm plotting a large set of data as billboards with procedurally created textures.

I've seen this post OpenGL GL_SELECT or manual collision detection? and have found it helpful. However it can take my program up to several minutes to complete a rendering of the full set, so I don't think drawing 2x (for color picking) is an option.

I'm currently drawing with calls to glBegin/glVertex.../glEnd. Given that I made the switch to batch rendering on the GPU with vao's and vbo's, do you think I would receive a speedup large enough to facilitate color picking?

If not, given all of the recommendations against using GL_SELECT, do you think it would be worth me using it?

I've investigated multithreaded CPU approaches to picking these quads that completely sidestep OpenGL all together. Do you think a OpenGL-less CPU solution is the way to go?

Sorry for all the questions. My main question remains to be, whats a good way that one can pick from a large set of quads using OpenGL (JOGL)?

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

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

发布评论

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

评论(4

ι不睡觉的鱼゛ 2024-12-04 10:28:15

从大量四边形中进行选择的最佳方法无法轻易定义。我不太喜欢颜色选择或类似的技术,因为它们在大多数情况下似乎不切实际。我一直不明白为什么有这么多教程专注于 OpenGL 新手,甚至编程专注于挑选,而这对几乎所有事情都是无用的。例如:尝试获取您在高度图中单击的像素:不可能。尝试在您单击的模型中找到精确的网格:不切实际。

如果您有大量四边形,您可能需要良好的空间分区或至少(更好)场景图。好吧,你不需要这个,但它有很大帮助。查看一些场景图教程以获取更多信息,如果您从 3D 编程开始,了解这一点是一件好事,因为您将了解很多概念,而不仅仅是 OpenGl 代码。

那么现在应该做什么来开始挑选呢?在鼠标光标所在的位置取模型视图矩阵的逆矩阵(带有 glUnproject(...) 的 iirc)。通过相机的方向,您现在可以将光线投射到空间结构(或包含空间结构的场景图)中。现在检查与四边形的碰撞。我目前没有链接,但如果您搜索逆模型视图矩阵,您应该找到一些页面可以比此处实际执行的更好、更详细地解释这一点。

通过这种基于光线投射的技术,您将能够在 O(log n) 中找到您的四边形,其中 n 是您拥有的四边形的数量。通过一些基于应用程序确切布局的启发式方法(您的问题太笼统而无法更具体),您可以在大多数情况下对此进行很大改进。

一个简单的空间结构是例如四叉树。然而,您应该首先从光线投射开始,以充分理解这项技术。

The best way to pick from a large number of quad cannot be easily defined. I don't like color picking or similar techniques very much, because they seem to be to impractical for most situations. I never understood why there are so many tutorials that focus on people that are new to OpenGl or even programming focus on picking that is just useless for nearly everything. For exmaple: Try to get a pixel you clicked on in a heightmap: Not possible. Try to locate the exact mesh in a model you clicked on: Impractical.

If you have a large number of quads you will probably need a good spatial partitioning or at least (better also) a scene graph. Ok, you don't need this, but it helps A LOT. Look at some tutorials for scene graphs for further information's, it's a good thing to know if you start with 3D programming, because you get to know a lot of concepts and not only OpenGl code.

So what to do now to start with some picking? Take the inverse of your modelview matrix (iirc with glUnproject(...)) on the position where your mouse cursor is. With the orientation of your camera you can now cast a ray into your spatial structure (or your scene graph that holds a spatial structure). Now check for collisions with your quads. I currently have no link, but if you search for inverse modelview matrix you should find some pages that explain this better and in more detail than it would be practical to do here.

With this raycasting based technique you will be able to find your quad in O(log n), where n is the number of quads you have. With some heuristics based on the exact layout of your application (your question is too generic to be more specific) you can improve this a lot for most cases.

An easy spatial structure for this is for example a quadtree. However you should start with they raycasting first to fully understand this technique.

审判长 2024-12-04 10:28:15

从未遇到过这样的问题,但在我看来,我认为基于 CPU 的选择是最好的尝试方法。

如果您有大量四边形,也许您可​​以按空间对四边形进行分组,以避免测试所有四边形。例如,您可以将四边形分组到两个框中,然后首先测试您选择哪个框

Never faced such problem, but in my opinion, I think the CPU based picking is the best way to try.

If you have a large set of quads, maybe you can group quads by space to avoid testing all quads. For example, you can group the quads in two boxes and firtly test which box you

聊慰 2024-12-04 10:28:15

我刚刚实现了颜色选择,但 glReadPixels 在这里很慢(我读过一些文章,它可能对 GLCPU 之间的异步行为不利) 。

在我看来,另一种可能性是使用变换反馈和进行剪刀测试的几何着色器。然后,GS 可以丢弃所有不包含鼠标位置的面。变换反馈缓冲区准确地包含有关悬停网格的信息。

您可能还想将深度写入变换反馈缓冲区,以便您可以找到最上面的悬停网格。
这种方法对于实例化也很有效(另外将实例 ID 写入缓冲区)

我还没有尝试过,但我想它会比使用 glReadPixels 快得多。
我只找到了此方法的参考。

I just implemented color picking but glReadPixels is slow here (I've read somehere that it might be bad for asynchron behaviour between GL and CPU).

Another possibility seems to me using transform feedback and a geometry shader that does the scissor test. The GS can then discard all faces that do not contain the mouse position. The transform feedback buffer contains then exactly the information about hovered meshes.

You probably want to write the depth to the transform feedback buffer too, so that you can find the topmost hovered mesh.
This approach works also nice with instancing (additionally write the instance id to the buffer)

I haven't tried it yet but I guess it will be a lot faster then using glReadPixels.
I only found this reference for this approach.

儭儭莪哋寶赑 2024-12-04 10:28:15

我正在使用从 DirectX SDK 借用的解决方案,有一个很好的示例如何检测顶点缓冲区对象中的选定多边形。

相同的算法适用于 OpenGL

I'm using the solution that I've borrowed from DirectX SDK, there's a nice example how to detect the selected polygon in a vertext buffer object.

The same algorithm works nice with OpenGL.

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