Fix T83749: Better handling of alpha in generic Nodes material wrapper for IO add-ons.

Try to detect if a given image may have valid alpha data or not (based
on number of channels and depth). This may be a bit doggy in theory, but
in practice it should cover most fields as expected. We can always
adjust the euristic here in other wrong cases appear.

This will affect all import add-ons using that node shader wrapper (at
least OBJ and FBX ones).
This commit is contained in:
Bastien Montagne 2020-12-29 16:38:40 +01:00
parent e22a36e80a
commit ae82410329
Notes: blender-bot 2023-02-14 18:44:32 +01:00
Referenced by issue #89630, FBX/OBJ Import - Show Backfaces makes object look wrong and is ON by default.
Referenced by issue #85612, FBX import. Textures with alpha become transparent by default
Referenced by issue #85234, FBX Importer, transparency of principled is connected to incorrect color (not alpha) output
Referenced by issue blender/blender-addons#83749, Obj Material transparencies not automatically connected correctly when using jpeg
1 changed files with 9 additions and 0 deletions

View File

@ -684,6 +684,8 @@ class ShaderImageTextureWrapper():
self.owner_shader._grid_to_location(-1, 0 + self.grid_row_diff, dst_node=node_image, ref_node=self.node_dst)
tree.links.new(node_image.outputs["Alpha" if self.use_alpha else "Color"], self.socket_dst)
if self.use_alpha:
self.owner_shader.material.blend_method = 'BLEND'
self._node_image = node_image
return self._node_image
@ -703,6 +705,13 @@ class ShaderImageTextureWrapper():
if image.colorspace_settings.is_data != self.colorspace_is_data and image.users >= 1:
image = image.copy()
image.colorspace_settings.name = self.colorspace_name
if self.use_alpha:
# Try to be smart, and only use image's alpha output if image actually has alpha data.
tree = self.owner_shader.material.node_tree
if image.channels < 4 or image.depth in {24, 8}:
tree.links.new(self.node_image.outputs["Color"], self.socket_dst)
else:
tree.links.new(self.node_image.outputs["Alpha"], self.socket_dst)
self.node_image.image = image
image = property(image_get, image_set)