I’m new to this community so still learning this library. I am making a 3D comparison tool and I want two models to have parts that are overlayed on top of each other (say one model has a part added to it, but the rest is the same). Currently, when parts of the model intersect there is a color flickering issue (z-fighting) since the pixels are in the same exact spot. I want instead for the pixels to default to say solid gray if z-fighting appears. Is anyone familiar with a way to do that?
One approach:
draw the first model with depthWrite=false on its material.
Then draw the second model as normal…
Or.. draw the first model as normal, and the second model with material.depthTest=false
Another approach is to use polygonOffset on the second model to artificially offset the second model toward the camera. This is often used for placing decals on surfaces while avoiding z-fighting.. but can break the visuals when used in other ways.
Yet another approach is to use logarithmicDepthBuffer:true on the renderer..
This improves the precision at close distances and can reduce (but not eliminate) z-fighting… but can affect other areas of the rendering pipeline.
More generally.. there isn’t really a way to “detect” z-fighting.. so there isn’t a way to just handle the z-fighting areas differently.
Also the amount of z-fighting will vary depending on GPU, and depth buffer precisions.
If you render 2 meshes with the exact same pos/rot/scale, and the exact same geometry, and same material type, they should not z-fight, but in practice this can be hard to achieve.