🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Overlaying textures

Started by
3 comments, last by Centurion 18 years, 4 months ago
I need to draw two different textures on the same plane. That works ok if both of textures have exact same edges, but if i try something like: 1) -1,-1,0 -1,1,0 1,1,0 1,-1,0 2) -.2,-.2,0 -.2,.2,0 .2,.2,0 .2,-.2,0 Then i got effect that different pixels are calculated "under" and other are "over" first texture, so second texture not completely overlay first one. I can solve problem adding a small number to height so second texture will float above first one (-.2,-.2,0.001 ....) but this have two another problems - i need to calculate what side second texture must be visible and if both i need to draw it twice one time with +.001 and second with -.001 .. So here is question - is any way other way to make one texture overlaying other ? I need to make that working without disabling depth test because both textures can be hidden behind another one. And making floating textures bring a lot of problems.
Advertisement
The problem you are describing is called z-fighting and it's cause by bad interpolation of depth coordinates.
It wouldn't happen if nvidia, ATI and those guys would use a standard plane equation instead of interpolation to calcylate z.

anyway, no there is no simple solution to this problem, the best thing would be to make shure that no such situation will appear, but if that can't be done you could try glPolygonoffset.

With it you can offset the z coordinates just before z testing with the smallest value possible.
I'm up to drawing a wall and then drawing a alpha-blended texture over it... so i see only two ways of doing that - draw full wall and then try to overlay it using glpolygonoffset, or i will try to divide my wall to subwall so one of subwalls will have same vetrixes as alpha texture have and i think i will escape z problem that way, but that will take me to draw 5 wall polygons and one alpha so will take 3x more time....
Quote: Original post by Centurion so will take 3x more time....

No, it will not, pixel fillrate is more important than the number of polys, and since the number of pixels drawn are actuarly less then it will cancel out the extra polys.

Not that it matters or anything, it's still way to small a speed difference to be noticed anyway.

Yes drawing subwalls worked... but i need to use exact same vertex... so i can't use for first layer vertex #1,2,3,4 and for second 2,3,4,1 ...

This topic is closed to new replies.

Advertisement