godotengine / godot

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

PNG files colors are incorrect when imported as Texture2D #81567

Closed czlowiekimadlo closed 1 year ago

czlowiekimadlo commented 1 year ago

Godot version

4.0.4.stable, 4.1.1.stable

System information

Windows 10 - Godot v4.1.1.stable - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3080, Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz (16 Threads), same on Godot v4.1.1.stable - macOS 13.5.2 - Vulkan (Forward+) - integrated Apple M2 - Apple M2 (8 Threads), also same on Steam Deck.

Issue description

When a PNG file is being imported as Texture2D to be used in a material, the colors are interpreted wrong, making the model look completely different than in the modelling tool. Importing the same PNG as an Image makes the colors correct, but I don't know what are the performance consequences of such action.

A screenshot from the minimal reproduction project shows Texture2D PNG on the left (incorrect) and Image PNG on the right (colors as expected).

Note: the imported meshes have material override on them so that I can apply two different albedo textures in the same manner. Removing the override material on the left model will not make a difference in it's appearance.

Steps to reproduce

Minimal reproduction project

https://github.com/czlowiekimadlo/Godot-texture-bug

AThousandShips commented 1 year ago

Does this happen if you import it without compression?

czlowiekimadlo commented 1 year ago

This example is without compression. If I select VRAM compressed, there is no difference. Selecting Basis Universal makes the colors different, but still incorrect.

timothyqiu commented 1 year ago

This example is without compression. If I select VRAM compressed, there is no difference. Selecting Basis Universal makes the colors different, but still incorrect.

The texture on the left has Compress > Mode set to VRAM Compressed, so it's compressed.

You are probably checking Detect 3D > Compress To which works like a 3D override. When set to Disabled, it does not change the compress mode for 3D.

It's recommended to use Lossless compress mode for pixel art style textures in 3D. See https://docs.godotengine.org/en/stable/tutorials/assets_pipeline/importing_images.html#detect-3d

Calinou commented 1 year ago

This is likely a sRGB/linear conversion issue rather than a VRAM compression issue, as textures used in 3D use linear color space instead of sRGB.

czlowiekimadlo commented 1 year ago

This example is without compression. If I select VRAM compressed, there is no difference. Selecting Basis Universal makes the colors different, but still incorrect.

The texture on the left has Compress > Mode set to VRAM Compressed, so it's compressed.

You are probably checking Detect 3D > Compress To which works like a 3D override. When set to Disabled, it does not change the compress mode for 3D.

It's recommended to use Lossless compress mode for pixel art style textures in 3D. See https://docs.godotengine.org/en/stable/tutorials/assets_pipeline/importing_images.html#detect-3d

You are correct, I misunderstood what that last option did. Changing mode to VRAM Uncompressed does indeed resolve the issue. Lossless works as well. Not sure why I have not tried changing that one setting...

Calinou commented 1 year ago

Closing per the above comment.