[Bf-extensions-cvs] [73df2edf] master: Shaders: update for color space moving from node to image datablock

Brecht Van Lommel noreply at git.blender.org
Mon May 13 17:18:23 CEST 2019


Commit: 73df2edf635eee24a2c7a67068acd4d9410de9e5
Author: Brecht Van Lommel
Date:   Mon May 13 14:05:23 2019 +0200
Branches: master
https://developer.blender.org/rBA73df2edf635eee24a2c7a67068acd4d9410de9e5

Shaders: update for color space moving from node to image datablock

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

M	io_coat3D/tex.py
M	io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_pbrSpecularGlossiness.py
M	io_scene_gltf2/blender/imp/gltf2_blender_map_normal.py
M	io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py
M	materials_utils/material_converter.py
M	modules/cycles_shader_compat.py
M	node_wrangler.py

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

diff --git a/io_coat3D/tex.py b/io_coat3D/tex.py
index a27c4547..eaed3302 100644
--- a/io_coat3D/tex.py
+++ b/io_coat3D/tex.py
@@ -543,18 +543,15 @@ def CreateTextureLine(type, act_material, main_mat, texcoat, coat3D, notegroup,
 
             tex_img_node = texture_tree.nodes.new('ShaderNodeTexImage')
 
-            if(type['colorspace'] == 'color' ):
-                tex_img_node.color_space = 'COLOR'
-            else:
-                tex_img_node.color_space = 'NONE'
-
-
             for ind, tex_index in enumerate(texcoat[type['name']]):
                 if(tex_index[0] == tile):
                     tex_img_node.image = bpy.data.images.load(texcoat[type['name']][ind][1])
                     break
             tex_img_node.location = tex_loc
 
+            if tex_img_node.image and type['colorspace'] != 'color':
+                tex_img_node.image.colorspace_settings.is_data = True
+
             tex_uv_node = texture_tree.nodes.new('ShaderNodeUVMap')
             tex_uv_node.location = uv_loc
             if(is_new):
@@ -689,8 +686,8 @@ def CreateTextureLine(type, act_material, main_mat, texcoat, coat3D, notegroup,
 
     if(tile_list == []):
         node.image = bpy.data.images.load(texcoat[type['name']][0])
-        if(type['colorspace'] == 'noncolor'):
-            node.color_space = 'NONE'
+        if node.image and type['colorspace'] == 'noncolor':
+            node.image.colorspace_settings.is_data = True
 
     if (coat3D.createnodes):
 
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_pbrSpecularGlossiness.py b/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_pbrSpecularGlossiness.py
index 0365fa18..13ab78f8 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_pbrSpecularGlossiness.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_pbrSpecularGlossiness.py
@@ -285,7 +285,8 @@ class BlenderKHR_materials_pbrSpecularGlossiness():
                         gltf.data.textures[pbrSG['specularGlossinessTexture']['index']].source
                     ].blender_image_name
                 ]
-            spec_text.color_space = 'NONE'
+            if spec_text.image:
+                spec_text.image.colorspace_settings.is_data = True
             spec_text.location = -500, 0
 
             spec_mapping = node_tree.nodes.new('ShaderNodeMapping')
@@ -323,7 +324,8 @@ class BlenderKHR_materials_pbrSpecularGlossiness():
                 spec_text.image = bpy.data.images[gltf.data.images[
                     gltf.data.textures[pbrSG['specularGlossinessTexture']['index']].source
                 ].blender_image_name]
-            spec_text.color_space = 'NONE'
+            if spec_text.image:
+                spec_text.image.colorspace_settings.is_data = True
             spec_text.location = -1000, 0
 
             spec_math = node_tree.nodes.new('ShaderNodeMath')
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_map_normal.py b/io_scene_gltf2/blender/imp/gltf2_blender_map_normal.py
index 9cc23db8..6631ad0b 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_map_normal.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_map_normal.py
@@ -66,7 +66,8 @@ class BlenderNormalMap():
                 gltf.data.textures[pymaterial.normal_texture.index].source
             ].blender_image_name]
         text.label = 'NORMALMAP'
-        text.color_space = 'NONE'
+        if text.image:
+            text.image.colorspace_settings.is_data = True
         text.location = -500, -500
 
         normalmap_node = node_tree.nodes.new('ShaderNodeNormalMap')
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py b/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py
index 05e6f580..eb7ca9e7 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py
@@ -237,7 +237,8 @@ class BlenderPbr():
                 metallic_text.image = bpy.data.images[gltf.data.images[
                     gltf.data.textures[pypbr.metallic_roughness_texture.index].source
                 ].blender_image_name]
-                metallic_text.color_space = 'NONE'
+                if metallic_text.image:
+                    metallic_text.image.colorspace_settings.is_data = True
                 metallic_text.label = 'METALLIC ROUGHNESS'
                 metallic_text.location = -500, 0
 
@@ -270,7 +271,8 @@ class BlenderPbr():
                 metallic_text.image = bpy.data.images[gltf.data.images[
                     gltf.data.textures[pypbr.metallic_roughness_texture.index].source
                 ].blender_image_name]
-                metallic_text.color_space = 'NONE'
+                if metallic_text.image:
+                    metallic_text.image.colorspace_settings.is_data = True
                 metallic_text.label = 'METALLIC ROUGHNESS'
                 metallic_text.location = -1000, 0
 
diff --git a/materials_utils/material_converter.py b/materials_utils/material_converter.py
index c2f36f50..3a208e80 100644
--- a/materials_utils/material_converter.py
+++ b/materials_utils/material_converter.py
@@ -342,7 +342,8 @@ def createNormalNodes(cmat, texCoordNode, mainShader, materialOutput):
 
             # Place the texture node
             renameNode(texNode, '{} Texture'.format(groupName), texCount, textureIdx)
-            texNode.color_space = 'NONE'
+            if texNode.image.image:
+                texNode.image.colorspace_settings.is_data = True
             links.new(normalMapping.outputs['Vector'], texNode.inputs['Vector'])
 
             # Add multiply node
@@ -528,7 +529,8 @@ def createEmissionNodes(cmat, texCoordNode, mainShader, materialOutput):
 
             # Place the texture node
             renameNode(texNode, '{} Texture'.format(groupName), texCount, textureIdx)
-            texNode.color_space = 'NONE'
+            if texNode.image.image:
+                texNode.image.colorspace_settings.is_data = True
             links.new(emissionMapping.outputs['Vector'], texNode.inputs['Vector'])
 
             # Add multiply node
diff --git a/modules/cycles_shader_compat.py b/modules/cycles_shader_compat.py
index 092dd744..7013ed2e 100644
--- a/modules/cycles_shader_compat.py
+++ b/modules/cycles_shader_compat.py
@@ -469,7 +469,8 @@ class CyclesShaderWrapper():
         node = self.node_normalmap
         self.node_image_normalmap = (
             self._image_create_helper(image, node, (node.inputs["Color"],)))
-        self.node_image_normalmap.color_space = 'NONE'
+        if self.node_image_normalmap.image:
+            self.node_image_normalmap.image.colorspace_settings.is_data = True
 
     def normal_mapping_set(self, coords='UV',
                            translation=None, rotation=None, scale=None, clamp=None):
diff --git a/node_wrangler.py b/node_wrangler.py
index 7cb71f38..f82c1528 100644
--- a/node_wrangler.py
+++ b/node_wrangler.py
@@ -2760,7 +2760,8 @@ class NWAddPrincipledSetup(Operator, NWBase, ImportHelper):
                 img = bpy.data.images.load(self.directory+sname[2])
                 disp_texture.image = img
                 disp_texture.label = 'Displacement'
-                disp_texture.color_space = 'NONE'
+                if disp_texture.image:
+                    disp_texture.image.colorspace_settings.is_data = True
 
                 # Add displacement offset nodes
                 disp_node = nodes.new(type='ShaderNodeDisplacement')
@@ -2825,8 +2826,8 @@ class NWAddPrincipledSetup(Operator, NWBase, ImportHelper):
                     link = links.new(active_node.inputs[sname[0]], texture_node.outputs[0])
 
                 # Use non-color for all but 'Base Color' Textures
-                if not sname[0] in ['Base Color']:
-                    texture_node.color_space = 'NONE'
+                if not sname[0] in ['Base Color'] and texture_node.image:
+                    texture_node.image.colorspace_settings.is_data = True
 
             else:
                 # If already texture connected. add to node list for alignment



More information about the Bf-extensions-cvs mailing list