Fix flickering for tileset with thin walls #5940
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This builds on #5820 which is the right idea but for me didn't completely solve the flickering, especially on the roof of the AGI building.
Originally I thought the flickering was caused by children rendering with their parents, but the problem is actually rendering the back faces and front faces of the same tile simultaneously, as required by the skip-lods approach. Normally this is never a problem, but it is a huge problem for thin walls where back and front faces overlap. Fixing the depth test in #5820 to allow the front face to render above the back face when it's depth is equal seems like it should work, but I think the test is too precise. Apply a polygon offset to the back faces seems to work better. Essentially it pushes the back face depth to "solidify" the geometry.
At some point @austinEng and I talked about disabling color-writes for the back face commands, and I think that was kept in because of this flickering bug, the rationale being it's better to show the back face color during the flicker rather than see through the model. Because the flickering is mostly gone now I disable color writes for back faces, hopefully we get some performance win there.
The last thing in this PR is not rendering back faces for leaf tiles. I think there could be an edge case here where a tile further in the distance with a greater selection depth could appear in front of the tile up close, but I think this situation is rare and haven't noticed it happen yet during my testing.
Before and after: