Skip to content

Commit cec6053

Browse files
Merge pull request #17 from kajupe/main
Tweaks to skin and hair shaders
2 parents b679b8d + 145f651 commit cec6053

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

MeddleTools/node_groups.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -641,13 +641,22 @@ def clearMaterialNodes(node_tree: bpy.types.ShaderNodeTree):
641641
for node in node_tree.nodes:
642642
node_tree.nodes.remove(node)
643643

644-
def createBsdfNode(node_tree: bpy.types.ShaderNodeTree):
644+
def createBsdfNode(node_tree: bpy.types.ShaderNodeTree, subsurface_method:str = 'BURLEY'):
645+
"""Creates the principled BSDF node for the material
646+
647+
Args:
648+
node_tree (bpy.types.ShaderNodeTree): A reference to the material's node tree
649+
subsurface_method (str, optional): Which subsurface method to use from BURLEY, RANDOM_WALK and RANDOM_WALK_SKIN. Defaults to 'BURLEY'.
650+
651+
Returns:
652+
bsdf_node (bpy.types.ShaderNodeBsdfPrincipled): A reference to the newly created principled BSDF node
653+
"""
645654
bsdf_node: bpy.types.ShaderNodeBsdfPrincipled = node_tree.nodes.new('ShaderNodeBsdfPrincipled') # type: ignore
646655
bsdf_node.width = 300
647656
try:
648-
bsdf_node.subsurface_method = 'BURLEY'
657+
bsdf_node.subsurface_method = subsurface_method
649658
except:
650-
print("Subsurface method not found")
659+
print(f"Something went wrong when trying to set subsurface method: \"{subsurface_method}\"")
651660
return bsdf_node
652661

653662
def mapBsdfOutput(mat: bpy.types.Material, material_output: bpy.types.ShaderNodeOutputMaterial, bsdf_node: bpy.types.ShaderNodeBsdfPrincipled, targetIdentifier: str):
@@ -800,7 +809,7 @@ def handleSkin(mat: bpy.types.Material, mesh, directory):
800809
group_node.node_tree = bpy.data.node_groups[group_name] # type: ignore
801810
group_node.width = 300
802811

803-
bsdf_node = createBsdfNode(node_tree)
812+
bsdf_node = createBsdfNode(node_tree, 'RANDOM_WALK_SKIN') # Specify Skin subsurface method
804813
mapBsdfOutput(mat, material_output, bsdf_node, 'Surface')
805814
mapGroupOutputs(mat, bsdf_node, group_node)
806815
mapMappings(mat, mesh, group_node, directory, base_mappings + mappings)
@@ -887,6 +896,14 @@ def handleHair(mat: bpy.types.Material, mesh, directory):
887896
mapBsdfOutput(mat, material_output, bsdf_node, 'Surface')
888897
mapGroupOutputs(mat, bsdf_node, group_node)
889898
mapMappings(mat, mesh, group_node, directory, base_mappings + mappings)
899+
900+
try:
901+
bsdf_node.inputs.get("Transmission Weight").default_value = 0.01
902+
bsdf_node.inputs.get("Subsurface Scale").default_value = 0.15
903+
node_tree.links.new(group_node.outputs.get("Base Color"), bsdf_node.inputs.get("Subsurface Radius"))
904+
except Exception as e:
905+
print(f"Exception occured when setting some hair inputs: {e}")
906+
890907
east = getEastModePosition(node_tree)
891908
group_node.location = (east + 300, 300)
892909
bsdf_node.location = (east + 600, 300)

MeddleTools/shaders.blend

-1.2 KB
Binary file not shown.

MeddleTools/shaders.blend1

-350 KB
Binary file not shown.

0 commit comments

Comments
 (0)