From 73df2edf635eee24a2c7a67068acd4d9410de9e5 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Mon, 13 May 2019 14:05:23 +0200 Subject: [PATCH] Shaders: update for color space moving from node to image datablock --- io_coat3D/tex.py | 13 +++++-------- ...2_blender_KHR_materials_pbrSpecularGlossiness.py | 6 ++++-- .../blender/imp/gltf2_blender_map_normal.py | 3 ++- .../imp/gltf2_blender_pbrMetallicRoughness.py | 6 ++++-- materials_utils/material_converter.py | 6 ++++-- modules/cycles_shader_compat.py | 3 ++- node_wrangler.py | 7 ++++--- 7 files changed, 25 insertions(+), 19 deletions(-) diff --git a/io_coat3D/tex.py b/io_coat3D/tex.py index a27c45471..eaed3302c 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 0365fa185..13ab78f87 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 @@ def create_nodetree(gltf, pbrSG, mat_name, vertex_color): 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 @@ def create_nodetree(gltf, pbrSG, mat_name, vertex_color): 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 9cc23db8d..6631ad0b6 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 @@ def create_nodetree(gltf, material_idx, vertex_color): 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 05e6f580b..eb7ca9e7e 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 @@ def create_nodetree(gltf, pypbr, mat_name, vertex_color, nodetype='principled'): 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 @@ def create_nodetree(gltf, pypbr, mat_name, vertex_color, nodetype='principled'): 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 c2f36f50f..3a208e80a 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 092dd7449..7013ed2e8 100644 --- a/modules/cycles_shader_compat.py +++ b/modules/cycles_shader_compat.py @@ -469,7 +469,8 @@ def normal_image_set(self, image): 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 7cb71f380..f82c1528e 100644 --- a/node_wrangler.py +++ b/node_wrangler.py @@ -2760,7 +2760,8 @@ def match_files_to_socket_names(): 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 @@ def match_files_to_socket_names(): 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