Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shader_recompiler: Maintain loss of precision when folding half-float unpack. #2201

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

squidbus
Copy link
Collaborator

@squidbus squidbus commented Jan 21, 2025

When folding a pair of half unpack and pack instructions, maintain the loss of precision that should have happened from converting to 16-bit float using a quantize op.

Fixes some missing lighting in CUSA05637. The game stores a set of control bits in the alpha channel during rendering in order to control lighting properties in later shaders. This involves dividing to convert it to a normalized float when writing, and multiplying to convert it back to an 8-bit integer when reading. When writing they compensate for the loss of precision when packing to 16-bit float on PS4 by adding a constant 0.5 / 255, but without the loss in precision this ends up changing the bits when transformed back into an integer in the lighting shader.

The lighting components that are now visible in this game seem to have some color problems but those appear to be a separate issue from this.

@Randomuser8219
Copy link

This breaks textures on both Sonic and the huge worm in Stage 1.

@squidbus
Copy link
Collaborator Author

This breaks textures on both Sonic and the huge worm in Stage 1.

No, it does not. What you are seeing are the incorrect lighting colors mentioned in the PR description.

@Randomuser8219
Copy link

Oh, that explains it.

@squidbus squidbus marked this pull request as draft January 24, 2025 08:13
@squidbus
Copy link
Collaborator Author

Status of this: It seems that precision can still be an issue due to different rounding behavior with conversion to 16-bit float, so this will probably need a different solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants