Jump to content
  • Advertisement
Sign in to follow this  
spliter

GLSL gl_FragDepth and glPolygonOffset

This topic is 2746 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!