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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user