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

Option to export VC even if not used in node tree #2233

Closed julienduroure closed 1 month ago

julienduroure commented 1 month ago

History of this PR:

In the common usage / historically / simplicity of usage, Vertex Colors are used not only for Vertex Color, but also for transmission of other custom data. The glTF Specification propose a way to transmit custom attributes, but seem for a number of reasons, this workflow is not commonly used: Not very well know Not perfect from Blender side yet (need to use name starting with underscore to avoid exporting internally used custom attributes) Lack of implementation / easy way to retrieve data for some engine/viewer This make the end to end workflow of custom attributes not very used (from what I know)

All of these make that VC are commonly used for custom attributes transmission too, even if this goes against the glTF Specification, which says that VC must act as a multiplier of Base Color.

Setting some custom attributes in VC COLOR_0 will generate some valid glTF files, but a fully compliant glTF 2.0 viewer must use these data as a base color multiplier, probably resulting in weird shading.

Even if we truly think we need to put energy setting a global solution around custom attributes (When we say globally, it means from Blender, Unity, Godot, UE, threejs, Babylonjs, etc...), we also know that you have some pipeline and workflow already in production right now, and that the ideal solution will take some time to be implemented in all these softwares.

So here is our proposition:

This PR add a new panel with more options to choose at export:

image

This PR adds an option to export active VC as COLOR_0, even if not use in node tree as a multiplier of base color. The generated glTF can look wrong in viewer that are fully compliant with glTF, as the VC will be a multiplier of base color, where it is not in Blender viewport.

The default value is still "MATERIAL", as this is the option fully compliant with glTF Specification image

When choosing ACTIVE, a warning will explaining that your workflow can be more robust with another solution:

image

You can also choose to never export VC:

image

You can now choose to export additional VC as COLOR_1, COLOR_2, etc...

image

This also add an option to choose what to do when there is no material. You can now choose to export active VC as COLOR_0, or not export any VC.

image

bertodelrio256 commented 1 month ago

Im not an expert but this looks like the optimal solution for everyone. I would say the "export all vertex colors" should include the alpha channel of the VC as well. thank you! Im sure game engines will eventually switch to using custom attributes instead for vertex colors, but who knows how long that will be. (unreal might already but still supports VC)

Takanu commented 2 weeks ago

I think you've covered all the bases and the extra explanation for the feature is important and helpful, thanks!