PDA

View Full Version : glPolygonOffset(1,1) not sufficient?



_x57_
01-06-2010, 11:12 AM
Hi!

I am having trouble with glPolygonOffset, which leads me to the question if there are any cases where the offset generated by glPolygonOffset(1.0, 1.0) is too small (to prevent z fighting)?

WHAT I DO IN PARTICULAR:
1) Render a "pushed-back" triangle mesh with glPolygonOffset(1.0, 1.0) to setup a GL_DEPTH_COMPONENT32F depthbuffer texture (FBO bound)

2) Render the same Geometry as GL_POINTS with Pointsize=1 while using a vertex/fragment shader program

3) In the fragment shader i manually calculate the depth of the rasterized one-fragmant point vertices and compare this depth to the depth value in the previously generated depth image.

WHAT I EXPECTED:
Since an offset should have been applied to the mesh in the first step i expect each point-vertex to have a smaller depth value and to lie in front of the filled mesh. Unfortunately some points don't.


WHAT I TRIED:
- Choosing glPolygonOffset(1.0,2.0) seems to do the trick for my current geometry - but i don not understand why and i suspect it won't work for other settings (i need to be flexible here).

- glPolygonOffset(1.0, 1.999) does not work for a single point more than (1.0, 1.0).

- Since the "bad" points lie on a slope relative to the viewing direction i tried glPolygonOffset(10.0, 1.0), but this only works for very few points more than (1.0, 1.0).


Any help would be greatly appreciated - i am out of ideas...

Dark Photon
01-06-2010, 06:05 PM
I am having trouble with glPolygonOffset, which leads me to the question if there are any cases where the offset generated by glPolygonOffset(1.0, 1.0) is too small (to prevent z fighting)?
See pages 20-26 here: Shadow Mapping with Today's OpenGL Hardware (Kilgard, 2002) (http://www.eecs.berkeley.edu/~ravir/6160/papers/shadowmaps.ppt)

But also see this (GlPolygonOffset whats the deal here? is it good or bad?) (http://www.gamedev.net/community/forums/topic.asp?topic_id=335012&whichpage=1%EE%80%8F) and this (glPolygonOffset units) (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Board=3&Number=197175) .

_x57_
01-07-2010, 03:26 AM
See pages 20-26 here: Shadow Mapping with Today's OpenGL Hardware (Kilgard, 2002) (http://www.eecs.berkeley.edu/~ravir/6160/papers/shadowmaps.ppt)

Ok, thats a nice explanation for the use of the slope parameter - thanks.

(1) So since i am rendering the scene twice using the same eye position and perspective setup it seems i do not need the slope-factor in glPolygonOffset at all, because each fragment depth should be computed at the exact same position right?

(2)However setting glPolygonOffset(0,1) or even glPolygonOffset(0,2) causes a lot of z-fighting along slopes... ?!?

(3)And still my question remains why glPolygonOffset(*, 1) is not sufficient since an 1*r offset should guarantee a distinct z in the depthbuffer according to the gl spec...

Meanwhile i will have a look at the modify the projection matrix - approach mentioned in your posted links...