0
votes

So I'm reading a paper on a particular shading algorithm and there is one section that seems a bit vague and I was wondering if I could get advice here.

Basically it says I first have to take a 3D vertex of a mesh and transform it to window coordinates wx, wy, wz where wz is depth. This part I've done.

Next I have to test to see if this window-coordinate "passes" the depth buffer or not.

This is all it says and I am not sure what it means by "passing" the depth buffer. Does anyone here know what that could mean and how I could implement this in openGL?

EDIT:

More specifically, I need openGL to offer me feedback as to whether or not a particular vertex passed the depth buffer. I'm not actually rendering these vertices so it does me no good if openGL does all the computations "behind the scenes."

1
Are you looked for this on wikipedia? en.wikipedia.org/wiki/Z-buffering - acrilige
yeah but it was a bit confusing. So I know that my 'wz' component is the depth of the pixel but what I'm confused about is apparently openGL has a built in z-buffer value that I can compare my wz term too but I don't know how to access that initial z-value. - user1782677
Look at OpenGL pipeline overview, for example here: opengl.org/wiki/Rendering_Pipeline_Overview#Rasterization this page has a depth test description. Actually, it is a part of pipeline, which you can disable or not, but you have no need to do this depth test by yourself - acrilige
I don't actually need to render the vertex though, I just need to know if it passes the depth test so I can do other things with the vertices that pass. - user1782677
what things, for example? - acrilige

1 Answers

3
votes

Depth test is the part of OpenGL pipeline, which should be invoked after fragment (pixel) shader. So you have no need to do this by yourself, all you have to do is properly initialize your projection matrix and viewport so that your Wz for each vertex was calculated and then interpolated across vertices. You can configure some properties of this test.

Here is the OpenGL pipeline overview: http://www.opengl.org/wiki/Rendering_Pipeline_Overview#Rasterization Look at chapter 7: Per sample processing

The depth test, if any, is performed; if it fails, then the fragment is culled and not added to the framebuffer.


You said that you have to know which of vertices passed the depth test. But depth test invokes only on fragments, and not on vertices. So if you already have vertices with window x, y and z coordinates then you can just check for z coordinates those who have the same (x, y) coordinates and decide who of them will win this depth-test...