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.45k stars 306 forks source link

VertexColor: Convert Float to RGB #2273

Open Blood-Machine opened 2 weeks ago

Blood-Machine commented 2 weeks ago

Describe the bug When exporting, no matter the settings, alpha channel for vertex paint/color attribute is exported as blank

To Reproduce Steps to reproduce the behavior: Visualise color attribute alpha with a shader Erase alpha on the default blender cube Export as glb/glTF Import the exported file Now it will have no vertex alpha, but other colors will be preserved

Expected behavior On importing, vertex alpha should be the same

.blend file/ .gltf (mandatory) attached a file with a cube with visualised vertex color exporting it results in a completely blank cube

Version

Additional context Add any other context about the problem here. vertexAlphaCube.zip

julienduroure commented 2 weeks ago

Hello, New version of Blender try to better manage how alpha are exported to glTF. You have to plug the alpha socket if you want to export alpha. BaseColor socket is for RGB only:

image

Blood-Machine commented 2 weeks ago

This seems to have exactly the same results(at least did for me when i tested it with a few different files, including the one uploaded here), export with plugging in alpha as not plugging in alpha Would it be possible to at least add a toggle to always include alpha ? Since i think it would be optimal to have it export alpha regardless of materials used, for most game assets and mass exporting for example. image

julienduroure commented 2 weeks ago

Hello, In Blender 4.2 beta. Here are your VC data:

image

Here are the exported VC data on glTF, with the following setup:

image

image

==> Alpha are exported correctly.

glTF exporter does not manage float socket to RGB socket. So no RGB is detected on your VC at export. If you want to manage RGB+A VC, you need a setup like this:

image

So I don't think there is any bug here. But an enhancement can be made by detecting float => Color setup

Blood-Machine commented 2 weeks ago

Hi, thank you for explanation Oh, willl try switching to 4,2 then Since in 4.1 it just doesn't export alpha whatsoever as far as I can tell, at least nothing reads it

Though the enhancement would be immensely appreciated

Blood-Machine commented 2 weeks ago

Okay, tested it in 4.2, it exports alpha if the alpha channel is connected, it is broken in 4.1 for future reference For now will use a workaround with plugging and unplugging the alpha channel

Thanks very much for help

EDIT: Oh, sorry, I misunderstood the enhancement thing,thought meant that if float was detected like, in vertex value then it would be used. My actual need for application is to actually have the alpha channel as such (since using it for vertex colour masking for texture blending) Is there a way to just always export entire rgba for vertex colour, even in changing something in code or sth that I could do myself?

Blood-Machine commented 2 weeks ago

Might need a little further elaboration, since did a bit more testing, and Alpha vertex seems to only get exported if it's plugged directly into the alpha port, if there's even just a multiply it fails to be exported, so it still seems bugged.

julienduroure commented 2 weeks ago

This setup exports the alpha channel:

image

image

The multiply node is ignored. There is no multiply Vertex Color Factor in glTF specification.

We can't handle hundred of nodes and thousand of node links/combination, as we need to navigate in node programmatically, as there is no bake available in Blender node tree.

Blood-Machine commented 2 weeks ago

I apologise for wording that poorly The issue is not that the nodes are ignored, rather than they aren't. I uploaded the files I'm working with. You are correct, multiply node does get ignored(I misremembered which one I tried, sorry ;;), but any other operation, such as maximum, minimum, mix, etc, result in alpha not getting exported at all. Seems as if anything that's not a multiply operation essentially blocks it.

To clarify Intended behaviour: Alpha channel passes through "minimum" float operation node and into the alpha plug in the shader node editor, on export, this node gets ignored, and alpha channel for vertex gets exported Current Behaviour: lpha channel passes through "minimum" float operation node and into the alpha plug in the shader node editor, on export, alpha vertex channel is blank (edit: apologies posted wrong file for the vertex alpha cube previously)

HallwayTest.zip

vertexAlphaCube3.zip

Blood-Machine commented 2 weeks ago

For extra testing, I've tested a lot of operation nodes So far only multiply seems to actually lead to alpha getting exported, if it passes through add, substract, divide, multiply add, power, minimum, maximum ,mix and a few others, they don't get ignored, they simply don't result in any alpha getting exported. Multiply seems to be the only one getting ignored