diff --git a/fast64_internal/f3d/f3d_bleed.py b/fast64_internal/f3d/f3d_bleed.py index b1dbf2057..20ad88c7c 100644 --- a/fast64_internal/f3d/f3d_bleed.py +++ b/fast64_internal/f3d/f3d_bleed.py @@ -253,6 +253,8 @@ def bleed_mat(self, cur_fmat: FMaterial, last_mat: FMaterial, bleed_state: int): commands_bled.commands.remove(None) else: commands_bled = self.bleed_cmd_list(cur_fmat.mat_only_DL, bleed_state) + # some syncs may become redundant after bleeding + self.optimize_syncs(commands_bled, bleed_state) # remove SPEndDisplayList while SPEndDisplayList() in commands_bled.commands: commands_bled.commands.remove(SPEndDisplayList()) @@ -353,6 +355,24 @@ def on_bleed_end( cmd_list.commands.append(SPEndDisplayList()) self.bled_gfx_lists[cmd_list] = last_mat + # remove syncs if first material, or if no gsDP cmds in material + def optimize_syncs(self, cmd_list: GfxList, bleed_state: int): + no_syncs_needed = {"DPSetPrimColor", "DPSetPrimDepth"} # will not affect rdp + syncs_needed = {"SPSetOtherMode"} # will affect rdp + if bleed_state == self.bleed_start: + while DPPipeSync() in cmd_list.commands: + cmd_list.commands.remove(DPPipeSync()) + for cmd in cmd_list.commands: + cmd_name = type(cmd).__name__ + if cmd == DPPipeSync(): + continue + if "DP" in cmd_name and cmd_name not in no_syncs_needed: + return + if cmd_name in syncs_needed: + return + while DPPipeSync() in cmd_list.commands: + cmd_list.commands.remove(DPPipeSync()) + def create_reset_cmds(self, reset_cmd_dict: dict[GbiMacro], default_render_mode: list[str]): reset_cmds = [] for cmd_type, cmd_use in reset_cmd_dict.items(): diff --git a/fast64_internal/f3d/f3d_writer.py b/fast64_internal/f3d/f3d_writer.py index 34a11d832..333d40366 100644 --- a/fast64_internal/f3d/f3d_writer.py +++ b/fast64_internal/f3d/f3d_writer.py @@ -1315,12 +1315,26 @@ def saveOrGetF3DMaterial(material, fModel, obj, drawLayer, convertTextureData): + (("_layer" + str(drawLayer)) if f3dMat.rdp_settings.set_rendermode and drawLayer is not None else "") + (("_area" + str(areaIndex)) if f3dMat.set_fog and f3dMat.use_global_fog and areaKey is not None else "") ) - fMaterial = fModel.addMaterial(materialName) - fMaterial.mat_only_DL.commands.append(DPPipeSync()) - fMaterial.revert.commands.append(DPPipeSync()) if not material.is_f3d: raise PluginError("Material named " + material.name + " is not an F3D material.") + fMaterial = fModel.addMaterial(materialName) + useDict = all_combiner_uses(f3dMat) + + defaults = bpy.context.scene.world.rdp_defaults + if fModel.f3d.F3DEX_GBI_2: + saveGeoModeDefinitionF3DEX2(fMaterial, f3dMat.rdp_settings, defaults, fModel.matWriteMethod) + else: + saveGeoModeDefinition(fMaterial, f3dMat.rdp_settings, defaults, fModel.matWriteMethod) + + # Checking for f3dMat.rdp_settings.g_lighting here will prevent accidental exports, + # There may be some edge case where this isn't desired. + if useDict["Shade"] and f3dMat.rdp_settings.g_lighting and f3dMat.set_lights: + fLights = saveLightsDefinition(fModel, fMaterial, f3dMat, materialName + "_lights") + fMaterial.mat_only_DL.commands.extend([SPSetLights(fLights)]) + + fMaterial.mat_only_DL.commands.append(DPPipeSync()) + fMaterial.revert.commands.append(DPPipeSync()) fMaterial.getScrollData(material, getMaterialScrollDimensions(f3dMat)) @@ -1412,20 +1426,12 @@ def saveOrGetF3DMaterial(material, fModel, obj, drawLayer, convertTextureData): ] ) - useDict = all_combiner_uses(f3dMat) multitexManager = MultitexManager(material, fMaterial, fModel) - # Set othermode if drawLayer is not None: defaultRM = fModel.getRenderMode(drawLayer) else: defaultRM = None - - defaults = bpy.context.scene.world.rdp_defaults - if fModel.f3d.F3DEX_GBI_2: - saveGeoModeDefinitionF3DEX2(fMaterial, f3dMat.rdp_settings, defaults, fModel.matWriteMethod) - else: - saveGeoModeDefinition(fMaterial, f3dMat.rdp_settings, defaults, fModel.matWriteMethod) saveOtherModeHDefinition( fMaterial, f3dMat.rdp_settings, @@ -1462,12 +1468,6 @@ def saveOrGetF3DMaterial(material, fModel, obj, drawLayer, convertTextureData): color = exportColor(f3dMat.env_color[0:3]) + [scaleToU8(f3dMat.env_color[3])] fMaterial.mat_only_DL.commands.append(DPSetEnvColor(*color)) - # Checking for f3dMat.rdp_settings.g_lighting here will prevent accidental exports, - # There may be some edge case where this isn't desired. - if useDict["Shade"] and f3dMat.set_lights and f3dMat.rdp_settings.g_lighting: - fLights = saveLightsDefinition(fModel, fMaterial, f3dMat, materialName + "_lights") - fMaterial.mat_only_DL.commands.extend([SPSetLights(fLights)]) # TODO: handle synching: NO NEED? - if useDict["Key"] and f3dMat.set_key: if material.mat_ver >= 4: center = f3dMat.key_center