Sign in to follow this  

GLSL gl_FragDepth and glPolygonOffset

Recommended Posts


I have a black and white texture that represents the captured depth.
What I want in my program is to draw geometry occluded by that texture (texture is always aligned with screen). Sort of simulate what glpolygonoffset would do but at a per-pixel level and the offset depends on the texture.

the simple way would be to draw the z coordinate of the pixel to the depth buffer and add the r component of the fragment like this:


But frag depth is in range from 0 to 1, but dividing the texColor.r by the( far plane - near plane) but that doesn't work either.

So, here I ask you: How do I simulate the glPolygonOffset in the fragment shader?

Share this post

Link to post
Share on other sites
I'm a little confused, what you're describing doesn't sound like what I think glPolygonOffset is used for. glPolygonOffset is designed to avoid z-fighting when you have two very close objects, by drawing one as if its z-value was offset by a few levels to separate them.

You're talking about drawing things occluded by a texture, though I don't understand exactly what you mean by occluded in this case, do you mean draw anything that's behind the texture, or just something that is fighting with it like I described for glPolygonOffset?

I assume texColor.r is your "depth texture" (please correct me otherwise), though I don't see how it makes sense to add that to the current depth. Exactly what are you trying to achieve, can you describe your scene a little bit more?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this