Z-Fighting Offset issues when looking perpendicular onto a mesh

Hi,

I made a playground with two ground planes, both having different materials and one has a zOffset. I see the material in red, but as soon as I move with the camera to top position, it turns blue. And when I zoom in to a radius of around 60, the red material is visible again. (I had to adjust the ArcRotateCamera lowerBetaLimit, since the default value did not allow a perpendicular view.)

https://playground.babylonjs.com/#ZGIX5J

I saw that the new zOffsetUnits property on a material can help, but since I am using an older version currently, I was wondering, if there is another option to deal with this issue? In my case I am experiencing z-fighting already with a beta value < 0.1
Using different minZ values helps, but mostly only at a specific distance. If one zooms out then the minZ value can be larger, zoomed in it can be smaller.

It is a bit tricky problem, since it mostly happens for perpendicular view and changing parameters only for this view can influence the experience of other viewing angles, too.

1 Like

Unfortunately there’s not much to do apart from what you said (raising minZ / using zOffset/zOffsetUnits). The best way to deal with this problem is to avoid it altogether by pushing asides the planes as much as possible.

Another possibility is to use WebGPU and to enable engine.useReverseDepthBuffer: I don’t think it’s an option for you but at least it allows me to brag a bit about it :slight_smile:

Here are some screenshots with your PG with camera.radius = 300 (so zoomed in a lot) and looking from above (https://playground.babylonjs.com/#ZGIX5J#3).

WebGL:

WebGPU without reverse depth buffer:

WebGPU with reverse depth buffer:

Note that engine.useReverseDepthBuffer = true won’t help for WebGL2 because of the range of the Z values in the NDC space.

3 Likes

real time game engines :roll_eyes:

thanks! I guess I will have to find a way around it. Maybe the zOffsetUnits is a good reason to update :slight_smile:

great to see your enthusiasm for webgpu :smiley: ( just realised, that my chrome supports webgpu now :slight_smile: )

4 Likes