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

[3.x] Allow disabling the alpha trim on texture atlas creation. #57165

Conversation

jasonwinterpixel
Copy link
Contributor

@jasonwinterpixel jasonwinterpixel commented Jan 24, 2022

3.x version of #57163

When creating an AtlasTexture, godot automatically removes unused pixels from the borders of the images. This is unexpected behaviour that changes the size of the texture. In general, if a developer asks for a texture of a specific size with transparent pixels in it, that's what the developer should get. Changing the size and contents of the texture can cause a plethora of issues.

For our project, this broke all of our styleboxes, as they had region's specified which were invalid because the size of the texture changes.

This PR creates an option for AtlasTexture importers to allow developers to enable the trim on transparent pixels on the borders. It defaults to Off, which I think is better, more expected behaviour. [ Edit - now it default to On to maintain compatibility ]

Related: #53390

@Calinou
Copy link
Member

Calinou commented Jan 24, 2022

Doesn't disabling alpha trimming negate most of the benefits of using a texture atlas in the first place? As I understand it, alpha trimming is the main way to reduce memory usage when using a texture atlas (along with reducing fillrate usage). While desktop devices have plenty of memory to spare now, this isn't necessarily the case on low-end mobile devices.

This PR creates an option for AtlasTexture importers to allow developers to enable the trim on transparent pixels on the borders. It defaults to Off, which I think is better, more expected behaviour.

While changing the default value in master is acceptable, the default value should be left to On on 3.x to avoid breaking compatibility with existing projects. This is because we now follow a strict compatibility policy within a major version.

@brianwinterpixel
Copy link
Contributor

Doesn't disabling alpha trimming negate most of the benefits of using a texture atlas in the first place? As I understand it, alpha trimming is the main way to reduce memory usage when using a texture atlas (along with reducing fillrate usage).

For us, we're using it for reducing draw calls. Binding the same texture for dozens of canvasitems lets them all draw in one batch.

@jasonwinterpixel jasonwinterpixel force-pushed the 3.x-allow-disable-alpha-trim-texture-atlas branch from 790d021 to c89992d Compare January 24, 2022 23:24
@jasonwinterpixel
Copy link
Contributor Author

the default value should be left to On

Ok. I changed the default to 'On'.

@jasonwinterpixel jasonwinterpixel force-pushed the 3.x-allow-disable-alpha-trim-texture-atlas branch from c89992d to 177041b Compare February 19, 2022 20:01
@akien-mga akien-mga merged commit 6071d78 into godotengine:3.x Feb 20, 2022
@akien-mga
Copy link
Member

Thanks!

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.

4 participants