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 317 forks source link

What Alpha socket is being use to determine Alphamode - always defaults to BLEND (should be OPAQUE)? #2261

Closed ronh991 closed 3 months ago

ronh991 commented 3 months ago

Describe the bug Depending on the shader node set up, my export will always default to alphaMode = BLEND , this cause flickering in the MSFS game engine. as the materials are always trying to blend with their background textures etc.

the gather_alpha_info function in gltf2_blender_search_node_tree.py will always pass through to the last if and default to BLEND

    # Set alpha mode
    if info['alphaMode'] is None:
        # Is zero? Weird, but okay.
        if info['alphaFactor'] == 0:
            info['alphaMode'] = 'MASK'
            info['alphaCutoff'] = 0.5
        else:
            info['alphaMode'] = 'BLEND'

Blender BSDF has alphamode naming as straight, premultiplied, channel packed and none. Is there a conflict with BLEND, OPAQUE, DITHER and MASK

To Reproduce Steps to reproduce the behavior: Utilize a shader node structure where alpha from texture is not connected in the base color, and utilize the ASOBO exporter updated to 4.2 (with all the other issues resolved)

Expected behavior The default alphamode should be OPAQUE?

Screenshots If applicable, add screenshots to help explain your problem.

.blend file/ .gltf (mandatory) a blend file will not work without the MSFS exporter edit: yes it does set to blend without the MSFS/ASOBO exporter

alphamode_test.zip

Version

Additional context trying to understand where the to_node_nav selects the alpha socket.

an example of error info is these materials should be opaque

        {
            "alphaMode":"BLEND",
            "name":"Tailwind Mechanicals",
            "pbrMetallicRoughness":{
                "baseColorTexture":{
                    "index":3
                },
                "metallicFactor":0.1090909093618393,
                "roughnessFactor":0.2672727108001709
            }
        },
        {
            "alphaMode":"BLEND",
            "name":"Yellow Plastic",
            "pbrMetallicRoughness":{
                "baseColorFactor":[
                    0.6104918718338013,
                    0.7991039156913757,
                    0.07818762212991714,
                    0.3436855673789978
                ],
                "metallicFactor":0,
                "roughnessFactor":0.30000001192092896
            }
        },

however this material has to have blend - windshield transparent

        {
            "alphaMode":"BLEND",
            "name":"Tailwind Mechanicals",
            "pbrMetallicRoughness":{
                "baseColorTexture":{
                    "index":0
                },
                "metallicFactor":0.1090909093618393,
                "roughnessFactor":0.2672727108001709
            }
        }
julienduroure commented 3 months ago

Hello, Not sure to understand why you think your material should be "OPAQUE". OPAQUE is the default, but in your node setup, your alpha socket of Principled BSDF node is linked to an alpha of a texture, so the alpha mode is set to BLEND.

There is no link between the alpha mode of glTF (OPAQUE, BLEND or MASK), and how alpha is managed in a texture file ( straight, premultiplied, channel packed and none)

ronh991 commented 3 months ago

Thank you, my point being - this is new functionality to me. The April 6th branch of 4.2 and 4.1.1 respects my setting the alphamode to OPAQUE. This is a game engine restriction - I can't change.

These are without the MSFS addon enabled - strictly Khronos gltf export

4.1 does this

        {
            "name":"Fuselage",
            "normalTexture":{
                "index":0
            },
            "occlusionTexture":{
                "index":1
            },
            "pbrMetallicRoughness":{
                "baseColorTexture":{
                    "index":2
                },
                "metallicFactor":0,
                "metallicRoughnessTexture":{
                    "index":1
                },
                "roughnessFactor":0.5
            }
        },

4.2 now does this

        {
            "alphaMode":"BLEND",
            "name":"Fuselage",
            "normalTexture":{
                "index":0
            },
            "occlusionTexture":{
                "index":1
            },
            "pbrMetallicRoughness":{
                "baseColorTexture":{
                    "index":2
                },
                "metallicFactor":0,
                "metallicRoughnessTexture":{
                    "index":1
                },
                "roughnessFactor":0.5
            }
        },

As to the Straight, pre multipled - that is an image.alpha_mode variable in Blender. - so I asked if this is new or why it has the same name as alphamode.

Seems I am getting things mixed up as the naming does not match the my expectations. Blend Mode is OPAQUE, BLEND etc. but the gltf calls it alphaMode.

my expectations are that the setting of blend mode is respected.

blend mode is set to OPAQUE - but exports as BLEND DA40CGDFQ_2024 06 05_10h32m56s

julienduroure commented 3 months ago

Starting Blender 4.2 beta (today), this option does not exist anymore in Blender

image

So, alphaMode can't be set anymore with this no more existing Blender value. We now have to analyze the node tree to detect what alphamode should be exported:

ronh991 commented 3 months ago

Ack! - ok will try to work around this with material_hook.

But there is still a alphaMode gltf json variable right?

julienduroure commented 3 months ago

glTF 2.0 specification didn't change

ronh991 commented 3 months ago

Using material hook - I was able to fix - Only works with 4.2 Beta release 01b8