Maniphest T80684

obj file import automatically connects the colour output of all png's into the principled's alpha input, needs to be the alpha output.
Closed, Resolved

Assigned To
Bastien Montagne (mont29)
Authored By
michael campbell (3di)
Sep 11 2020, 7:46 AM
Tags
  • BF Blender
  • Import/Export
  • Add-ons (BF-Blender)
Subscribers
Bastien Montagne (mont29)
michael campbell (3di)
Richard Antalik (ISS)
Tokens
"Yellow Medal" token, awarded by 3di.

Description

System Information
Operating system: Windows-10-10.0.18362-SP0 64 Bits
Graphics card: GeForce GTX 1070/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 452.06

Blender Version
Broken: version: 2.91.0 Alpha, branch: master, commit date: 2020-09-09 00:05, hash: rBb8840c105a4e
Worked: (newest version of Blender that worked as expected)

Short description of error

obj file import automatically creates a second image texture node if the material has a .png file assigned, and then connects the colour output of the second image node into the principled's alpha input, needs to be the alpha output which connects to the principled alpha input.

Import file and examine material of imported object

Revisions and Commits

rB Blender
Audited

Event Timeline

michael campbell (3di) created this task.Sep 11 2020, 7:46 AM
Richard Antalik (ISS) changed the task status from Needs Triage to Needs Information from User.Sep 15 2020, 2:40 PM
Richard Antalik (ISS) added a subscriber: Richard Antalik (ISS).

Please upload example file.

Is source of .obj file .blend file? if so, please upload .blend file

michael campbell (3di) added a comment.Sep 15 2020, 4:14 PM

Hi Richard, file below. Created in 3ds max, but that doesnt make any difference as the same issue happens in all fbx files regardless application used to generate file. To confirm this once you've imported the file, select the model, go to the shader editor, delete the image texture that's conected to the alpha, export from blender, then reimport. The same bug will arise.

ps, obj doesnt do anything with alpha if the texutre is .png. Ideally if the base colour has a .png file, then the alpha output should lead to the principled alpha input. this will always make sure that if there is an alpha channel it will be used, and if there isn't it won't make a difference.

Richard Antalik (ISS) changed the task status from Needs Information from User to Confirmed.Sep 15 2020, 6:49 PM
Richard Antalik (ISS) updated the task description.
Richard Antalik (ISS) added projects: Pipeline, Assets & I/O, Import/Export.
Bastien Montagne (mont29) added a subscriber: Bastien Montagne (mont29).Sep 16 2020, 12:01 PM

@Richard Antalik (ISS) this is add-on stuff, not DATA/IO area!

@michael campbell (3di) looks like you are confusing the formats here, you are talking about OBJ but provides an FBX?

In any case, am not sure there is actually a bug here, sounds more like known limitations (translating a static shading like in FBX or OBJ, to a nodal material is always tricky, exact match is seldom possible).

Bastien Montagne (mont29) changed the task status from Confirmed to Needs Information from User.Sep 16 2020, 12:01 PM
Bastien Montagne (mont29) edited projects, added Add-ons (BF-Blender); removed Pipeline, Assets & I/O.
michael campbell (3di) added a comment.EditedSep 16 2020, 12:05 PM

It’s easy to code, I’ve already written it. Just need to assign the base couloir textures alpha out to the principled alpha in if the format is .png.

Yep, it’s the fbx Importer that gets it wrong, the obj Importer doesn’t bother trying :)

michael campbell (3di) added a comment.EditedSep 16 2020, 12:13 PM

Easier to do in the importer, but here's how I do it after the fact.

import bpy

mats = bpy.data.materials


for mat in mats:
        
            
    principled = mat.node_tree.nodes["Principled BSDF"]
    socket = principled.inputs[18] # alpha input
    links = mat.node_tree.links


    #generate array of links that have a textures colour output plugged into a principled's alpha
    tex_ps_links = [l for l in links 
        if l.from_node.type == 'TEX_IMAGE' 
        and l.from_socket.name == "Color"
        and l.to_node.type == 'BSDF_PRINCIPLED'
        and l.to_socket.name == "Alpha"]
        

    for l in tex_ps_links:
        # print tex node image
        texnode = l.from_node
        print(texnode.name)
        
         #create new link
        mat.node_tree.links.new(principled.inputs[18], texnode.outputs['Alpha'])
michael campbell (3di) added a comment.EditedSep 16 2020, 12:19 PM

regardless though, it's definitely a bug, otherwise every imported material that uses a .png will render semi transparent unless the user goes through each material and swaps over the sockets.

michael campbell (3di) added a comment.Sep 16 2020, 1:28 PM

the importer is presumably already checking if the imported diffuse is using a .png texture rather than a .jpg etc, because it only creates the additional image texture node in the case of png. So in the bit of code that creates the second image texture node, it must also be creating the link between the colour socket and the principled alpha socket. So it would appear to be just an error in the line of code that creates the link:

this is being done:

mat.node_tree.links.new(principled.inputs[18], texnode.outputs['Color'])

instead of:

mat.node_tree.links.new(principled.inputs[18], texnode.outputs['Alpha'])

I can't see much point in creating a second image texture node though, why not just connect from the original's alpha to the principled's alpha?

Bastien Montagne (mont29) closed this task as Resolved by committing rB0696eaa3e84e: Fix T80684: Node shader wrapper: Tweak handling of alpha textures..Sep 16 2020, 4:40 PM
Bastien Montagne (mont29) claimed this task.
Bastien Montagne (mont29) added a commit: rB0696eaa3e84e: Fix T80684: Node shader wrapper: Tweak handling of alpha textures..
michael campbell (3di) awarded a token.Sep 16 2020, 4:51 PM