GLSL gl_FragDepth and glPolygonOffset

Started by
0 comments, last by karwosts 13 years ago
Hello!

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:

gl_FragDepth=gl_FragCoord.z+texColor.r

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?
Advertisement
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?
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game

This topic is closed to new replies.

Advertisement