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

[Bug]: In 32bpp sprites, partially transparent pixels with an animated mask aren't correctly updated. #11538

Open
zephyris opened this issue Dec 4, 2023 · 5 comments

Comments

@zephyris
Copy link
Contributor

zephyris commented Dec 4, 2023

Version of OpenTTD

Latest nightly, Windows 10

Expected result

Using animated palette entries in an 8bpp mask for a 32bpp sprite should lead to those pixels being correctly animated, irrespective of the transparency/alpha of the 32bpp sprite.

Actual result

Fully opaque pixels in a 32bpp sprite with animated 8bpp palette entries animate correctly. Partially transparent pixels in a 32bpp sprite with animated 8bpp palette entry aren't correctly animated. eg using the following test sprites:

The problematic pixels mostly don't animate at all, but occasionally change. It seems that they are correctly animated when redraw is triggered for some other reason, eg. if the animated sprite is in a window then dragging that window around gives the expected animation while the window is in motion.

Steps to reproduce

  1. Setup a test NewGRF with index entries, eg. the following, which replaces the diagonal bus view used as the company colour preview in the company window.
grf {
	grfid: "RWZ1";
	name: string(STR_GRF_NAME);
	desc: string(STR_GRF_DESCRIPTION);
	url: string(STR_GRF_URL);
	version: 3;
	min_compatible_version: version_openttd(1, 3, 0);
}

template template_256square() {
	[0, 0, 256, 256, 0, 0]
}
replace bus01(3097, "hgradient_ttdpal_8bpp.png") { template_256square() }
alternative_sprites(bus01, ZOOM_LEVEL_NORMAL, BIT_DEPTH_32BPP, "vgradient_alpha_32bpp.png", "hgradient_ttdpal_8bpp.png") { template_256square() }

32bpp sprite:
vgradient_alpha_32bpp

8bpp mask:
hgradient_ttdpal_8bpp

  1. Load the NewGRF and look at the pixels... Animation works for the bottom row (100% opacity/0% transparency) but not the other rows.
@PeterN
Copy link
Member

PeterN commented Dec 4, 2023

This is the nature of palette remaps, if it is partially transparent then it is no longer a paletted colour, and cannot be palette-animated.

Not really a bug.

@zephyris
Copy link
Contributor Author

zephyris commented Dec 4, 2023

It's not that it doesn't animate, it doesn't animate correctly. That means it gets glitchy when partial redraws are triggered:
tmpanim

If they shouldn't animate then it shouldn't animate at all... (but it would be more useful if it did animated!)

@PeterN
Copy link
Member

PeterN commented Dec 4, 2023

The actual fix is to not use transparent animated pixels in your sprites.

It partially "animates" because it uses the current animated colour when it is drawn, but those cannot be updated by the palette animator. There is no "unanimated" colour at those palette indices.

@zephyris
Copy link
Contributor Author

zephyris commented Dec 4, 2023

I don't quite follow the logic there - how does lightening/darkening of animated colours work then?

In any case, if this is expected behaviour then it's an nml/nfo/newgrf documentation issue.

@PeterN
Copy link
Member

PeterN commented Dec 4, 2023

That is a special case that doesn't involve transparency. It's unrelated. When transparency is involved you are mixing (at least) two different colours together.

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

No branches or pull requests

2 participants