[Bf-blender-cvs] [ae824103295] master: Fix T83749: Better handling of alpha in generic Nodes material wrapper for IO add-ons.

Bastien Montagne noreply at git.blender.org
Tue Dec 29 16:42:47 CET 2020


Commit: ae8241032959c7bc225dfaef3b75f44b1f65577b
Author: Bastien Montagne
Date:   Tue Dec 29 16:38:40 2020 +0100
Branches: master
https://developer.blender.org/rBae8241032959c7bc225dfaef3b75f44b1f65577b

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

===================================================================

M	release/scripts/modules/bpy_extras/node_shader_utils.py

===================================================================

diff --git a/release/scripts/modules/bpy_extras/node_shader_utils.py b/release/scripts/modules/bpy_extras/node_shader_utils.py
index 5ddb42e49fc..161560f7f05 100644
--- a/release/scripts/modules/bpy_extras/node_shader_utils.py
+++ b/release/scripts/modules/bpy_extras/node_shader_utils.py
@@ -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)



More information about the Bf-blender-cvs mailing list