GS: Split and round sprites to emulate UV rounding error.#14029
Closed
TJnotJT wants to merge 1 commit intoPCSX2:masterfrom
Closed
GS: Split and round sprites to emulate UV rounding error.#14029TJnotJT wants to merge 1 commit intoPCSX2:masterfrom
TJnotJT wants to merge 1 commit intoPCSX2:masterfrom
Conversation
|
The 2 Tenchu games are mentioned here: #1562 Tenchu - Wrath of Heaven Tenchu - Fatal Shadows Tenchu - Wrath of Heaven_SLUS-20397_20260217201346.zip |
db370a3 to
4b14632
Compare
4b14632 to
7e42597
Compare
Contributor
Author
|
It seems that underflow (https://en.wikipedia.org/wiki/Arithmetic_underflow) has a different technical meaning than I thought, so changing it to rounding error everywhere. |
7e42597 to
80f067d
Compare
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Some games draws point-sampled sprites that should sample exactly at texel boundaries. For such cases, it seems that the GS rounds texels coordinates to the nearest texel. However, in many cases there appears to interpolation error in UVs so that the GS rounds down to the nearest texel instead (details on hardware tests below). This PR attempts to detect such cases, and split and round sprites to account for this.
Credits: This is built on ideas and work by refraction (see #6553).
Rationale behind Changes
Fixes accuracy issues in games that rely on accurate rounding. The initial intention was to fix the Beyond Good and Evil water reflections (see #1986).
Appears to fix #14002.
Caveats:
Comparisons
bge.gs.xz (note, red strip that looks like a bug on left occurs on both PS2 and PR)
PS2

Master SW

PR SW

Gallop Racer Inbreed_SLPS-25701.gs.xz (UI elements)
PS2

Master SW

PR SW

Dragon Ball Z - Budokai Tenkaichi 3_SLUS-21678_20221208223633.gs.xz (character outlines, some might still be a bit off in PR)
PS2

Master SW

PR SW

Ace Combat - Squadron Leader_SCES-52424_20250401050853.gs.xz (example where PS2 and PR look slightly worse, "Edge" in HUD looks a bit squished compared to master)
PS2

Master SW

PR SW

Wild_ARMs_3_SCUS-97203.gs.xz (see borders of UI elements)
PS2

Master SW

PR SW

roguegalaxytext.gs.xz (black line at top in both PS2 and PR, though alignment of circle UI elements is a bit more centered compared to master)
PS2

Master SW

PR SW

Dragon Quest VIII - Journey of the Cursed King_SLES-53974_20230321134214.gs.xz ("HP" and "MP" in PS2 and PR are a bit more stretched and may look slightly worse than master)
PS2

Master SW

PR SW

Suggested Testing Steps
Use any renderer, as both SW or HW are affected. Many games may not have not visual differences (although a large number of pixel might have tiny differences), or have subtle changes (UI alignment changes or single black line at edge of frame changed, etc.).
Hardware Tests/Details
Based on hardware tests the following rounding rules seems to apply when UVs are should ("should" means if the interpolation was mathematically exact) be on texel boundaries for sprites (similar conditions may apply to triangles and lines):
Note: The default behavior on the PCSX2 SW and HW renderers appears to be to round up at texel boundaries, hence the inaccuracies.
Additional details:
The hardware tests were straightforward: draw some sprites and lines with different dimensions and choose UVs in such a way that the sampling values should fall on texel boundaries. No tests were done for triangles, though I'd assume the results would be the same for axis-aligned triangles.
Did you use AI to help find, test, or implement this issue or feature?
I asked AI on advice for types of hardware tests to use to reverse GS internal precision. However, this did not end up being necessary to fix the rounding issues.