KhronosGroup / glTF-Blender-IO

Blender glTF 2.0 importer and exporter
https://docs.blender.org/manual/en/latest/addons/import_export/scene_gltf2.html
Apache License 2.0
1.48k stars 316 forks source link

Objects with semi-transparent PNGs are not semi-transparent #194

Closed soadzoor closed 5 years ago

soadzoor commented 5 years ago

Hi,

I'm trying to create a leaf, which is typically a rectangle with a semi-transparent PNG texture. I have the following node setup: capture4

And while it looks correct within blender (with viewport alpha: alpha blend): capture5

It looks very strange after exported: capture6

Not only it's not transparent where it should be, but my guess is that the R and G channels are swapped for some reason.

Am I doing something wrong with the node setup? Or is it something else?

Here's the blend file, if anyone wants to test: test.zip

AlexMuir commented 5 years ago

Definetly [Edit: NOT] a bug, but I don't think it's related to transparency. I re-exported your PNG on a white background with no transparency, plugged it straight into the Base Color node and I still get funky colors.

image

image

image

soadzoor commented 5 years ago

Definitely a bug, but I don't think it's related to transparency. I re-exported your PNG on a white background with no transparency, plugged it straight into the Base Color node and I still get funky colors.

Oh, thanks for checking. This gradient color gave me an idea that it might have vertex colors, so I checked, and it does!

Removing the vertex colors solved this "funky-color-issue", but it's still not transparent where it should be. Any idea on that?

AlexMuir commented 5 years ago

Ah good. I've tried a few things but nothing working so far. I think that the exporter only really works with the Principled BSDF node, and anything like a mix shader that comes after that isn't exported. That's my understanding anyway. I notice that the BaseColor input for the principled node accepts RGBA values, not just RGB. I can't figure out how to recombine the RGBA from the Image Texture node using its 'Color' and 'Alpha' outputs. I might be heading in the wrong direction here anyway!

soadzoor commented 5 years ago

From the docs, here's an example for a basic node setup for gltf: https://gltf-blender-io-docs-gbueavkvns.now.sh/_images/addons_io-gltf2-material-principled.png

So I guess transparency should work in a similar way to emission. I know we still have problems with emission as well, so I guess we have to wait (or contribute) to get these things done.

AlexMuir commented 5 years ago

I hadn't seen this manual. What route did you use to get to that image? The addons -> glTF 2 section is a 404 at the moment.

soadzoor commented 5 years ago

I hadn't seen this manual. What route did you use to get to that image? The addons -> glTF 2 section is a 404 at the moment.

I've found it among the issues, right here: https://github.com/KhronosGroup/glTF-Blender-IO/issues/97

This is the link for the current prototype of the docs: https://gltf-blender-io-docs-fuznnktuig.now.sh/addons/io_gltf2

donmccurdy commented 5 years ago

Docs are now live, here: https://docs.blender.org/manual/en/dev/addons/io_gltf2.html

Are you using the Alpha Clip mode on the material? I think you'll need that.

soadzoor commented 5 years ago

Docs are now live, here: https://docs.blender.org/manual/en/dev/addons/io_gltf2.html

Are you using the Alpha Clip mode on the material? I think you'll need that.

I can confirm that it looks the same if I use Alpha Clip

donmccurdy commented 5 years ago

Oops, should have said using Alpha Clip mode, and also setting a clip threshold >0. With 0.5, and vertex colors disabled, I see:

screen shot 2019-02-14 at 9 48 49 am

... the edges are a bit rough, but adjusting the clip threshold should resolve that.

soadzoor commented 5 years ago

Oh, you're right, it works that way. So is it the correct behavior? I guess this method only works if I want either fully opaque, or fully transparent pixels. But what if I want a semi-transparent look on some parts?

donmccurdy commented 5 years ago

If you want semi-transparent pixels, use the Alpha Blend mode instead. But note that semi-transparency will be subject to various limitations in realtime engines (example, example) – for cutout/mask shapes like leaves on a tree, Alpha Clip will be much better.

This exporter cannot parse nodes like Mix Shader, so the alpha mode must be set appropriately.

soadzoor commented 5 years ago

Ok, thanks!