Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,43 @@ def __gather_extras(blender_material, export_settings):
return None


def __get_metallic_scale_from_socket(blender_shader_socket: bpy.types.NodeSocket):
result = gltf2_blender_search_node_tree.from_socket(
blender_shader_socket,
gltf2_blender_search_node_tree.FilterByName("metallic_scale_node"))
if not result:
return None
return result[0]

def __gather_metallic_factor(blender_material, export_settings):
metallic_socket = gltf2_blender_get.get_socket_or_texture_slot(blender_material, "Metallic")
if metallic_socket is None:
metallic_socket = gltf2_blender_get.get_socket_or_texture_slot_old(blender_material, "MetallicFactor")
if isinstance(metallic_socket, bpy.types.NodeSocket) and not metallic_socket.is_linked:
return metallic_socket.default_value
metallic_scale_node = __get_metallic_scale_from_socket(metallic_socket)
if metallic_scale_node:
return metallic_scale_node.shader_node.inputs[1].default_value
return None

def __get_roughness_scale_from_socket(blender_shader_socket: bpy.types.NodeSocket):
result = gltf2_blender_search_node_tree.from_socket(
blender_shader_socket,
gltf2_blender_search_node_tree.FilterByName("roughness_scale_node"))
if not result:
return None
return result[0]

def __gather_roughness_factor(blender_material, export_settings):
roughness_socket = gltf2_blender_get.get_socket_or_texture_slot(blender_material, "Roughness")
if roughness_socket is None:
roughness_socket = gltf2_blender_get.get_socket_or_texture_slot_old(blender_material, "RoughnessFactor")
if isinstance(roughness_socket, bpy.types.NodeSocket) and not roughness_socket.is_linked:
return roughness_socket.default_value
roughness_scale_node = __get_roughness_scale_from_socket(roughness_socket)
if roughness_scale_node:
return roughness_scale_node.shader_node.inputs[1].default_value
return None

def __gather_metallic_roughness_texture(blender_material, orm_texture, export_settings):
if orm_texture is not None:
Expand All @@ -157,14 +186,6 @@ def __gather_metallic_roughness_texture(blender_material, orm_texture, export_se
return gltf2_blender_gather_texture_info.gather_texture_info(texture_input, export_settings)


def __gather_roughness_factor(blender_material, export_settings):
roughness_socket = gltf2_blender_get.get_socket_or_texture_slot(blender_material, "Roughness")
if roughness_socket is None:
roughness_socket = gltf2_blender_get.get_socket_or_texture_slot_old(blender_material, "RoughnessFactor")
if isinstance(roughness_socket, bpy.types.NodeSocket) and not roughness_socket.is_linked:
return roughness_socket.default_value
return None

def __has_image_node_from_socket(socket):
result = gltf2_blender_search_node_tree.from_socket(
socket,
Expand Down
23 changes: 21 additions & 2 deletions func_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,22 @@ def CreatePBRBranch(Material, bsdf_node, offset=(0.0,0.0)):
metallic_separate = CreateNewNode(Material,'ShaderNodeSeparateRGB',"metallic_sep",location=(offset[0]+550,offset[1]-305))
metallic_separate.hide = True

# Roughness scale
roughness_scale_node = CreateNewNode(Material,'ShaderNodeMath',"roughness_scale_node",location=(offset[0]+750,offset[1]-355))
roughness_scale_node.hide = True
roughness_scale_node.operation = 'MULTIPLY'
roughness_scale_node.use_clamp = True
roughness_scale_node.inputs[1].default_value = Material.msfs_roughness_scale

# Metallic scale
metallic_scale_node = CreateNewNode(Material,'ShaderNodeMath',"metallic_scale_node",location=(offset[0]+750,offset[1]-405))
metallic_scale_node.hide = True
metallic_scale_node.operation = 'MULTIPLY'
metallic_scale_node.use_clamp = True
metallic_scale_node.inputs[1].default_value = Material.msfs_metallic_scale



# Create a node group for the occlusion map
#Let's see if the node tree already exists, if not create one.
occlusion_node_tree = bpy.data.node_groups.get("glTF Settings")
Expand All @@ -207,16 +223,19 @@ def CreatePBRBranch(Material, bsdf_node, offset=(0.0,0.0)):

#Link the UV:
links.new(uv_node.outputs["UV"], texture_metallic_node.inputs["Vector"])

#Create metallic links:
links.new(texture_metallic_node.outputs["Color"], metallic_detail_mix.inputs["Color1"])
links.new(metallic_detail_mix.outputs["Color"], metallic_separate.inputs["Image"])
links.new(metallic_separate.outputs[0], occlusion_group.inputs["Occlusion"])
links.new(metallic_separate.outputs[1], roughness_scale_node.inputs[0])
links.new(metallic_separate.outputs[2], metallic_scale_node.inputs[0])
if Material.msfs_metallic_texture != None:
if Material.msfs_metallic_texture.name != "":
#link to bsdf
if (bsdf_node != None and metallic_separate != None):
links.new(metallic_separate.outputs[1], bsdf_node.inputs["Roughness"])
links.new(metallic_separate.outputs[2], bsdf_node.inputs["Metallic"])
links.new(roughness_scale_node.outputs[0], bsdf_node.inputs["Roughness"])
links.new(metallic_scale_node.outputs[0], bsdf_node.inputs["Metallic"])


# Normal map
Expand Down
39 changes: 27 additions & 12 deletions li_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,8 @@ def match_metallic(self, context):
#Try to generate the links:
bsdf_node = nodes.get("bsdf")
metallic = nodes.get("metallic")
metallic_sep_node = nodes.get("metallic_sep")
metallic_scale_node = nodes.get("metallic_scale_node")
roughness_scale_node = nodes.get("roughness_scale_node")

if metallic != None:
nodes["metallic"].image = mat.msfs_metallic_texture
Expand All @@ -790,16 +791,20 @@ def match_metallic(self, context):
nodes["metallic"].image.colorspace_settings.name = 'Non-Color'

#link to bsdf
if (bsdf_node != None and metallic_sep_node != None):
links.new(metallic_sep_node.outputs[1], bsdf_node.inputs["Roughness"])
links.new(metallic_sep_node.outputs[2], bsdf_node.inputs["Metallic"])
if bsdf_node != None:
if roughness_scale_node != None:
links.new(roughness_scale_node.outputs[0], bsdf_node.inputs["Roughness"])
if metallic_scale_node != None:
links.new(metallic_scale_node.outputs[0],bsdf_node.inputs["Metallic"])
else:
#unlink the separator:
if (bsdf_node != None and metallic_sep_node != None):
l = bsdf_node.inputs["Roughness"].links[0]
links.remove(l)
l = bsdf_node.inputs["Metallic"].links[0]
links.remove(l)
#unlink the metallic/roughness scales:
if bsdf_node != None:
if roughness_scale_node != None:
l = bsdf_node.inputs["Roughness"].links[0]
links.remove(l)
if metallic_scale_node != None:
l = bsdf_node.inputs["Metallic"].links[0]
links.remove(l)

def match_normal(self, context):
mat = context.active_object.active_material
Expand Down Expand Up @@ -1082,6 +1087,16 @@ def update_normal_scale(self,context):
if mat.node_tree.nodes.get("normal_map_node", None) != None:
mat.node_tree.nodes["normal_map_node"].inputs["Strength"].default_value = mat.msfs_normal_scale

def update_metallic_scale(self,context):
mat = context.active_object.active_material
if mat.node_tree.nodes.get("metallic_scale_node", None) != None:
mat.node_tree.nodes["metallic_scale_node"].inputs[1].default_value = mat.msfs_metallic_scale

def update_roughness_scale(self,context):
mat = context.active_object.active_material
if mat.node_tree.nodes.get("roughness_scale_node", None) != None:
mat.node_tree.nodes["roughness_scale_node"].inputs[1].default_value = mat.msfs_roughness_scale

def update_detail_uv_scale(self,context):
mat = context.active_object.active_material
if mat.node_tree.nodes.get("detail_uv_scale", None) != None:
Expand Down Expand Up @@ -1239,8 +1254,8 @@ def update_detail_uv_offset(self,context):
Material.msfs_uv_clamp_z = bpy.props.BoolProperty(name="Z",default=False)

#Material parameters
Material.msfs_roughness_scale = bpy.props.FloatProperty(name="Roughness scale",min=0,max=1,default=1)
Material.msfs_metallic_scale = bpy.props.FloatProperty(name="Metallic scale",min=0,max=1,default=1)
Material.msfs_roughness_scale = bpy.props.FloatProperty(name="Roughness scale",min=0,max=1,default=1,update=update_roughness_scale)
Material.msfs_metallic_scale = bpy.props.FloatProperty(name="Metallic scale",min=0,max=1,default=1,update=update_metallic_scale)
Material.msfs_normal_scale = bpy.props.FloatProperty(name="Normal scale",min=0,default=1,update=update_normal_scale)
Material.msfs_alpha_cutoff = bpy.props.FloatProperty(name="Alpha cutoff",min=0,max=1,default=0.1,update=update_alpha_cutoff)
Material.msfs_detail_uv_scale = bpy.props.FloatProperty(name="Detail UV scale",min=0,default=1,update=update_detail_uv_scale)
Expand Down