godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Add option to "Preserve alpha test coverage" on mip map generation for texture import #9152

Open Arnklit opened 8 months ago

Arnklit commented 8 months ago

Describe the project you are working on

Various 3D projects.

Describe the problem or limitation you are having in your project

Materials using alpha scissor look bad farther away from camera due to higher mip map levels making them dissolve.

Example: Close up looks good. image

Zoomed out the alpha clipping makes the leaves a noisy disintigrating mess. image

There is already a solution for this, which is to use .dds textures that are exported with mipmaps that have alpha testing in mind: image

The problem is most people don't have the technical knowledge to know why this is happening or how to resolve it and knowing how to export .dds textures and what settings to use is quite a burden on users.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

I suggest we add an option to the texture importer to generate the mip maps that preserve the alpha test coverage.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Add an option in the mipmaps section. Possibly it could be set to detect and auto enable when used with alpha scissor.

image

If this enhancement will not be used often, can it be worked around with a few lines of script?

This would be used often in 3d scenes.

Is there a reason why this should be core and not an add-on in the asset library?

It would have to be in core to be useful.

Calinou commented 8 months ago

Can you link to an algorithm that performs this processing?

Arnklit commented 8 months ago

I believe this is the code used for GIMP's .dds exporter. https://github.com/GNOME/gimp/blob/748b2b5767dd8ce14b961cee178800420150a5ed/plug-ins/file-dds/mipmap.c#L933

Arnklit commented 8 months ago

Looking around a bit. I see that O3DE also has this option and is open source, so might be a good place to look.

https://www.docs.o3de.org/docs/user-guide/assets/texture-settings/interface/#mipmap-settings

https://github.com/o3de/o3de/blob/f1c7eeedfeba9f68c95c385ed75ad1e6db5932a9/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/Converters/AlphaCoverage.cpp#L88

EriKWDev commented 4 months ago

Ignacio Castanos MIT licensed implementation was succesfully used in The Witness.

Explanation:http://the-witness.net/news/2010/09/computing-alpha-mipmaps/?source=post_page-----8b177335ae4f--------------------------------

Code: https://github.com/castano/nvidia-texture-tools/blob/aeddd65f81d36d8cb7b169b469ef25156666077e/src/nvimage/FloatImage.cpp#L1379

https://github.com/castano/nvidia-texture-tools/blob/aeddd65f81d36d8cb7b169b469ef25156666077e/src/nvimage/FloatImage.cpp#L1424