atteneder / glTFast

Efficient glTF 3D import / export package for Unity
Other
1.21k stars 239 forks source link

Issue rendering textures with images that have transparency #700

Open acesolucoes opened 1 week ago

acesolucoes commented 1 week ago

Describe the bug I am trying to view a GLTF model with textures whose PNG already has transparency. For me the rendering is a little weird for reason that I will explain:

These are the GLTF being rendered by GLTFast and by the Windows embedded 3d viewer comparison

There is some noticable differences in parts where the image used by texture have a great deal of transparency: comparison2

The transparency in this region is very high, and I was expecting to see a color more reddish instead of whitish/greyish due to the low amount of alpha (I highlighted in blue the region I had selected for displaying the color information including alpha):

viewing alpha in GIMP

I have verified this problem in Unity 2022.1.13f1 and Unity 2022.3.18f1 using URP in both and GLTfast 5.0 and GLTFast 6.6 and 6.7, so, it is not a new problem. In my understanding the rendering output by the viewers like the WIndows Embedded and others in web that I have tested are saner that which is presented by GLTFast. Simply put, I could achieve a similar look by GLTF pasting the image (with alpha taken away) on top of a red background that matches with the base color texture of my sample. So, my conclusion is that in these cases the transparency is being ignored.

Additionally in 6.6 I could confirm the same issue in the builtin pipeline and HDRP I couldn't check because it was plainly wrong (It was solved in https://github.com/atteneder/glTFast/issues/699 that I had opened).

All tests were made in Windows 11, both in Editor as in a build. It follows the test sample that I have used for my tests (using builtin pipeline).

Test GLTF.zip

atteneder commented 6 days ago

Thanks for reporting,

There seems to be a color space issue with the alpha channel specifically. Even worse, it's reproducible with the URP Unlit shader:

image

left to right:

  1. Opaque URP/Unlit with a pre-composited texture on a plane. Assuming this is the target.
  2. Transparent URP/Unlit with your texture in front of a black unlit plane. Notice that it's considerably brighter, similar to your report.
  3. glTF-unlit shader graph with a fix that converts the alpha from sRGB/gamma to linear space (without that fix it looks just like 2.).

But before shipping a fix I'd like to fully understand the root of the issue first.

atteneder commented 6 days ago

It's also reproducible with Lit/Standard shaders and in Built-In render pipeline as well. The problem only exists in linear color space projects. When switching to gamma it's correct.