Java OpenGL保存深度缓冲区

发布于 2024-08-26 17:27:59 字数 229 浏览 4 评论 0原文

我不完全确定我是否可以在这里做我想做的事,但我有一堆对象正在 OpenGL 中渲染(使用 JOGL)。对于一组对象,我想确保该组中的某些对象渲染在该组中其他对象的前面。我尝试清除深度缓冲区位并最后渲染“前面”对象,这很有效,除了它会扰乱屏幕上的其他深度缓冲。

归根结底是我有一个正在渲染的对象列表,我想确保该列表中的某些对象渲染在其他对象之前(尽管它们都位于相同的 Z 坐标)。有办法做到这一点吗?

谢谢, 杰夫

I'm not entirely sure if I can do what I want here, but I have a bunch of objects being rendered in OpenGL (using JOGL). For one group of objects, I want to ensure that certain objects in that group are rendered in front of other objects in that group. I've tried clearing the depth buffer bit and rendering the "front" objects last, and that works, except it messes up other depth buffering on screen.

What it comes down to is I have a list of objects being rendered and I want to ensure that certain objects in that list are rendered in front of other objects (they are all at the same Z coordinate though). Is there a way to do that?

thanks,
Jeff

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

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

发布评论

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

评论(1

愛上了 2024-09-02 17:27:59

这是绘制透明对象(具有 alpha!=1 部分的对象)的一种非常常见的技术。

最常见的方法是首先构建要绘制的对象树,然后可以在通过投影*相机矩阵后按照“深度”进行排序。基本上,您不是盲目地向 GPU 扔三角形,而是在世界中处理对象时将它们一一发送到临时缓冲区。这些对象完全了解每个三角形和每个顶点颜色/顶点着色器/纹理名称+id 等。然后您可以对缓冲区进行排序(天真地逐个对象排序,或者基于对象之间的相似补丁进行全面排序)。

如果我没记错的话,glDepthMask 技巧是这样的:

glDepthMask(true);
drawOpaqueObjects();
glDepthMask(false);
drawTransparentObjects();

为了获得最佳结果,透明对象从后到前排序,但在大多数(简单)应用程序中,这并不重要。

编辑:请注意,对于第二种技术,当您启用然后禁用深度缓冲区写入时,您仍然使用深度缓冲区测试,因此普通对象后面的透明对象(例如指向“屏幕”的头盔)不会被绘制。

This is a very common technique to draw transparent objects (objects that have parts with alpha!=1).

The most common approach is to first build a tree of objects to be drawn that you can then sort along to the "depth" after being passed through the projection*camera matrices. Basically instead of just blindly throwing triangles at the GPU, you send your objects one by one as you're processing them in the world to a temporary buffer. These objects have full knowledge of every triangle and every vertex color/vertex shader/texture name+id etc. Then you can sort your buffer (either naively, object by object, or a full blown sort based on similar patches across objects).

The glDepthMask trick, if i recall correctly, goes something like this:

glDepthMask(true);
drawOpaqueObjects();
glDepthMask(false);
drawTransparentObjects();

For best results the transparent objects are sorted back-to-front, but in most (simple) applications this doesn't matter.

edit: note that for the 2nd technique, while you enable and then disable depth buffer WRITING, you still use depth buffer TESTING, so transparent objects behind your normal objects (a helmet pointing "into" the screen for example) won't get drawn.

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