Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <bastien@blender.org>2020-12-29 18:38:40 +0300
committerBastien Montagne <bastien@blender.org>2020-12-29 18:38:40 +0300
commitae8241032959c7bc225dfaef3b75f44b1f65577b (patch)
tree36cca9e7be808bd7e47680b9c660461816b62b28
parente22a36e80a1e2723e8d9f2b9a39b5d61d6b4b6ec (diff)
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).
-rw-r--r--release/scripts/modules/bpy_extras/node_shader_utils.py9
1 files changed, 9 insertions, 0 deletions
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)