GS: Triangle/sprite edge rasterzation to find UV range for draw in SW renderer. #12192
+1,202
−48
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 an addition to the logic for calculating accurate UV ranges to determine texture ranges (currently SW renderer only). To enable accurate UV calculation, we rasterize the edge of triangles or the corners of sprites to determine the max/min UV coordinates to use. In the case of bilinear filtering, we make sure that the +/-1 UV is accurately computed. The changes are still very rough and require some more optimization and cleaning up. I also added some structs to the class GSState to develop this more quickly, which would probably be replaced by the existing structs in the final.
Rationale behind Changes
This is in response to the issue of screan tearing with Tales of Rebirth (#12100). The issues was caused by inaccurate calculation of the UVs for sprite-like triangles (i.e., triangles with axis-aligned coordinates in the form of a rectangle such that the UVs were also axis aligned). The more accurate UV calculation should allows the proper ranges of texture needed for rendering the draw to be accurated calculated and prevent screen tearing. However, the changes also might be overkill if most such problem are only for sprite-like triangles, where the calculation could be done much more quickly than in the general case for 3D triangles, as this PR addresses.
Suggested Testing Steps
This has currently been tested against several homebrews and comparing the min/max UVs against the software renderer rasterization. In all cases checked by hand so far, the only differences with the SW renderer were due to rounding errors of floats. Suggested testing steps is to test this in release against the Tales of Rebirth game and others that are known to have similar issues.