Fixing mesh overlaps in dynamic unknown scenes

So, I’ve read that for fixing mesh overlaps you guys mostly suggest using:

material.polygonOffset = true;
material.polygonOffsetFactor = value;

But this might only apply for scenes where you understand and know the sources you are going to add.

In a unknown scene, where users can upload their own objects, there’s no way to tell which materials should have these values turned on to avoid mesh overlaps.

I’ve found a good approach that works perfectly for this: scaling the camera

Here are some examples of how it works:

Camera Scale (1,1,1), clothes overlap too easily thru the user.
Screenshot 2022-12-24 at 12.32.53

But as soon as I change the Camera Scale to be i.g. (10,10,10), the mesh stops overlapping. I’m guessing that by increasing the camera scale, depth buffer is more precise?
Screenshot 2022-12-24 at 12.34.11

This approach has worked for me very good, until I start adding more complex scenes to the renderer, such as effects, composer, passes, etc. I suppose, some relay on the camera matrix and lead to glitches.

Is there a better way to avoid overlapping for unknown scenes?

Thanks in advance.

This was a issue with the near / far camera settings I was using.

Seems that if the far / near relation is way too big, this effects will start showing. Fixed it by reducing the relation between far / near of the camera.

I reduced it severals year ago by increasing near from 0.01 to 0.05

1 Like

Yes, I’m using 0.1 and 100 now, and it’s working great.

When the camera zooms out, I dynamically change the near to 0.5 and far to 150, and it works too :slight_smile:

Flickering pixels was then distance to object was about 100 meters.