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

BasisUniversal: Fix artifacts on images with resolutions not divisible by 4 #89426

Merged
merged 1 commit into from
May 2, 2024

Conversation

BlueCube3310
Copy link
Contributor

Fixes artifacts on mipmaps of BasisU-compressed images whose resolutions aren't multiples of 4.

master PR
aaa bbb

MRP: Basisu_not_mul_4_test.zip
(Requires reimporting the image).

@BlueCube3310 BlueCube3310 requested a review from a team as a code owner March 12, 2024 18:09
@AThousandShips AThousandShips added this to the 4.3 milestone Mar 12, 2024
Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@lyuma
Copy link
Contributor

lyuma commented Mar 12, 2024

I do not agree with this approach. Unless I am misreading the code, it is silently resizing the image by a few pixels which will cause blurry heavily antialiasing artifacts on any text, lines or pixel art. The user will be unaware of why their art is getting corrupted when basisu is used.

There is no requirement I can see that textures are rounded to a multiple of 4:
https://registry.khronos.org/OpenGL-Refpages/es3.0/html/glCompressedTexImage2D.xhtml
Therefore, the correct approach should be to smear average pixels over the last 4x4 blocks in each row and column, to pad the extra blocks.

If we are unable to implement this algorithm or there is not enough time to implement for 4.3, it would be better to fail the import (with a user visible warning in the import dock IMHO) than to silently resize it, and perhaps have a dropdown where the user can manually choose to resize to 4 if they want.

@BlueCube3310

This comment was marked as outdated.

@BlueCube3310 BlueCube3310 marked this pull request as draft March 13, 2024 07:49
@BlueCube3310 BlueCube3310 marked this pull request as ready for review March 15, 2024 17:54
@BlueCube3310
Copy link
Contributor Author

BlueCube3310 commented Mar 15, 2024

The processing is now done without upscaling, but with a slight variation of the smearing algorithm from Godot's etcpak implementation.

@clayjohn clayjohn requested a review from lyuma March 15, 2024 22:22
@BlueCube3310 BlueCube3310 force-pushed the basisu-mult-of-4 branch 2 times, most recently from 34e5d3f to f1deb20 Compare March 20, 2024 20:51
@BlueCube3310 BlueCube3310 changed the title Fix BasisU artifacts on images with resolutions not divisible by 4 BasisUniversal: Fix artifacts on images with resolutions not divisible by 4 Mar 26, 2024
@clayjohn
Copy link
Member

CC @lyuma

Copy link
Contributor

@lyuma lyuma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I missed this one. The algorithm for resizing, padding and smearing pixels seems correct for cases where w>2 and h>2.

I will admit I am not familiar with the w=1 and w=2 cases: I would think those also need to be padded to a multiple of 4, but maybe it is handled by basisu already so we would need to test and maybe fix separately if needed.

Copy link
Member

@fire fire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving for good luck.

@BlueCube3310
Copy link
Contributor Author

I will admit I am not familiar with the w=1 and w=2 cases: I would think those also need to be padded to a multiple of 4, but maybe it is handled by basisu already so we would need to test and maybe fix separately if needed.

Thank you for the review! Images with small resolutions would trigger the "BasisUniversal cannot unpack level 1" error. As it turns out, this bug would also happen to all textures without mipmaps due to incorrect logic for checking the mipmap count, which I've fixed now.

@akien-mga akien-mga merged commit 9122286 into godotengine:master May 2, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@BlueCube3310 BlueCube3310 deleted the basisu-mult-of-4 branch August 21, 2024 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants