Flickering edges in OpenGL

Started by
16 comments, last by NineYearCycle 16 years, 1 month ago
Hi, I do realize that this has probably been asked a million times before since I know it to be a common problem but I can only find solutions to issues related to texturing. My problem is that I get flickering edges when drawing adjacent surfaces. My surfaces use no textures, they're just phong shaded. The flickering appears as white dots that move around. I want to build a retro style level using building blocks that should appear seamless. Any help would be appreciated, thanx in advance /Mekanikles
Advertisement
Try enabling antialiasing.
while (tired) DrinkCoffee();
Don't think antialiasing is the problem here. if you read it carefully, he's getting flickering between polys, not jagged edges.

The first thing I would suggest is looking at your z-buffer resolution. If it's 16 bit right now bump it to 24 and see if that helps. Also, if you have two polygons that are meant to be connected, make sure that their vertices line up EXACTLY. Even an incredibly small offset can lead to rendering artifacts.
Yeah, sounds like some form of z-fighting. You might also want to check your calls to glFrustum or glPerspective and see what your near plane is set to. If you've got it set to something ridiculously small (like 0 or 0.1) then you'll waste all your precision near to the camera. Push it out further and see if it helps.
Thanx for the swift replies. However, I don't think my Z-buffer is the problem since the adjacent polygons aren't overlapping and I see white artifacts where two black surfaces connect. I do believe it's an precision problem though, that the two edges really aren't connecting properly due to subpixel faults when filling the surfaces. But I am putting the vertices of the surfaces on the exact same spot (I'm only dealing with integer map coordinates). I read somewhere that putting a small border on each surface to "fill up" the possible gap can solve it but then I would get Z-battling between those borders.

On a side note: Lots of less polished PS1 games had this problem so it seems to be rather common :-)

thxnx again /Mekanikles
Use indexed primitives (indexed triangle lists or indexed traingle strips being the most efficient), and all these problems will instantly go away. But you could run into some issues with texcoords.

That said, you should not get any kind of sparkling along connected edges, if you really supply the exact same coordinates for connected vertices.

Try to post a screenshot of the artifact, that would help,
A screenshot would probably help.

Are you possibly mixing the fixed function pipeline with shaders? That can cause even identical input coords to render to slightly different screen pixels (use the ftransform() function if you really want to mix the two).
@Yann L: Hm, I'm not quite sure what you mean, does it pay to use indexed list for simple quads? (my level is made up by connected boxes).

Here's a screenshot anyway:
Screenshot of flickering egdes 2

It doesn't show an awful lot here, but when moving the view it flickers alot, sometimes whole lines of white along the edges. I don't know if the shader has something to do with it, the "white" dots change color from grey to white when moving the lights around, so they seem to be affected by the shader.

@OrangyTang: I do not quite understand what you mean but I am using the ftransform.

thnx /Mekanikles

[Edited by - Mekanikles on March 2, 2008 6:51:51 AM]
Update: I've tried modifying the near clipping plane and the artifacts go down significantly (though never quite disappear). At a value of 10 they're almost gone, but that's way too high, I'm using around 1 now and it feels like that's as far as I can go. My far clipping plane is 300 btw if that's any help. I'm using relatively large coordinates where the columns in the picture are about 5*30*10.
Well, from the image and near-plane description you gave, I defiantly think that it's what we were saying earlier: The vertices are not the same, numerically, so the subpixel calculations are causing overlap and, naturally, some z-fighting.

It sounds like you want them to be two separate meshes for some reason, so sharing an actual vertex may be impossible here. If that's the case, you will probably want to find a way of preventing the z-test from happening along that edge. If possible disable z-testing when drawing those elements, and if not try using polygon offsets: http://www.opengl.org/resources/faq/technical/polygonoffset.htm

This topic is closed to new replies.

Advertisement