UV clipping hack for Tales of Rebirth screen tearing #12127
Closed
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.
Description of Changes
This is a PR to address the screen tearing problem in #12100 for SW rendering. The main change is to clip UV values of individually rasterized pixels to the bounding box of the (rounded) UV) values of the poly. This is still very much for testing purposed as it only applies to SW renderers without the JIT recompiler (so it's very slow) and the code is hacky. This is for testing purposes at this point, but if it accepted I would add it to the JIT recompilers and clean it up. Also, the changes only apply to texture mapping in UV mode, though it might be able to be modifited to work with ST mode also.
Rationale behind Changes
The problem is that some times bilinear interpolation causes interpolated UV values to go outside the area where they are expected to be. These edge UV values cause sampling from incorrect texels causing alpha tests to fail and leave tears in the poly. I don’t know if this is a game bug that is being correctly emulated or an emulation bug. Either way, the effect is not desirable.
The fix I suggest is to clip the UV values during rasterization against the min/max integer values of the UV values of the vertices of the poly. I don’t have enough experience to know if this is a viable solution or if it would cause worse issues elsewhere, so any help testing this on games or feedback would be much appreciated.
Suggested Testing Steps
I have tested this on a GS dump of provided in the thread #12100 and it seems to fix that issue. I would suggest testing this on games to make sure it is not breaking other things. I anticipate it will be quite slow.
PS: I hope I made this PR correctly. Please let me know if I should change anything!