godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.17k stars 98 forks source link

Add alpha support for ETC1 textures #822

Open andy-noisyduck opened 4 years ago

andy-noisyduck commented 4 years ago

Describe the project you are working on: Mobile game, targeting GL ES 2.0 devices

Describe the problem or limitation you are having in your project: The ETC1 format does not support alpha channels in textures. Currently the only way around this in Godot (whilst maintaining ES 2 support) is to use a a non VRAM compression format e.g. Godot's Lossy setting. This gives the packed asset a smaller file size, but does nothing for the VRAM needed at runtime. Using any format other than ETC1 becomes prohibitive if you have a moderately large amount of assets with transparency and are targeting mid/low end mobile devices.

Describe the feature / enhancement and how it helps to overcome the problem or limitation: There are a number of techniques that make it possible to use ETC1 w/ an alpha channel. Including:

  1. Designating a specific color (such as bright pink) to represent fully transparent. This is the simplest to implement and may be useful to get some initial support out the door quickly. This would just need an editor setting and no additional tooling to extract alpha channel.
  2. Generating alpha channel data in an additional texture and combining them (a good reference can be found at https://web.archive.org/web/20160624152133/http://malideveloper.arm.com/resources/sample-code/etcv1-texture-compression-and-alpha-channels/). This is the more flexible solution.

Both methods imply using an additional shader to apply the channel. Not all textures would need this, so it would make sense to either have this as an additional import option, or even automatic if ETC1 is selected and an alpha channel is in the imported texture.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams: Covered above.

If this enhancement will not be used often, can it be worked around with a few lines of script?: You could manually extract an alpha channel from your images (there are tools to do this), and apply a shader to every texture to implement the channel. It would be pretty unfriendly to manage this (and a massive pain to re-extract the alpha channels on any image change). It's a nasty combination of more code and more tooling.

Is there a reason why this should be core and not an add-on in the asset library?: ES 2.0 support is here to stay, and forms a core part of Godot's mobile offering (along with Vulkan when ES 3 support is eventually dropped). Working with textures is an integral part of any game engine, and to me it makes sense to have equal texture support on all target platforms.

It is not clear to me how many mobile games are being developed in Godot at the moment - though we clearly have aspirations of increasing that number, and better support is needed if we are to continue to do that.

As a reference point, Unity decided to implement this as a core part of their offering.

Mojko commented 4 years ago

I'm just wondering if this will be coming soon? Is it planned for 4.0?

Calinou commented 4 years ago

@Mojko I don't think this will be implemented soon unless someone does the required work.

Also, 4.0 will not feature a GLES2 renderer for 3D, making ETC1 support not really useful anymore (since using VRAM compression in 2D is ill-advised).