Skip to content

Commit

Permalink
[F3D] Pass in shade alpha into fog blender instead of disabling it wh…
Browse files Browse the repository at this point in the history
…en fog is off (#399)

* [F3D] Pass in shade alpha into fog blender instead of disabling it when fog is off

* Fixed global fog and added comments

* black
  • Loading branch information
Lilaa3 authored Aug 9, 2024
1 parent fd27559 commit fc28297
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions fast64_internal/f3d/f3d_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -1585,34 +1585,30 @@ def update_node_combiner(material, combinerInputs, cycleIndex):
def update_fog_nodes(material: Material, context: Context):
nodes = material.node_tree.nodes
f3dMat: "F3DMaterialProperty" = material.f3d_mat
shade_alpha_is_fog = material.f3d_mat.rdp_settings.g_fog

fogBlender: ShaderNodeGroup = nodes["FogBlender"]
# if NOT setting rendermode, it is more likely that the user is setting
# rendermodes in code, so to be safe we'll enable fog. Plus we are checking
# that fog is enabled in the geometry mode, so if so that's probably the intent.
fogBlender.node_tree = bpy.data.node_groups[
(
"FogBlender_On"
if shade_alpha_is_fog and is_blender_doing_fog(material.f3d_mat.rdp_settings, True)
else "FogBlender_Off"
)
("FogBlender_On" if is_blender_doing_fog(material.f3d_mat.rdp_settings, True) else "FogBlender_Off")
]

if shade_alpha_is_fog:
inherit_fog = f3dMat.use_global_fog or not f3dMat.set_fog
if inherit_fog:
link_if_none_exist(material, nodes["SceneProperties"].outputs["FogColor"], nodes["FogColor"].inputs[0])
link_if_none_exist(material, nodes["GlobalFogColor"].outputs[0], fogBlender.inputs["Fog Color"])
link_if_none_exist(
material, nodes["SceneProperties"].outputs["FogNear"], nodes["CalcFog"].inputs["FogNear"]
)
link_if_none_exist(material, nodes["SceneProperties"].outputs["FogFar"], nodes["CalcFog"].inputs["FogFar"])
else:
remove_first_link_if_exists(material, nodes["FogBlender"].inputs["Fog Color"].links)
remove_first_link_if_exists(material, nodes["CalcFog"].inputs["FogNear"].links)
remove_first_link_if_exists(material, nodes["CalcFog"].inputs["FogFar"].links)

remove_first_link_if_exists(material, fogBlender.inputs["FogAmount"].links)
if material.f3d_mat.rdp_settings.g_fog:
material.node_tree.links.new(nodes["CalcFog"].outputs["FogAmount"], fogBlender.inputs["FogAmount"])
else: # If fog is not being calculated, pass in shade alpha
material.node_tree.links.new(nodes["Shade Color"].outputs["Alpha"], fogBlender.inputs["FogAmount"])

if f3dMat.use_global_fog or not f3dMat.set_fog: # Inherit fog
link_if_none_exist(material, nodes["SceneProperties"].outputs["FogColor"], nodes["FogColor"].inputs[0])
link_if_none_exist(material, nodes["GlobalFogColor"].outputs[0], fogBlender.inputs["Fog Color"])
link_if_none_exist(material, nodes["SceneProperties"].outputs["FogNear"], nodes["CalcFog"].inputs["FogNear"])
link_if_none_exist(material, nodes["SceneProperties"].outputs["FogFar"], nodes["CalcFog"].inputs["FogFar"])
else:
remove_first_link_if_exists(material, nodes["FogBlender"].inputs["Fog Color"].links)
remove_first_link_if_exists(material, nodes["CalcFog"].inputs["FogNear"].links)
remove_first_link_if_exists(material, nodes["CalcFog"].inputs["FogFar"].links)
fogBlender.inputs["Fog Color"].default_value = s_rgb_alpha_1_tuple(f3dMat.fog_color)
nodes["CalcFog"].inputs["FogNear"].default_value = f3dMat.fog_position[0]
nodes["CalcFog"].inputs["FogFar"].default_value = f3dMat.fog_position[1]
Expand Down

0 comments on commit fc28297

Please sign in to comment.