Hello everybody. I did read the guide for creating a new topic, I searched on Google to find an answer as well as on this site and I cannot find a clear answer.
Please note that
- English is not my native language.
- I am writing on a smartphone.
- It’s 02:43 am when I write this.
I am not looking for a code. In fact, even if I have a long (somewhat) experience with OpenGL, I never wrote a single line of Vulkan. My question is from a theoric point of view, almost an open discussion. I asked roughly the same question years ago about OpenGL, and back then the short answer was no.
The question is: is it possible to use two different depth buffers at the same time, in the same scene, during the same pass etc. ?
More precisely, let’s say I have a scene like this: a starfield, with two moons, some clouds and a house in a crop field, with the hand of the player holding a gun and a health bar floating on the top left corner.
In that scene:
The starfield will always be behind everything else;
The moon with the greatest orbite will always behind everything else, except the starfield;
The second moon will always be behind everything else, except the first moon and the starfield
You got the idea: the clouds can hide the moons and the starfield, the house can hide the clouds.
The hands can hide the house, because we don’t want them to clip through the house’s walls. They must always be drawn on top of the rest of the scene.
Finally the HUD is on top of everything else
You can obtain this effect by drawing each layer one by one and clearing the depth buffer between two passes. But I would like to keep the number of rendering passes to one.
The additional depth buffer would only contains integers (not float) and would not be interpolated. The vertex shader would define the value for all the fragments, that would be copied as is.
Such an implementation would be easy (it seems much simpler than the current behavior of the depth buffer) so I think that the problem is not there. Like my teacher used to say “it’s not exactly an NP hard problem”.
The depth test would be done by testing first the value of the integers then, if those values are the same, falling back on the classic depth buffer test.
Like I said, my question is: is it possible to do so, that in Vulkan ?
I kind of heard that Vulkan is more low level than OpenGL, so maybe we have to reimplements the depth test ourselves and, if it is the case, maybe we can tweak it while doing so.
Such a double test could eliminate primitive even before the fragmentation part: if some triangles of the farthest moon are hidden by the closest moon, or if the player is wearing a helmet ( that occludes a lot of it’s vision ).
Quite frankly, I find it weird that over the course of years almost every aspect of the pipeline opened up for modification but the depth test remained unchanged. I understand that criticizing the choices of khronos isn’t going to help me, but it’s more a genuine question than a critic.
Well in any case thanks for reading and good night.