Java OpenGL保存深度缓冲区 [英] Java OpenGL saving depth buffer

查看:109
本文介绍了Java OpenGL保存深度缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定我是否可以在这里做我想做的事,但是我有一堆在OpenGL中渲染的对象(使用JOGL).对于一组对象,我想确保该组中的某些对象呈现在该组中其他对象的前面.我试过清除深度缓冲位,最后渲染前"对象,该方法行之有效,只是它弄乱了屏幕上的其他深度缓冲.

归结为,我有一个要渲染的对象列表,并且我想确保该列表中的某些对象在其他对象之前渲染(尽管它们都在相同的Z坐标上).有办法吗?

谢谢, 杰夫

解决方案

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

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

如果我没记错的话,glDepthMask的窍门是这样的:

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

为了获得最佳结果,透明对象是从头到尾排序的,但是在大多数(简单)应用程序中,这无关紧要.

edit:请注意,对于第二种技术,在启用然后禁用深度缓冲区写入时,仍将使用深度缓冲区TESTING,因此普通对象后面的透明对象(例如,头盔指向屏幕的透明"对象)将不会不会被吸引.

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

解决方案

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.

这篇关于Java OpenGL保存深度缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆