godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.37k stars 21.06k forks source link

TileSet not detecting almost zero alpha tiles #57680

Open rakkarage opened 2 years ago

rakkarage commented 2 years ago

Godot version

v4.0.alpha1.official [31a7ddbf8]

System information

Windows 10

Issue description

Light

Here is a set of 32 'light' tiles that are black with changing alpha... When the TileSet automatically detects tiles or I manually trigger a detection with the menu item it ignores 4 tiles with non-zero alpha. The menu item says "Create Tiles in Non-Transparent Texture Regions" so I expect it to ignore the last one because it has alpha 0 but the rest do not.

Thanks.

Steps to reproduce

  1. Open TileSet and "Create Tiles in Non-Transparent Texture Regions"

Minimal reproduction project

https://github.com/rakkarage/TestLight

groud commented 2 years ago

Ok so I found the issue. This is the code used on the TileSet's side:

for (int region_x = region.get_position().x; region_x < region.get_end().x; region_x++) {
    for (int region_y = region.get_position().y; region_y < region.get_end().y; region_y++) {
        if (texture->is_pixel_opaque(region_x, region_y)) {
            is_opaque = true;
            break;
        }
    }
    if (is_opaque) {
        break;
    }
}

The issue comes for the is_pixel_opaque function, which is called here on an ImageTexture.

The ImageTexture class uses this to generate it's alpha bitmap:

alpha_cache->create_from_image_alpha(img);

We can provide a custom threshold for create_from_image_alpha (the default in 0.1, which causes the issue), but we currently have no way to make this configurable in ImageTexture.

So I don't know, we could add a property to ImageTexture maybe, or lower the default.

rakkarage commented 1 year ago

0.1 seems high for default? Everything under 10% alpha is discarded? I tested with 0.01 and my example works fine. Edit: I am thinking I am fixing it in the gif by selecting those last few tiles... but it is already too late and the engine has not copied them? I am selecting nothing? :(

AThousandShips commented 1 year ago

but it is already too late

You can just manually create those tiles

rakkarage commented 1 year ago

Thanks. Sorry, I was assuming it happening in other places too like tile merge, etc but they all come through merge fine. It is just a dialog not actually editing data/image. 0.1 still does seem high... like me.