Skip to content

Commit

Permalink
final first pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilaa3 committed Oct 26, 2024
1 parent 684e425 commit 57b089d
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions fast64_internal/f3d/bsdf_converter/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def material_to_bsdf(material: Material, put_alpha_into_color=False):

node_x = node_y = alpha_y_offset = 0

def set_location(node, set_x=False, x_offset=0, y_offset=0):
def set_location(node, set_x=False, x_offset=0, y_offset=0): # some polish stuff
nonlocal node_x, node_y
node.location = (node_x - node.width + x_offset, node_y + y_offset)
if set_x:
Expand All @@ -279,7 +279,6 @@ def create_node(typ: T, name: str, location=False, x_offset=0, y_offset=0):
set_location(node, location, x_offset=x_offset, y_offset=y_offset)
return node

# output
output_node = create_node(ShaderNodeOutputMaterial, "Output", True)
node_y -= 25

Expand All @@ -296,18 +295,16 @@ def create_node(typ: T, name: str, location=False, x_offset=0, y_offset=0):
else:
node_y -= 80
alpha_y_offset -= 462
else:
else: # use a mix shader of transparent bsdf and background and use fac as alpha
print("Creating unlit shader node")
mix_shader = create_node(ShaderNodeMixShader, "Mix Shader", True)
links.new(mix_shader.outputs[0], output_node.inputs[0])
alpha_input = mix_shader.inputs["Fac"]

# transparent bsdf shader
transparent_node = create_node(ShaderNodeBsdfTransparent, "Transparency Shader", y_offset=-47)
links.new(transparent_node.outputs[0], mix_shader.inputs[1])
alpha_y_offset += transparent_node.height + 47

# background shader
background_node = create_node(
ShaderNodeBackground, "Background Shader", True, y_offset=-47 - transparent_node.height
)
Expand Down Expand Up @@ -352,11 +349,12 @@ def create_node(typ: T, name: str, location=False, x_offset=0, y_offset=0):
if abstracted_mat.vertex_alpha:
if put_alpha_into_color: # link vertex color's alpha to vertex alpha mul
links.new(vertex_color.outputs[1], vertex_alpha_mul.inputs[0])
else: # create vertex alpha
else: # create vertex alpha node
vertex_alpha = create_node(ShaderNodeVertexColor, "Vertex Alpha", True, y_offset=alpha_y_offset)
vertex_alpha.layer_name = "Alpha"
links.new(vertex_alpha.outputs[0], vertex_alpha_mul.inputs[0])

# support for glTF base color which gets multiplied on to textures
mix_rgb = False
if abstracted_mat.texture_sets_col and abstracted_mat.color[:3] != [1.0, 1.0, 1.0]:
print(f"Creating color mul node {abstracted_mat.color} and setting color input")
Expand All @@ -367,7 +365,6 @@ def create_node(typ: T, name: str, location=False, x_offset=0, y_offset=0):
links.new(color_mul.outputs[0], color_input)
color_input = color_mul.inputs[2]
mix_rgb = True

if abstracted_mat.texture_sets_alpha and abstracted_mat.color[3] != 1.0 and abstracted_mat.output_method != "OPA":
print(f"Setting alpha mul node {abstracted_mat.color[3]} and setting alpha input")
alpha_mul = create_node(ShaderNodeMath, "Alpha Mul", y_offset=alpha_y_offset)
Expand All @@ -393,6 +390,7 @@ def create_node(typ: T, name: str, location=False, x_offset=0, y_offset=0):

tex_color_inputs = [color_input, None]
tex_alpha_inputs = [alpha_input, None]
assert len(abstracted_mat.textures) <= 2, "Too many textures"
if len(abstracted_mat.textures) == 2:
if all(abstracted_tex.set_color for abstracted_tex in abstracted_mat.textures):
print("Creating mix rgb node for multi texture, setting color input")
Expand All @@ -412,7 +410,7 @@ def create_node(typ: T, name: str, location=False, x_offset=0, y_offset=0):
texture_nodes = []
for abstracted_tex, tex_color_input, tex_alpha_input in zip(
abstracted_mat.textures, tex_color_inputs, tex_alpha_inputs
): # create textures
): # create invidual texture nodes and link them
tex_node = create_node(ShaderNodeTexImage, "Texture", y_offset=tex_y_offset)
tex_node.image = abstracted_tex.tex
tex_node.extension = "REPEAT" if abstracted_tex.repeat else "EXTEND"
Expand Down

0 comments on commit 57b089d

Please sign in to comment.