Saving Java OpenGL Depth Buffer

I'm not quite sure if I can do what I want here, but I have a bunch of objects that are displayed in OpenGL (using JOGL). For one group of objects, I want to make sure that some objects in this group appear before other objects in this group. I tried to clear the depth buffer bit and render the β€œfront” objects for the last time, and this works, except that it gets confused with other depth buffering on the screen.

What this means, I have a list of objects that are being visualized, and I want certain objects in this list to appear in front of other objects (all of them coincide with the Z coordinate). Is there any way to do this?

thanks jeff

0
source share
1 answer

This is a very common technique for drawing transparent objects (objects with parts with alpha! = 1).

The most common approach is to first build a tree of objects to be drawn, which can then be sorted by "depth" after passing through the projection * matrix of the camera. Basically, instead of just throwing triangles blindly at the GPU, you send your objects in turn when you process them in the world in a temporary buffer. These objects have full knowledge of each triangle and each vertex / vertex shader / texture name + identifier, etc. Then you can sort your buffer (either naively, an object by an object, or a full scattered view based on similar patches by objects).

The glDepthMask trick, if I remember correctly, looks something like this:

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

For best results, transparent objects are sorted in reverse order, but in most (simple) applications this does not matter.

edit: note that for the second method, when turning the WRITING depth buffer on and off, you still use the TESTTING of the depth buffer, so draw transparent objects behind your usual objects (for example, a helmet pointing to the β€œscreen”).

+1
source

Source: https://habr.com/ru/post/1305182/


All Articles