Firch / Bunco

36 stars 7 forks source link

Fix haloing on card suits #34

Closed unascribed closed 3 months ago

unascribed commented 3 months ago

Hi! Thanks for the great mod.

The card suit haloing when "Pixel Art Smoothing" is enabled appears to be caused by Balatro interpreting the color values in the "fully transparent" pixels, due to a faulty color interpolation shader. The base game's assets fix this by having the surrounding pixels of card suits and the like be surrounded by a "moat" of fully-transparent but correctly-colored pixels.

Pre-5.0 versions of Bunco still had these moats for some textures (e.g. the Exotic suits) but not others (e.g. the base game recolored high contrast suits), but at some point these textures were optimized to indexed color and had all their transparent color data removed.

This PR makes the files significantly bigger (sorry!) but also makes them render correctly in-game.

Before:

image image image

After:

image image image

I'm not familiar enough with Balatro (or this mod, having gone in spoiler-free) to know if any other parts of the mod are likely to be affected by this issue, but this at least fixes the most obvious occurrence.

Firch commented 3 months ago

Thanks for the PR! Didn't even know this was a thing. May I ask how to do this or to check if it exists? I use Aseprite, but I'm checking & comparing the sprites (original and from the PR) and it shows zero difference.

unascribed commented 3 months ago

Absolutely no idea if Aseprite is capable of dealing with this. I created this PR by going into GIMP, creating a duplicate of the layer, median blurring the layer, moving the layer down and then adding a layer mask that was all black and then exporting the file as a PNG with transparent color saving enabled, which is kind of a lot of hoops now that I'm writing it out. Setting the layer to zero transparency isn't good enough as GIMP tries to be smart when doing compositing and will make all of the fully transparent colors black, which is exactly what I'm trying to avoid.

You can see this on an opened file in GIMP by going to the Channels dock and disabling visibility for the alpha channel, or by using the eraser in anti-erase mode.

Strictly, this is a bug in whatever shader Balatro is using here, but I would not really expect fixing that bug to be in-scope for Bunco. And LocalThunk's way of fixing this seems to be to just work around it with this hack.

When I learned this was why this was happening, I was quite surprised — and the fix is pretty annoying to upkeep as lots of tools do not maintain transparent colors; they're supposed to be meaningless. Simply creating this PR and using oxipng without it stripping my fully transparent colors again was painful.

Firch commented 3 months ago

After investigating with Steamodded team and my friend, we found out that this border actually appears first on the 1x version of the sprites, and then is upscaled to 2x afterwards - this is probably the reason why all the sprites have one pixel of an empty space (that is not really empty, as it turns out now) between them. We'll do a script to automate all the sprites in the mod and then I'll update the repo. I will not merge the PR just for the sake of consistency, but this PR turned out very, very useful!

Again, thank you very much! 🫡