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

Closed
opened 2020-09-11 07:46:05 +02:00 by michael campbell · 15 comments

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: blender/blender@b8840c105a
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.

png import colour as alpha.fbx

Import file and examine material of imported object

**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: `blender/blender@b8840c105a` 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. [png import colour as alpha.fbx](https://archive.blender.org/developer/F8883690/png_import_colour_as_alpha.fbx) Import file and examine material of imported object

Added subscriber: @3di

Added subscriber: @3di

Added subscriber: @iss

Added subscriber: @iss

Changed status from 'Needs Triage' to: 'Needs User Info'

Changed status from 'Needs Triage' to: 'Needs User Info'

Please upload example file.

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

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

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.

png import colour as alpha.fbx

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.

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. [png import colour as alpha.fbx](https://archive.blender.org/developer/F8883690/png_import_colour_as_alpha.fbx) 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.

Changed status from 'Needs User Info' to: 'Confirmed'

Changed status from 'Needs User Info' to: 'Confirmed'

Added subscriber: @mont29

Added subscriber: @mont29

@iss this is add-on stuff, not DATA/IO area!

@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).

@iss this is add-on stuff, not DATA/IO area! @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).

Changed status from 'Confirmed' to: 'Needs User Info'

Changed status from 'Confirmed' to: 'Needs User Info'

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 :)

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 :)

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'])

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']) ```

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.

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.

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?

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?

This issue was referenced by blender/blender@0696eaa3e8

This issue was referenced by blender/blender@0696eaa3e84e9394518e9bc86217291aa58dcf13

Changed status from 'Needs User Info' to: 'Resolved'

Changed status from 'Needs User Info' to: 'Resolved'
Bastien Montagne self-assigned this 2020-09-16 16:40:11 +02:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#80684
No description provided.