Jump to content
  • Advertisement
Sign in to follow this  
uto314

z-fighting and glPolygonOffset

This topic is 4948 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

Hi, I'm trying to get ride of a Z-fighting against two polygon which overlap one the other and belong to the same plane. First I enable GL_POLYGON_OFFSET_FILL, then I set glPolygonOffset(k,u); and I draw the 2 polygons. But I can't find the propers k and u unit to make the thing work, there is always a point of view (distance / perspective) which involves a z-fight between the 2 polygons. So if someone knows something about that a little help would be great... Thanks, -uto-

Share this post


Link to post
Share on other sites
Advertisement
I can't help with the polygon offset thing, but my solution is to either have a high bit dipth buffer, 32 bit, check where you are and without checking the depth buffer, choose which polygon to draw first, or draw one polygon 0.1 distance from the other, or something like that. Unless you get really close, I think the last works fine.

Share this post


Link to post
Share on other sites
Thanks for you reply, but I'm not sure that the depth buffer sampling is linear, in which case a constant offset will not work.
I'm sure that is very known problem but I haven't found some good documentation about how to solve it.

...

after googling... [http://www.codesampler.com/oglsrc.htm]

-uto-

[Edited by - uto314 on March 31, 2005 5:38:29 PM]

Share this post


Link to post
Share on other sites
I'm also having problems using glPolygonOffset.

I'm getting line artifacts when two separate objects, like boxes, are drawn side by side.
There's a visible line where the two boxes meet.

I don't know the correct way to setup glPolygonOffset() either. I'm using a perspective-type
view and based on the position of the camera, using constant value like 1.0 doesn't seem to
work very good. Objects can be very close or very far away.

This is informative, but not helpful:
http://www.opengl.org/resources/faq/technical/polygonoffset.htm

I've seen some code that alternates the offset from 0 to 1, but that code looks wacky and have
no idea what's it's doing.

Here's a better description of the math involved (at the bottom of the page):
http://www.glprogramming.com/red/chapter06.html

"Also, since depth values are unevenly transformed into window coordinates when using perspective projection (see "The Transformed Depth Coordinate" in Chapter 3), less offset is needed for polygons that are closer to the near clipping plane, and more offset is needed for polygons that are further away."

Oh, and I read somewhere that artifacts can be completely eliminated (?) using fragment shaders,
but I have no idea about this.

Would anyone use glPolygonOffset on a poly-per-poly basis, or would you set it once for the
entire object?

[Edited by - raydog on March 31, 2005 8:39:16 PM]

Share this post


Link to post
Share on other sites
Quote:
've seen some code that alternates the offset from 0 to 1
its not limited to between 0->1 ui can use glPolygonOffset(-10,-10) for instance , which shouldnt result in any zfighting (though one might appear to be floating abouve the other ;)

Share this post


Link to post
Share on other sites
If you have Game Programming Gems 1, check out Section 4.1. It's a little trick for tweaking the projection matrix to effectively get z offset for free. You don't get the hardware adjustment for the slope, but on the flip side you don't lose hierarchical z-cull with this method.

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!