Skip to content

Commit

Permalink
Shaders: update for color space moving from node to image datablock
Browse files Browse the repository at this point in the history
  • Loading branch information
brechtvl committed May 13, 2019
1 parent a863bff commit 73df2ed
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 19 deletions.
13 changes: 5 additions & 8 deletions io_coat3D/tex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down
3 changes: 2 additions & 1 deletion io_scene_gltf2/blender/imp/gltf2_blender_map_normal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions materials_utils/material_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion modules/cycles_shader_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 4 additions & 3 deletions node_wrangler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 73df2ed

Please sign in to comment.