avaraline / Avara

Port of the original 1996 game from Ambrosia Software.
MIT License
122 stars 19 forks source link

Z-fighting/moire patterns when rendering thin blocks used for coloring #26

Open assertivist opened 5 years ago

assertivist commented 5 years ago

The easiest way to see this happening is to load Treble from AA Tre and look at the columnar blocks in the center. The decorations on top show z-fighting artifacts on Windows.

This may be distance related since they look fine when you're playing/up close, but I've also seen it on the corner blocks in Symbiosis at pretty close range.

It may also be platform related, but you can definitely see this in both Windows and Linux.

assertivist commented 5 years ago

After hearing from users on other platforms (thanks @scarletswordfish) I can pretty much safely say it isn't a platform issue. We probably need to adjust the way our object shader treats thin objects.

assertivist commented 4 years ago

There's an attempt to deal with this issue in the shader labelled "decal". this uniform becomes .9999 when the object in question has a bounding box with a dimension smaller than some value (.001 I think it is right now). Then the z-buffer value is multiplied by that to bring those objects a little closer to the 'camera'.

This successfully gets rid of z-fighting in some situations but not all, and it also applies to thickness=0 ramps and other objects that we don't want to adjust the z-buffer of. So this is still in progress.

assertivist commented 4 years ago

74 didn't fix this, but it did make it better...

Instead of messing with the z-buffer directly, I discovered glPolygonOffset and used that to fix a lot of the instances of z-fighting, mostly of flat panels on the surface of larger blocks.

But we still have some, especially in places where the geometry that is coplanar with the decal geometry is also considered a decal (which means they both get shifted and the effect doesn't work).

It may be possible to utilize Juri's original algorithms for whether or not an object is obscured to assist with these adjustments in the depth buffer...