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 2 years ago by 3di · 15 comments
3di commented 2 years ago

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
3di commented 2 years ago
Poster

Added subscriber: @3di

Added subscriber: @3di
iss commented 2 years ago
Collaborator

Added subscriber: @iss

Added subscriber: @iss
iss commented 2 years ago
Collaborator

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

Changed status from 'Needs Triage' to: 'Needs User Info'
iss commented 2 years ago
Collaborator

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
3di commented 2 years ago
Poster

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.
iss commented 2 years ago
Collaborator

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

Changed status from 'Needs User Info' to: 'Confirmed'
mont29 commented 2 years ago
Owner

Added subscriber: @mont29

Added subscriber: @mont29
mont29 commented 2 years ago
Owner

@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).
mont29 commented 2 years ago
Owner

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

Changed status from 'Confirmed' to: 'Needs User Info'
3di commented 2 years ago
Poster

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 :)
3di commented 2 years ago
Poster

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']) ```
3di commented 2 years ago
Poster

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.
3di commented 2 years ago
Poster

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?
Collaborator

This issue was referenced by blender/blender@0696eaa3e8

This issue was referenced by blender/blender@0696eaa3e84e9394518e9bc86217291aa58dcf13
mont29 commented 2 years ago
Owner

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

Changed status from 'Needs User Info' to: 'Resolved'
mont29 closed this issue 2 years ago
mont29 self-assigned this 2 years ago
Sign in to join this conversation.
No Label
good first issue
legacy module/Animation & Rigging
legacy module/Core
legacy module/Eevee & Viewport
legacy module/Grease Pencil
legacy module/Modeling
legacy module/Nodes & Physics
legacy module/Pipeline, Assets & IO
legacy module/Platforms, Builds, Tests & Devices
legacy module/Python API
legacy module/Rendering & Cycles
legacy module/Sculpt, Paint & Texture
legacy module/User Interface
legacy module/VFX & Video
legacy project/2.81
legacy project/2.82
legacy project/2.83
legacy project/2.90
legacy project/2.92
legacy project/2.93
legacy project/3.0
legacy project/3.1
legacy project/3.2
legacy project/3.4
legacy project/Add-ons (BF-Blender)
legacy project/Add-ons (Community)
legacy project/Alembic
legacy project/Animation & Rigging
legacy project/Asset Browser
legacy project/Automated Testing
legacy project/BF Blender: 2.8
legacy project/BF Blender: After Release
legacy project/BF Blender: Next
legacy project/BF Blender: Regressions
legacy project/BF Blender: Unconfirmed
legacy project/Blender 2.70
legacy project/Blender Cloud
legacy project/Code Quest
legacy project/Collada
legacy project/Compositing
legacy project/Core
legacy project/Cycles
legacy project/Datablocks and Libraries
legacy project/Dependency Graph
legacy project/Documentation
legacy project/EEVEE & Viewport
legacy project/Freestyle
legacy project/Game Data Conversion
legacy project/Game Engine
legacy project/Game Physics
legacy project/Game Python
legacy project/Game UI
legacy project/Geometry Nodes
legacy project/Good First Issue
legacy project/Grease Pencil
legacy project/Images & Movies
legacy project/Import/Export
legacy project/Infrastructure: Blender Buildbot
legacy project/Infrastructure: Blender Web Assets
legacy project/Infrastructure: Websites
legacy project/Modeling
legacy project/Modifiers
legacy project/Motion Tracking
legacy project/Nodes
legacy project/Nodes & Physics
legacy project/OpenGL Error
legacy project/Overrides
legacy project/Papercut
legacy project/Physics
legacy project/Pillar
legacy project/Pipeline, Assets & I/O
legacy project/Platform: Linux
legacy project/Platform: macOS
legacy project/Platforms, Builds, Tests & Devices
legacy project/Platform: Windows
legacy project/Python API
legacy project/Render & Cycles
legacy project/Render Pipeline
legacy project/Sculpt, Paint & Texture
legacy project/Straightforward Issue
legacy project/Text Editor
legacy project/Tracker Curfew
legacy project/Translations
legacy project/USD
legacy project/User Interface
legacy project/UV Editing
legacy project/VFX & Video
legacy project/Video Sequencer
legacy project/Virtual Reality
papercut
Priority › High
Priority › Low
Priority › Normal
Priority › Unbreak Now!
Status › Archived
Status › Confirmed
Status › Duplicate
Status › Needs Information from Developers
Status › Needs Information from User
Status › Needs Triage
Status › Resolved
straightforward issue
Type › Bug
Type › Design
Type › Known Issue
Type › Patch
Type › Report
Type › To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#80684
Loading…
There is no content yet.