Z Buffer

Hi all,

I have this problem, I must change or to keep the old value of the z-buffer. Can I change this value with vertex shader? However anyone solution is good for me.

Thanks for all answers.

Can you paint us a slightly broader picture?

There’s no access to gl_FragDepth from a vertex shader, if that’s what you mean. Actually I’ve no idea at all what you mean.

You can compute vertex depth in a vertex shader like this:


//compute vertex clip coordinates:
vec4 projVertex = ftransform();
projVertex /= projVertex.w;
// vertex depth in screen space (assuming that depth range is [0 1]
vertexDepth = 0.5 * projVertex + 0.5;

I explain better, I put a vertex, example with glVertex, this vertex must be comparative with the current Z value and if it’s good the old Z value must be invariated.
I have tried with glDephMask(GL_FALSE) but with it the glDepthFunc doesnt work.

I hope you have understood my problem but I have poor English.

Thanks again for your answers

With the code I have supplied above you can compute the current vertex depth and this is the one that is stored per fragment (after interpolation) in the depth buffer.

So you need to compare this value with the depth you want. This depth value can be passed with a depth texture if your hardware supports VTF (Vertex Texture Fetch). Otherwise, you will need to retrieve the depth value in software and give it to your vertex shader as a uniform.

glDepthMask, as far as I understand, has nothing to do with want you want to do (or is at least not sufficient), it just enables/disables depth writing in the depth buffer.

I dont know how glDepthMask works, but I think it doesnt test the Zfunc, it doesnt write only the zbuffer. Am I being wrong?

As I said glDepthMask just enables or disables the fragment depth writing (if it is relevant) in the depth buffer, nothing more, the color buffer is not affected (there is a similar command for the color buffer: glColorMask)

Ok it’s right, but does it disable the depth func (depth test) also? Im not sure but I think yes

glDisable(GL_DEPTH_TEST) disables it and the other prohibits to modify it. if depth buffer is filled with values depth test is still performed.

DESCRIPTION
glDepthMask specifies whether the depth buffer is enabled
for writing. If flag is GL_FALSE, depth buffer writing is
disabled. Otherwise, it is enabled. Initially, depth
buffer writing is enabled.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.