From e321a71aaaecfae2080ee1f00ab25be0d068a28c Mon Sep 17 00:00:00 2001 From: Sauraen Date: Sun, 31 Dec 2023 12:21:31 -0800 Subject: [PATCH 1/8] First draft of rendermode changes --- fast64_internal/f3d/f3d_material.py | 304 +++++++++++++++------------- 1 file changed, 164 insertions(+), 140 deletions(-) diff --git a/fast64_internal/f3d/f3d_material.py b/fast64_internal/f3d/f3d_material.py index eb40ac3dd..41fcffb9f 100644 --- a/fast64_internal/f3d/f3d_material.py +++ b/fast64_internal/f3d/f3d_material.py @@ -177,85 +177,144 @@ def update_draw_layer(self, context): set_output_node_groups(material) -def rendermodePresetToBits(rdp_settings: "RDPSettings") -> Tuple[int, int]: - f3d = get_F3D_GBI() - r1 = getattr(f3d, rdp_settings.rendermode_preset_cycle_1, f3d.G_RM_AA_ZB_OPA_SURF) - r2 = getattr(f3d, rdp_settings.rendermode_preset_cycle_2, f3d.G_RM_AA_ZB_OPA_SURF) - if rdp_settings.g_mdsft_cycletype == "G_CYC_1CYCLE": - r2 = 0 - return r1, r2 - - -def all_blender_uses(rdp_settings: "RDPSettings") -> Dict[str, bool]: +def rendermode_preset_to_advanced(material: bpy.types.Material): """ - Returns a dictionary of the external features which the blender may or may - not use, or None if set_rendermode is disabled so we don't know. + Set all individual controls for the rendermode from the preset rendermode. """ - if not rdp_settings.set_rendermode: - return None - is_one_cycle = rdp_settings.g_mdsft_cycletype == "G_CYC_1CYCLE" - if rdp_settings.rendermode_advanced_enabled: - useZ = rdp_settings.z_cmp or rdp_settings.z_upd - useShade = rdp_settings.blend_a1 == "G_BL_A_SHADE" - if not is_one_cycle: - useShade = useShade or rdp_settings.blend_a2 == "G_BL_A_SHADE" + settings = material.f3d_mat.rdp_settings + f3d = get_F3D_GBI() + + if settings.rendermode_advanced_enabled: + # Already in advanced mode, don't overwrite this with the preset + return + + def get_with_default(preset, default): + # Use the default either if we are not setting rendermode, or if the + # preset is not in the GBI. We do want to set the advanced settings + # even if not setting rendermode, because they are read for nodes preview. + if not settings.set_rendermode: + return default + return getattr(f3d, preset, default) + + is_one_cycle = settings.g_mdsft_cycletype == "G_CYC_1CYCLE" + if is_one_cycle: + r = get_with_default(rdp_settings.rendermode_preset_cycle_1, f3d.G_RM_AA_ZB_OPA_SURF) + r1 = r + # For GBL_c2, look at the same bits as for cycle 1. Cycle 1 bits are copied + # to cycle 2 bits at export. + r2 = r >> 2 else: - r1, r2 = rendermodePresetToBits(rdp_settings) - f3d = get_F3D_GBI() - useZ = bool((r1 | r2) & (f3d.Z_CMP | f3d.Z_UPD)) - useShade = ((r1 >> 26) & 3) == f3d.G_BL_A_SHADE or ((r2 >> 24) & 3) == f3d.G_BL_A_SHADE - return {"Shade Alpha": useShade, "Z Buffer": useZ} - - -def get_blend_method(material): - f3dMat = material.f3d_mat - drawLayer = material.f3d_mat.draw_layer - blend_method = drawLayerSM64Alpha[drawLayer.sm64] + r1 = get_with_default(rdp_settings.rendermode_preset_cycle_1, f3d.G_RM_FOG_SHADE_A) + r2 = get_with_default(rdp_settings.rendermode_preset_cycle_2, f3d.G_RM_AA_ZB_OPA_SURF2) + r = r1 | r2 + + settings.aa_en = (r & f3d.AA_EN) != 0 + settings.z_cmp = (r & f3d.Z_CMP) != 0 + settings.z_upd = (r & f3d.Z_UPD) != 0 + settings.im_rd = (r & f3d.IM_RD) != 0 + settings.clr_on_cvg = (r & f3d.CLR_ON_CVG) != 0 + settings.cvg_dst = f3d.cvgDstDict[(r & f3d.CVG_DST_SAVE) // f3d.CVG_DST_WRAP] + settings.zmode = f3d.zmodeDict[(r & f3d.ZMODE_DEC) // f3d.ZMODE_INTER] + settings.cvg_x_alpha = (r & f3d.CVG_X_ALPHA) != 0 + settings.alpha_cvg_sel = (r & f3d.ALPHA_CVG_SEL) != 0 + settings.force_bl = (r & f3d.FORCE_BL) != 0 + + settings.blend_p1 = f3d.blendColorDict[(r1 >> 30) & 3] + settings.blend_p2 = f3d.blendColorDict[(r2 >> 28) & 3] + settings.blend_a1 = f3d.blendAlphaDict[(r1 >> 26) & 3] + settings.blend_a2 = f3d.blendAlphaDict[(r2 >> 24) & 3] + settings.blend_m1 = f3d.blendColorDict[(r1 >> 22) & 3] + settings.blend_m2 = f3d.blendColorDict[(r2 >> 20) & 3] + settings.blend_b1 = f3d.blendMixDict[(r1 >> 18) & 3] + settings.blend_b2 = f3d.blendMixDict[(r2 >> 16) & 3] + + +def does_blender_use_color( + settings: "RDPSettings", + color: str, + default_for_no_rendermode: bool = False +) -> bool: + if not settings.set_rendermode: + return default_for_no_rendermode + is_one_cycle = settings.g_mdsft_cycletype == "G_CYC_1CYCLE" + return ( + settings.blend_p1 == color or settings.blend_m1 == color + or (is_one_cycle and (settings.blend_p2 == color or settings.blend_m2 == color)) + ) + - is_one_cycle = f3dMat.rdp_settings.g_mdsft_cycletype == "G_CYC_1CYCLE" +def does_blender_use_alpha( + settings: "RDPSettings", + alpha: str, + default_for_no_rendermode: bool = False +) -> bool: + if not settings.set_rendermode: + return default_for_no_rendermode + is_one_cycle = settings.g_mdsft_cycletype == "G_CYC_1CYCLE" + return settings.blend_a1 == alpha or (is_one_cycle and settings.blend_a2 == alpha) - if f3dMat.rdp_settings.set_rendermode: - if f3dMat.rdp_settings.rendermode_advanced_enabled: - if f3dMat.rdp_settings.cvg_x_alpha: - blend_method = "CLIP" - elif ( - is_one_cycle - and f3dMat.rdp_settings.force_bl - and f3dMat.rdp_settings.blend_p1 == "G_BL_CLR_IN" - and f3dMat.rdp_settings.blend_a1 == "G_BL_A_IN" - and f3dMat.rdp_settings.blend_m1 == "G_BL_CLR_MEM" - and f3dMat.rdp_settings.blend_b1 == "G_BL_1MA" - ): - blend_method = "BLEND" - elif ( - not is_one_cycle - and f3dMat.rdp_settings.force_bl - and f3dMat.rdp_settings.blend_p2 == "G_BL_CLR_IN" - and f3dMat.rdp_settings.blend_a2 == "G_BL_A_IN" - and f3dMat.rdp_settings.blend_m2 == "G_BL_CLR_MEM" - and f3dMat.rdp_settings.blend_b2 == "G_BL_1MA" - ): - blend_method = "BLEND" - else: - blend_method = "OPAQUE" - else: - rendermode = f3dMat.rdp_settings.rendermode_preset_cycle_1 - if not is_one_cycle: - rendermode = f3dMat.rdp_settings.rendermode_preset_cycle_2 - - f3d = get_F3D_GBI() - r_mode = getattr(f3d, rendermode, f3d.G_RM_AA_ZB_OPA_SURF) - if r_mode & f3d.CVG_X_ALPHA: - blend_method = "CLIP" - else: - cfunc = GBL_c1 if is_one_cycle else GBL_c2 - xlu_comb = r_mode & cfunc(f3d.G_BL_CLR_IN, f3d.G_BL_A_IN, f3d.G_BL_CLR_MEM, f3d.G_BL_1MA) - if xlu_comb and r_mode & f3d.FORCE_BL: - blend_method = "BLEND" - else: - blend_method = "OPAQUE" - return blend_method +def does_blender_use_mix( + settings: "RDPSettings", + mix: str, + default_for_no_rendermode: bool = False +) -> bool: + if not settings.set_rendermode: + return default_for_no_rendermode + is_one_cycle = settings.g_mdsft_cycletype == "G_CYC_1CYCLE" + return settings.blend_b1 == mix or (is_one_cycle and settings.blend_b2 == mix) + + +def is_blender_lerp( + settings: "RDPSettings", + cycle: int, + p: str, + a: str, + m: str, + b: str, + default_for_no_rendermode: bool = False +) -> bool: + assert cycle in {1, 2, -1} # -1 = last cycle + if cycle == -1: + cycle = 1 if settings.g_mdsft_cycletype == "G_CYC_1CYCLE" else 2 + if not settings.set_rendermode: + return default_for_no_rendermode + return ( + getattr(settings, f"blend_p{cycle}") == p + and getattr(settings, f"blend_a{cycle}") == a + and getattr(settings, f"blend_m{cycle}") == m + and getattr(settings, f"blend_b{cycle}") == b + ) + + +def is_blender_doing_fog(settings: "RDPSettings") -> bool: + return is_blender_lerp( + settings, + # If 2 cycle, fog must be in first cycle. + 1, + "G_BL_CLR_FOG", + "G_BL_A_SHADE", + # While technically it being fog only requires that P and A be fog color + # and shade alpha, the only reasonable choice for M and B in this case + # is color in and 1-A. + "G_BL_CLR_IN", + "G_BL_1MA", + # if NOT setting rendermode, it is more likely that the user is setting + # rendermodes in code, so to be safe we'll enable fog + True + ) + + +def get_blend_method(material: bpy.types.Material) -> str: + settings = material.f3d_mat.settings + if not settings.set_rendermode: + return drawLayerSM64Alpha[material.f3d_mat.draw_layer.sm64] + if settings.cvg_x_alpha: + return "CLIP" + if settings.force_bl and is_blender_lerp(settings, -1, + "G_BL_CLR_IN", "G_BL_A_IN", "G_BL_CLR_MEM", "G_BL_1MA"): + return "BLEND" + return "OPAQUE" def update_blend_method(material: Material, context): @@ -264,19 +323,6 @@ def update_blend_method(material: Material, context): material.alpha_threshold = 0.125 -def getZMode(material: Material): - f3dMat = material.f3d_mat - settings = f3dMat.rdp_settings - if not settings.set_rendermode: - return "ZMODE_OPA" - if settings.rendermode_advanced_enabled: - return settings.zmode - r1, r2 = rendermodePresetToBits(settings) - f3d = get_F3D_GBI() - zmode = ((r1 | r2) & f3d.ZMODE_DEC) // f3d.ZMODE_INTER - return enumZMode[zmode][0] - - class DrawLayerProperty(PropertyGroup): sm64: bpy.props.EnumProperty(items=sm64EnumDrawLayers, default="1", update=update_draw_layer) oot: bpy.props.EnumProperty(items=ootEnumDrawLayers, default="Opaque", update=update_draw_layer) @@ -422,19 +468,16 @@ def indentGroup(parent: UILayout, textOrProp: Union[str, "F3DMaterialProperty"], isF3DEX3 = bpy.context.scene.f3d_type == "F3DEX3" lightFxPrereq = isF3DEX3 and settings.g_lighting + ccWarnings = shadeInCC = False + blendWarnings = shadeInBlender = zInBlender = False if isinstance(dataHolder, F3DMaterialProperty): - ccWarnings = blendWarnings = True + ccWarnings = True ccUse = all_combiner_uses(dataHolder) shadeInCC = ccUse["Shade"] or ccUse["Shade Alpha"] - blendUse = all_blender_uses(settings) - if blendUse is None: - blendWarnings = shadeInBlender = zInBlender = False - else: - shadeInBlender = blendUse["Shade Alpha"] - zInBlender = blendUse["Z Buffer"] - else: - ccWarnings = shadeInCC = False - blendWarnings = shadeInBlender = zInBlender = False + if rdp_settings.set_rendermode: + blendWarnings = True + shadeInBlender = does_blender_use_alpha(rdp_settings, "G_BL_A_SHADE") + zInBlender = settings.z_cmp or settings.z_upd inputGroup.prop(settings, "g_shade_smooth") @@ -913,7 +956,11 @@ def ui_misc(self, f3dMat: "F3DMaterialProperty", inputCol: UILayout, showCheckBo if f3dMat.set_attroffs_z: prop_split(inputGroup.row(), f3dMat, "attroffs_z", "Z Attr Offset") - if f3dMat.rdp_settings.g_fog: + if ( + f3dMat.rdp_settings.g_fog + or does_blender_use_color(f3dMat.rdp_settings, "G_BL_CLR_FOG") + or does_blender_use_alpha(f3dMat.rdp_settings, "G_BL_A_FOG") + ): if showCheckBox or f3dMat.set_fog: inputGroup = inputCol.column() if showCheckBox: @@ -947,7 +994,7 @@ def ui_cel_shading(self, material: Material, layout: UILayout): prop_split(inputGroup.row(), cel, "tintPipeline", "Tint pipeline:") prop_split(inputGroup.row(), cel, "cutoutSource", "Cutout:") - if getZMode(material) != "ZMODE_OPA": + if material.f3d_mat.rdp_settings.zmode != "ZMODE_OPA": inputGroup.label(text = "zmode in blender / rendermode must be opaque.", icon = "ERROR") if cel.cutoutSource == "ENVIRONMENT": @@ -1020,9 +1067,7 @@ def checkDrawLayersWarnings(self, f3dMat: "F3DMaterialProperty", useDict: Dict[s settings = f3dMat.rdp_settings isF3DEX3 = bpy.context.scene.f3d_type == "F3DEX3" lightFxPrereq = isF3DEX3 and settings.g_lighting - - blendUse = all_blender_uses(settings) - anyUseShadeAlpha = useDict["Shade Alpha"] or (blendUse is not None and blendUse["Shade Alpha"]) + anyUseShadeAlpha = useDict["Shade Alpha"] or does_blender_use_alpha(settings, "G_BL_A_SHADE") g_lighting = settings.g_lighting g_fog = settings.g_fog @@ -1371,6 +1416,14 @@ def update_cel_cutout_source(self, context): f3dMat.combiner1.D_alpha = "0" +def update_rendermode_preset(self, context): + with F3DMaterial_UpdateLock(get_material_from_context(context)) as material: + if material: + rendermode_preset_to_advanced(material) + + update_node_values_with_preset(self, context) + + def getSocketFromCombinerToNodeDictColor(nodes, combinerInput): nodeName, socketIndex = combinerToNodeDictColor[combinerInput] return nodes[nodeName].outputs[socketIndex] if nodeName is not None else None @@ -1485,50 +1538,21 @@ def update_node_combiner(material, combinerInputs, cycleIndex): material.node_tree.links.new(cycle_node.inputs[i], input_value) -def check_fog_settings(material: Material): - f3dMat: "F3DMaterialProperty" = material.f3d_mat - fog_enabled: bool = f3dMat.rdp_settings.g_fog - fog_rendermode_enabled: bool = fog_enabled - - is_one_cycle = f3dMat.rdp_settings.g_mdsft_cycletype == "G_CYC_1CYCLE" - - if is_one_cycle or fog_enabled == False: - fog_rendermode_enabled = False - elif f3dMat.rdp_settings.set_rendermode: - if f3dMat.rdp_settings.rendermode_advanced_enabled: - if f3dMat.rdp_settings.blend_p1 == "G_BL_CLR_FOG" and f3dMat.rdp_settings.blend_a1 == "G_BL_A_SHADE": - fog_rendermode_enabled = True - else: - f3d = get_F3D_GBI() - r_mode = getattr(f3d, f3dMat.rdp_settings.rendermode_preset_cycle_1, f3d.G_RM_PASS) - - # Note: GBL_c1 uses (m1a) << 30 | (m1b) << 26 | (m2a) << 22 | (m2b) << 18 - # This checks if m1a is G_BL_CLR_FOG and m1b is G_BL_A_SHADE - if r_mode & (f3d.G_BL_CLR_FOG << 30) != 0 and r_mode & (f3d.G_BL_A_SHADE << 26): - fog_rendermode_enabled = True - else: - # if NOT setting rendermode, it is more likely that the user is setting rendermodes in code, - # so to be safe we'll enable fog - fog_rendermode_enabled = True - - return fog_enabled, fog_rendermode_enabled - - 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 - fog_enabled, fog_rendermode_enabled = check_fog_settings(material) - - nodes["Shade Color"].inputs["Fog"].default_value = int(fog_enabled) + nodes["Shade Color"].inputs["Fog"].default_value = int(shade_alpha_is_fog) fogBlender: ShaderNodeGroup = nodes["FogBlender"] - if fog_rendermode_enabled and fog_enabled: - fogBlender.node_tree = bpy.data.node_groups["FogBlender_On"] - else: - fogBlender.node_tree = bpy.data.node_groups["FogBlender_Off"] + fogBlender.node_tree = bpy.data.node_groups[ + "FogBlender_On" + if shade_alpha_is_fog and is_blender_doing_fog(material.f3d_mat.rdp_settings) + else "FogBlender_Off" + ] - if fog_enabled: + 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]) @@ -3093,13 +3117,13 @@ class RDPSettings(PropertyGroup): items=enumRenderModesCycle1, default="G_RM_AA_ZB_OPA_SURF", name="Render Mode Cycle 1", - update=update_node_values_with_preset, + update=update_rendermode_preset, ) rendermode_preset_cycle_2: bpy.props.EnumProperty( items=enumRenderModesCycle2, default="G_RM_AA_ZB_OPA_SURF2", name="Render Mode Cycle 2", - update=update_node_values_with_preset, + update=update_rendermode_preset, ) aa_en: bpy.props.BoolProperty( update=update_node_values_with_preset, From 9f5669e4ccd14b2afe6707c0f8cfae20cf01aa87 Mon Sep 17 00:00:00 2001 From: Sauraen Date: Sun, 31 Dec 2023 12:49:15 -0800 Subject: [PATCH 2/8] Bugfixes --- fast64_internal/f3d/f3d_material.py | 12 ++++++------ fast64_internal/f3d/f3d_writer.py | 3 +-- fast64_internal/oot/oot_upgrade.py | 1 + 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/fast64_internal/f3d/f3d_material.py b/fast64_internal/f3d/f3d_material.py index 41fcffb9f..92fe8694d 100644 --- a/fast64_internal/f3d/f3d_material.py +++ b/fast64_internal/f3d/f3d_material.py @@ -198,14 +198,14 @@ def get_with_default(preset, default): is_one_cycle = settings.g_mdsft_cycletype == "G_CYC_1CYCLE" if is_one_cycle: - r = get_with_default(rdp_settings.rendermode_preset_cycle_1, f3d.G_RM_AA_ZB_OPA_SURF) + r = get_with_default(settings.rendermode_preset_cycle_1, f3d.G_RM_AA_ZB_OPA_SURF) r1 = r # For GBL_c2, look at the same bits as for cycle 1. Cycle 1 bits are copied # to cycle 2 bits at export. r2 = r >> 2 else: - r1 = get_with_default(rdp_settings.rendermode_preset_cycle_1, f3d.G_RM_FOG_SHADE_A) - r2 = get_with_default(rdp_settings.rendermode_preset_cycle_2, f3d.G_RM_AA_ZB_OPA_SURF2) + r1 = get_with_default(settings.rendermode_preset_cycle_1, f3d.G_RM_FOG_SHADE_A) + r2 = get_with_default(settings.rendermode_preset_cycle_2, f3d.G_RM_AA_ZB_OPA_SURF2) r = r1 | r2 settings.aa_en = (r & f3d.AA_EN) != 0 @@ -306,7 +306,7 @@ def is_blender_doing_fog(settings: "RDPSettings") -> bool: def get_blend_method(material: bpy.types.Material) -> str: - settings = material.f3d_mat.settings + settings = material.f3d_mat.rdp_settings if not settings.set_rendermode: return drawLayerSM64Alpha[material.f3d_mat.draw_layer.sm64] if settings.cvg_x_alpha: @@ -474,9 +474,9 @@ def indentGroup(parent: UILayout, textOrProp: Union[str, "F3DMaterialProperty"], ccWarnings = True ccUse = all_combiner_uses(dataHolder) shadeInCC = ccUse["Shade"] or ccUse["Shade Alpha"] - if rdp_settings.set_rendermode: + if settings.set_rendermode: blendWarnings = True - shadeInBlender = does_blender_use_alpha(rdp_settings, "G_BL_A_SHADE") + shadeInBlender = does_blender_use_alpha(settings, "G_BL_A_SHADE") zInBlender = settings.z_cmp or settings.z_upd inputGroup.prop(settings, "g_shade_smooth") diff --git a/fast64_internal/f3d/f3d_writer.py b/fast64_internal/f3d/f3d_writer.py index 247ae76ab..15b6dec29 100644 --- a/fast64_internal/f3d/f3d_writer.py +++ b/fast64_internal/f3d/f3d_writer.py @@ -11,7 +11,6 @@ from .f3d_material import ( all_combiner_uses, getMaterialScrollDimensions, - getZMode, isTexturePointSampled, RDPSettings, ) @@ -920,7 +919,7 @@ def writeCelLevels(self, celTriList: Optional[GfxList] = None, triCmds: Optional # Don't want to have to change back and forth arbitrarily between decal and # opaque mode. So if you're using both lighter and darker, need to do those # first before switching to decal. - if getZMode(self.material) != "ZMODE_OPA": + if f3dMat.rdp_settings.zmode != "ZMODE_OPA": raise PluginError(f"Material {self.material.name} with cel shading: zmode in blender / rendermode must be opaque.", icon = "ERROR") wroteLighter = wroteDarker = usesDecal = False if len(cel.levels) == 0: diff --git a/fast64_internal/oot/oot_upgrade.py b/fast64_internal/oot/oot_upgrade.py index b3dfd90de..9815c6720 100644 --- a/fast64_internal/oot/oot_upgrade.py +++ b/fast64_internal/oot/oot_upgrade.py @@ -1,5 +1,6 @@ from dataclasses import dataclass from typing import TYPE_CHECKING +import bpy from bpy.types import Object, CollectionProperty from .data import OoT_ObjectData from .oot_utility import getEvalParams From ea8bb903d6c320f3bab14f01a1d7fc8ddd9b4950 Mon Sep 17 00:00:00 2001 From: Sauraen Date: Sun, 31 Dec 2023 13:25:59 -0800 Subject: [PATCH 3/8] GUI warnings for incompatible presets --- fast64_internal/f3d/f3d_gbi.py | 8 ++++ fast64_internal/f3d/f3d_material.py | 59 ++++++++++++++++++++--------- 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/fast64_internal/f3d/f3d_gbi.py b/fast64_internal/f3d/f3d_gbi.py index a8af5ebbf..5efc1634b 100644 --- a/fast64_internal/f3d/f3d_gbi.py +++ b/fast64_internal/f3d/f3d_gbi.py @@ -1404,6 +1404,14 @@ def RM_OPA_CI(clk): self.G_RM_FOG_PRIM_A = GBL_c1(G_BL_CLR_FOG, G_BL_A_FOG, G_BL_CLR_IN, G_BL_1MA) self.G_RM_PASS = GBL_c1(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) + self.rendermodePresetsWithoutFlags = { + "G_RM_NOOP", + "G_RM_NOOP2", + "G_RM_FOG_SHADE_A", + "G_RM_FOG_PRIM_A", + "G_RM_PASS", + } + # G_SETCONVERT: K0-5 self.G_CV_K0 = 175 diff --git a/fast64_internal/f3d/f3d_material.py b/fast64_internal/f3d/f3d_material.py index 92fe8694d..c5e9f1e0c 100644 --- a/fast64_internal/f3d/f3d_material.py +++ b/fast64_internal/f3d/f3d_material.py @@ -213,8 +213,8 @@ def get_with_default(preset, default): settings.z_upd = (r & f3d.Z_UPD) != 0 settings.im_rd = (r & f3d.IM_RD) != 0 settings.clr_on_cvg = (r & f3d.CLR_ON_CVG) != 0 - settings.cvg_dst = f3d.cvgDstDict[(r & f3d.CVG_DST_SAVE) // f3d.CVG_DST_WRAP] - settings.zmode = f3d.zmodeDict[(r & f3d.ZMODE_DEC) // f3d.ZMODE_INTER] + settings.cvg_dst = f3d.cvgDstDict[r & f3d.CVG_DST_SAVE] + settings.zmode = f3d.zmodeDict[r & f3d.ZMODE_DEC] settings.cvg_x_alpha = (r & f3d.CVG_X_ALPHA) != 0 settings.alpha_cvg_sel = (r & f3d.ALPHA_CVG_SEL) != 0 settings.force_bl = (r & f3d.FORCE_BL) != 0 @@ -851,9 +851,28 @@ def ui_lower_render_mode(self, material, layout, useDropdown): renderGroup = inputGroup.column() renderGroup.prop(material.rdp_settings, "rendermode_advanced_enabled", text="Show Advanced Settings") if not material.rdp_settings.rendermode_advanced_enabled: + f3d = get_F3D_GBI() prop_split(renderGroup, material.rdp_settings, "rendermode_preset_cycle_1", "Render Mode") + no_flags_1 = material.rdp_settings.rendermode_preset_cycle_1 in f3d.rendermodePresetsWithoutFlags if material.rdp_settings.g_mdsft_cycletype == "G_CYC_2CYCLE": prop_split(renderGroup, material.rdp_settings, "rendermode_preset_cycle_2", "Render Mode Cycle 2") + no_flags_2 = material.rdp_settings.rendermode_preset_cycle_2 in f3d.rendermodePresetsWithoutFlags + if no_flags_1 and no_flags_2: + multilineLabel(renderGroup.box(), + "Invalid combination of rendermode presets.\n" + + "Neither of these presets sets the rendermode flags.", + "ERROR") + elif not no_flags_1 and not no_flags_2: + multilineLabel(renderGroup.box(), + "Invalid combination of rendermode presets.\n" + + "Both of these presets set the rendermode flags.", + "ERROR") + else: + if no_flags_1: + multilineLabel(renderGroup.box(), + "Invalid rendermode preset in 1-cycle.\n" + + "This preset does not set the rendermode flags.", + "ERROR") else: prop_split(renderGroup, material.rdp_settings, "aa_en", "Antialiasing") prop_split(renderGroup, material.rdp_settings, "z_cmp", "Z Testing") @@ -866,22 +885,6 @@ def ui_lower_render_mode(self, material, layout, useDropdown): prop_split(renderGroup, material.rdp_settings, "alpha_cvg_sel", "Use Coverage For Alpha") prop_split(renderGroup, material.rdp_settings, "force_bl", "Force Blending") - if material.rdp_settings.g_mdsft_cycletype == "G_CYC_2CYCLE": - if ( - material.rdp_settings.blend_b1 == "G_BL_A_MEM" or - material.rdp_settings.blend_p1 == "G_BL_CLR_MEM" or - material.rdp_settings.blend_m1 == "G_BL_CLR_MEM" - ): - multilineLabel(renderGroup.box(), - "RDP silicon bug: Framebuffer color / alpha in blender\n" + - "cycle 1 is broken, actually value from PREVIOUS pixel.", - 'ORPHAN_DATA') - if material.rdp_settings.blend_a2 == "G_BL_A_SHADE": - multilineLabel(renderGroup.box(), - "RDP silicon bug: Shade alpha in blender cycle 2\n" + - "is broken, actually shade alpha from NEXT pixel.", - 'ORPHAN_DATA') - # cycle dependent - (P * A + M - B) / (A + B) combinerBox = renderGroup.box() combinerBox.label(text="Blender (Color = (P * A + M * B) / (A + B)") @@ -904,6 +907,22 @@ def ui_lower_render_mode(self, material, layout, useDropdown): rowAlpha2.prop(material.rdp_settings, "blend_a2", text="A") rowAlpha2.prop(material.rdp_settings, "blend_b2", text="B") + if material.rdp_settings.g_mdsft_cycletype == "G_CYC_2CYCLE": + if ( + material.rdp_settings.blend_b1 == "G_BL_A_MEM" or + material.rdp_settings.blend_p1 == "G_BL_CLR_MEM" or + material.rdp_settings.blend_m1 == "G_BL_CLR_MEM" + ): + multilineLabel(renderGroup.box(), + "RDP silicon bug: Framebuffer color / alpha in blender\n" + + "cycle 1 is broken, actually value from PREVIOUS pixel.", + 'ORPHAN_DATA') + if material.rdp_settings.blend_a2 == "G_BL_A_SHADE": + multilineLabel(renderGroup.box(), + "RDP silicon bug: Shade alpha in blender cycle 2\n" + + "is broken, actually shade alpha from NEXT pixel.", + 'ORPHAN_DATA') + renderGroup.enabled = material.rdp_settings.set_rendermode def ui_uvCheck(self, layout, context): @@ -2120,6 +2139,10 @@ def load_handler(dummy): bpy.context.scene["f3d_lib_dir"] = None # force node reload! link_f3d_material_library() + for mat in bpy.data.materials: + if mat is not None and mat.use_nodes and mat.is_f3d: + rendermode_preset_to_advanced(mat) + bpy.app.handlers.load_post.append(load_handler) From 99b7e9f356bd5efee658a1213616cd8d987d5f9c Mon Sep 17 00:00:00 2001 From: Sauraen Date: Mon, 8 Jan 2024 21:21:44 -0800 Subject: [PATCH 4/8] blacked --- fast64_internal/f3d/f3d_material.py | 80 ++++++++++++----------------- 1 file changed, 34 insertions(+), 46 deletions(-) diff --git a/fast64_internal/f3d/f3d_material.py b/fast64_internal/f3d/f3d_material.py index dce9d4f09..2202575ec 100644 --- a/fast64_internal/f3d/f3d_material.py +++ b/fast64_internal/f3d/f3d_material.py @@ -183,11 +183,11 @@ def rendermode_preset_to_advanced(material: bpy.types.Material): """ settings = material.f3d_mat.rdp_settings f3d = get_F3D_GBI() - + if settings.rendermode_advanced_enabled: # Already in advanced mode, don't overwrite this with the preset return - + def get_with_default(preset, default): # Use the default either if we are not setting rendermode, or if the # preset is not in the GBI. We do want to set the advanced settings @@ -195,7 +195,7 @@ def get_with_default(preset, default): if not settings.set_rendermode: return default return getattr(f3d, preset, default) - + is_one_cycle = settings.g_mdsft_cycletype == "G_CYC_1CYCLE" if is_one_cycle: r = get_with_default(settings.rendermode_preset_cycle_1, f3d.G_RM_AA_ZB_OPA_SURF) @@ -207,7 +207,7 @@ def get_with_default(preset, default): r1 = get_with_default(settings.rendermode_preset_cycle_1, f3d.G_RM_FOG_SHADE_A) r2 = get_with_default(settings.rendermode_preset_cycle_2, f3d.G_RM_AA_ZB_OPA_SURF2) r = r1 | r2 - + settings.aa_en = (r & f3d.AA_EN) != 0 settings.z_cmp = (r & f3d.Z_CMP) != 0 settings.z_upd = (r & f3d.Z_UPD) != 0 @@ -218,7 +218,7 @@ def get_with_default(preset, default): settings.cvg_x_alpha = (r & f3d.CVG_X_ALPHA) != 0 settings.alpha_cvg_sel = (r & f3d.ALPHA_CVG_SEL) != 0 settings.force_bl = (r & f3d.FORCE_BL) != 0 - + settings.blend_p1 = f3d.blendColorDict[(r1 >> 30) & 3] settings.blend_p2 = f3d.blendColorDict[(r2 >> 28) & 3] settings.blend_a1 = f3d.blendAlphaDict[(r1 >> 26) & 3] @@ -229,36 +229,25 @@ def get_with_default(preset, default): settings.blend_b2 = f3d.blendMixDict[(r2 >> 16) & 3] -def does_blender_use_color( - settings: "RDPSettings", - color: str, - default_for_no_rendermode: bool = False -) -> bool: +def does_blender_use_color(settings: "RDPSettings", color: str, default_for_no_rendermode: bool = False) -> bool: if not settings.set_rendermode: return default_for_no_rendermode is_one_cycle = settings.g_mdsft_cycletype == "G_CYC_1CYCLE" return ( - settings.blend_p1 == color or settings.blend_m1 == color + settings.blend_p1 == color + or settings.blend_m1 == color or (is_one_cycle and (settings.blend_p2 == color or settings.blend_m2 == color)) ) - -def does_blender_use_alpha( - settings: "RDPSettings", - alpha: str, - default_for_no_rendermode: bool = False -) -> bool: + +def does_blender_use_alpha(settings: "RDPSettings", alpha: str, default_for_no_rendermode: bool = False) -> bool: if not settings.set_rendermode: return default_for_no_rendermode is_one_cycle = settings.g_mdsft_cycletype == "G_CYC_1CYCLE" return settings.blend_a1 == alpha or (is_one_cycle and settings.blend_a2 == alpha) -def does_blender_use_mix( - settings: "RDPSettings", - mix: str, - default_for_no_rendermode: bool = False -) -> bool: +def does_blender_use_mix(settings: "RDPSettings", mix: str, default_for_no_rendermode: bool = False) -> bool: if not settings.set_rendermode: return default_for_no_rendermode is_one_cycle = settings.g_mdsft_cycletype == "G_CYC_1CYCLE" @@ -266,13 +255,7 @@ def does_blender_use_mix( def is_blender_lerp( - settings: "RDPSettings", - cycle: int, - p: str, - a: str, - m: str, - b: str, - default_for_no_rendermode: bool = False + settings: "RDPSettings", cycle: int, p: str, a: str, m: str, b: str, default_for_no_rendermode: bool = False ) -> bool: assert cycle in {1, 2, -1} # -1 = last cycle if cycle == -1: @@ -301,7 +284,7 @@ def is_blender_doing_fog(settings: "RDPSettings") -> bool: "G_BL_1MA", # if NOT setting rendermode, it is more likely that the user is setting # rendermodes in code, so to be safe we'll enable fog - True + True, ) @@ -311,8 +294,7 @@ def get_blend_method(material: bpy.types.Material) -> str: return drawLayerSM64Alpha[material.f3d_mat.draw_layer.sm64] if settings.cvg_x_alpha: return "CLIP" - if settings.force_bl and is_blender_lerp(settings, -1, - "G_BL_CLR_IN", "G_BL_A_IN", "G_BL_CLR_MEM", "G_BL_1MA"): + if settings.force_bl and is_blender_lerp(settings, -1, "G_BL_CLR_IN", "G_BL_A_IN", "G_BL_CLR_MEM", "G_BL_1MA"): return "BLEND" return "OPAQUE" @@ -849,21 +831,27 @@ def ui_lower_render_mode(self, material, layout, useDropdown): prop_split(renderGroup, material.rdp_settings, "rendermode_preset_cycle_2", "Render Mode Cycle 2") no_flags_2 = material.rdp_settings.rendermode_preset_cycle_2 in f3d.rendermodePresetsWithoutFlags if no_flags_1 and no_flags_2: - multilineLabel(renderGroup.box(), + multilineLabel( + renderGroup.box(), "Invalid combination of rendermode presets.\n" + "Neither of these presets sets the rendermode flags.", - "ERROR") + "ERROR", + ) elif not no_flags_1 and not no_flags_2: - multilineLabel(renderGroup.box(), + multilineLabel( + renderGroup.box(), "Invalid combination of rendermode presets.\n" + "Both of these presets set the rendermode flags.", - "ERROR") + "ERROR", + ) else: if no_flags_1: - multilineLabel(renderGroup.box(), + multilineLabel( + renderGroup.box(), "Invalid rendermode preset in 1-cycle.\n" + "This preset does not set the rendermode flags.", - "ERROR") + "ERROR", + ) else: prop_split(renderGroup, material.rdp_settings, "aa_en", "Antialiasing") prop_split(renderGroup, material.rdp_settings, "z_cmp", "Z Testing") @@ -906,16 +894,16 @@ def ui_lower_render_mode(self, material, layout, useDropdown): ): multilineLabel( renderGroup.box(), - "RDP silicon bug: Framebuffer color / alpha in blender\n" + - "cycle 1 is broken, actually value from PREVIOUS pixel.", - 'ORPHAN_DATA' + "RDP silicon bug: Framebuffer color / alpha in blender\n" + + "cycle 1 is broken, actually value from PREVIOUS pixel.", + "ORPHAN_DATA", ) if material.rdp_settings.blend_a2 == "G_BL_A_SHADE": multilineLabel( renderGroup.box(), - "RDP silicon bug: Shade alpha in blender cycle 2\n" + - "is broken, actually shade alpha from NEXT pixel.", - 'ORPHAN_DATA' + "RDP silicon bug: Shade alpha in blender cycle 2\n" + + "is broken, actually shade alpha from NEXT pixel.", + "ORPHAN_DATA", ) renderGroup.enabled = material.rdp_settings.set_rendermode @@ -1007,7 +995,7 @@ def ui_cel_shading(self, material: Material, layout: UILayout): cel = material.f3d_mat.cel_shading prop_split(inputGroup.row(), cel, "tintPipeline", "Tint pipeline:") prop_split(inputGroup.row(), cel, "cutoutSource", "Cutout:") - + if material.f3d_mat.rdp_settings.zmode != "ZMODE_OPA": inputGroup.label(text="zmode in blender / rendermode must be opaque.", icon="ERROR") @@ -1440,7 +1428,7 @@ def update_rendermode_preset(self, context): with F3DMaterial_UpdateLock(get_material_from_context(context)) as material: if material: rendermode_preset_to_advanced(material) - + update_node_values_with_preset(self, context) From dc11898badcf31cb1cf9d067b425e8d4b744c73c Mon Sep 17 00:00:00 2001 From: Sauraen Date: Mon, 8 Jan 2024 22:11:22 -0800 Subject: [PATCH 5/8] Addressing comments --- fast64_internal/f3d/f3d_material.py | 63 +++++++++++++++-------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/fast64_internal/f3d/f3d_material.py b/fast64_internal/f3d/f3d_material.py index 2202575ec..95b7fbca4 100644 --- a/fast64_internal/f3d/f3d_material.py +++ b/fast64_internal/f3d/f3d_material.py @@ -196,18 +196,20 @@ def get_with_default(preset, default): return default return getattr(f3d, preset, default) - is_one_cycle = settings.g_mdsft_cycletype == "G_CYC_1CYCLE" - if is_one_cycle: - r = get_with_default(settings.rendermode_preset_cycle_1, f3d.G_RM_AA_ZB_OPA_SURF) - r1 = r - # For GBL_c2, look at the same bits as for cycle 1. Cycle 1 bits are copied - # to cycle 2 bits at export. - r2 = r >> 2 - else: + is_two_cycle = settings.g_mdsft_cycletype == "G_CYC_2CYCLE" + if is_two_cycle: r1 = get_with_default(settings.rendermode_preset_cycle_1, f3d.G_RM_FOG_SHADE_A) r2 = get_with_default(settings.rendermode_preset_cycle_2, f3d.G_RM_AA_ZB_OPA_SURF2) r = r1 | r2 + else: + r = get_with_default(settings.rendermode_preset_cycle_1, f3d.G_RM_AA_ZB_OPA_SURF) + r1 = r + # The cycle 1 bits are copied to the cycle 2 bits at export if in 1-cycle mode + # (the hardware requires them to be the same). So, here we also move the cycle 1 + # bits to the cycle 2 slots. r2 is only read for the cycle dependent settings below. + r2 = r >> 2 + # cycle independent settings.aa_en = (r & f3d.AA_EN) != 0 settings.z_cmp = (r & f3d.Z_CMP) != 0 settings.z_upd = (r & f3d.Z_UPD) != 0 @@ -219,6 +221,7 @@ def get_with_default(preset, default): settings.alpha_cvg_sel = (r & f3d.ALPHA_CVG_SEL) != 0 settings.force_bl = (r & f3d.FORCE_BL) != 0 + # cycle dependent / lerp settings.blend_p1 = f3d.blendColorDict[(r1 >> 30) & 3] settings.blend_p2 = f3d.blendColorDict[(r2 >> 28) & 3] settings.blend_a1 = f3d.blendAlphaDict[(r1 >> 26) & 3] @@ -232,26 +235,26 @@ def get_with_default(preset, default): def does_blender_use_color(settings: "RDPSettings", color: str, default_for_no_rendermode: bool = False) -> bool: if not settings.set_rendermode: return default_for_no_rendermode - is_one_cycle = settings.g_mdsft_cycletype == "G_CYC_1CYCLE" + is_two_cycle = settings.g_mdsft_cycletype == "G_CYC_2CYCLE" return ( settings.blend_p1 == color or settings.blend_m1 == color - or (is_one_cycle and (settings.blend_p2 == color or settings.blend_m2 == color)) + or (is_two_cycle and (settings.blend_p2 == color or settings.blend_m2 == color)) ) def does_blender_use_alpha(settings: "RDPSettings", alpha: str, default_for_no_rendermode: bool = False) -> bool: if not settings.set_rendermode: return default_for_no_rendermode - is_one_cycle = settings.g_mdsft_cycletype == "G_CYC_1CYCLE" - return settings.blend_a1 == alpha or (is_one_cycle and settings.blend_a2 == alpha) + is_two_cycle = settings.g_mdsft_cycletype == "G_CYC_2CYCLE" + return settings.blend_a1 == alpha or (is_two_cycle and settings.blend_a2 == alpha) def does_blender_use_mix(settings: "RDPSettings", mix: str, default_for_no_rendermode: bool = False) -> bool: if not settings.set_rendermode: return default_for_no_rendermode - is_one_cycle = settings.g_mdsft_cycletype == "G_CYC_1CYCLE" - return settings.blend_b1 == mix or (is_one_cycle and settings.blend_b2 == mix) + is_two_cycle = settings.g_mdsft_cycletype == "G_CYC_2CYCLE" + return settings.blend_b1 == mix or (is_two_cycle and settings.blend_b2 == mix) def is_blender_lerp( @@ -259,7 +262,7 @@ def is_blender_lerp( ) -> bool: assert cycle in {1, 2, -1} # -1 = last cycle if cycle == -1: - cycle = 1 if settings.g_mdsft_cycletype == "G_CYC_1CYCLE" else 2 + cycle = 2 if settings.g_mdsft_cycletype == "G_CYC_2CYCLE" else 1 if not settings.set_rendermode: return default_for_no_rendermode return ( @@ -367,9 +370,9 @@ def combiner_uses( checkAlpha=True, swapTexelsCycle2=True, ): - is2Cycle = f3dMat.rdp_settings.g_mdsft_cycletype == "G_CYC_2CYCLE" + is_two_cycle = f3dMat.rdp_settings.g_mdsft_cycletype == "G_CYC_2CYCLE" for i in range(1, 3): - if i == 1 and not checkCycle1 or i == 2 and (not checkCycle2 or not is2Cycle): + if i == 1 and not checkCycle1 or i == 2 and (not checkCycle2 or not is_two_cycle): continue combiner = getattr(f3dMat, f"combiner{i}") for isAlpha in [False, True]: @@ -575,7 +578,6 @@ def ui_upper_mode(settings, dataHolder, layout: UILayout, useDropdown): prop_split(inputGroup, settings, "g_mdsft_textdetail", "Texture Detail") prop_split(inputGroup, settings, "g_mdsft_textpersp", "Texture Perspective Correction") prop_split(inputGroup, settings, "g_mdsft_cycletype", "Cycle Type") - prop_split(inputGroup, settings, "g_mdsft_pipeline", "Pipeline Span Buffer Coherency") @@ -809,6 +811,7 @@ def ui_convert(self, material, layout, showCheckBox): return inputGroup def ui_lower_render_mode(self, material, layout, useDropdown): + is_two_cycle = material.rdp_settings.g_mdsft_cycletype == "G_CYC_2CYCLE" # cycle independent inputGroup = layout.column() if useDropdown: @@ -827,7 +830,7 @@ def ui_lower_render_mode(self, material, layout, useDropdown): f3d = get_F3D_GBI() prop_split(renderGroup, material.rdp_settings, "rendermode_preset_cycle_1", "Render Mode") no_flags_1 = material.rdp_settings.rendermode_preset_cycle_1 in f3d.rendermodePresetsWithoutFlags - if material.rdp_settings.g_mdsft_cycletype == "G_CYC_2CYCLE": + if is_two_cycle: prop_split(renderGroup, material.rdp_settings, "rendermode_preset_cycle_2", "Render Mode Cycle 2") no_flags_2 = material.rdp_settings.rendermode_preset_cycle_2 in f3d.rendermodePresetsWithoutFlags if no_flags_1 and no_flags_2: @@ -875,7 +878,7 @@ def ui_lower_render_mode(self, material, layout, useDropdown): rowAlpha.prop(material.rdp_settings, "blend_a1", text="A") rowAlpha.prop(material.rdp_settings, "blend_b1", text="B") - if material.rdp_settings.g_mdsft_cycletype == "G_CYC_2CYCLE": + if is_two_cycle: combinerBox2 = renderGroup.box() combinerBox2.label(text="Blender Cycle 2") combinerCol2 = combinerBox2.row() @@ -886,7 +889,7 @@ def ui_lower_render_mode(self, material, layout, useDropdown): rowAlpha2.prop(material.rdp_settings, "blend_a2", text="A") rowAlpha2.prop(material.rdp_settings, "blend_b2", text="B") - if material.rdp_settings.g_mdsft_cycletype == "G_CYC_2CYCLE": + if is_two_cycle: if ( material.rdp_settings.blend_b1 == "G_BL_A_MEM" or material.rdp_settings.blend_p1 == "G_BL_CLR_MEM" @@ -1167,7 +1170,7 @@ def drawCCProps(ui: UILayout, combiner: "CombinerProperty", isAlpha: bool, enabl r.label(text=f"{letter}{' Alpha' if isAlpha else ''}:") r.prop(combiner, f"{letter}{'_alpha' if isAlpha else ''}", text="") - isTwoCycle = f3dMat.rdp_settings.g_mdsft_cycletype == "G_CYC_2CYCLE" + is_two_cycle = f3dMat.rdp_settings.g_mdsft_cycletype == "G_CYC_2CYCLE" combinerBox = layout.box() combinerBox.prop(f3dMat, "set_combiner", text="Color Combiner (Color = (A - B) * C + D)") @@ -1177,10 +1180,10 @@ def drawCCProps(ui: UILayout, combiner: "CombinerProperty", isAlpha: bool, enabl drawCCProps(combinerCol, f3dMat.combiner1, True, not f3dMat.use_cel_shading) if f3dMat.use_cel_shading: r = combinerBox.column().label( - text=f"CC alpha{' cycle 1' if isTwoCycle else ''} is occupied by cel shading." + text=f"CC alpha{' cycle 1' if is_two_cycle else ''} is occupied by cel shading." ) - if isTwoCycle: + if is_two_cycle: combinerBox2 = layout.box() combinerBox2.label(text="Color Combiner Cycle 2") combinerBox2.enabled = f3dMat.set_combiner @@ -1625,19 +1628,19 @@ def update_combiner_connections(material: Material, context: Context, combiner: def set_output_node_groups(material: Material): nodes = material.node_tree.nodes f3dMat: "F3DMaterialProperty" = material.f3d_mat - is_one_cycle = f3dMat.rdp_settings.g_mdsft_cycletype == "G_CYC_1CYCLE" + is_two_cycle = f3dMat.rdp_settings.g_mdsft_cycletype == "G_CYC_2CYCLE" output_node = nodes["OUTPUT"] - if is_one_cycle: + if is_two_cycle: if material.blend_method == "OPAQUE": - output_node.node_tree = bpy.data.node_groups["OUTPUT_1CYCLE_OPA"] + output_node.node_tree = bpy.data.node_groups["OUTPUT_2CYCLE_OPA"] else: - output_node.node_tree = bpy.data.node_groups["OUTPUT_1CYCLE_XLU"] + output_node.node_tree = bpy.data.node_groups["OUTPUT_2CYCLE_XLU"] else: if material.blend_method == "OPAQUE": - output_node.node_tree = bpy.data.node_groups["OUTPUT_2CYCLE_OPA"] + output_node.node_tree = bpy.data.node_groups["OUTPUT_1CYCLE_OPA"] else: - output_node.node_tree = bpy.data.node_groups["OUTPUT_2CYCLE_XLU"] + output_node.node_tree = bpy.data.node_groups["OUTPUT_1CYCLE_XLU"] def update_light_colors(material, context): From f192c848614b8937da01d186def518f4a877dfbe Mon Sep 17 00:00:00 2001 From: Sauraen Date: Tue, 30 Jan 2024 21:51:01 -0800 Subject: [PATCH 6/8] Changes for Dragorn --- fast64_internal/f3d/f3d_material.py | 19 +++++++++---------- fast64_internal/f3d/f3d_material_presets.py | 8 ++++---- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/fast64_internal/f3d/f3d_material.py b/fast64_internal/f3d/f3d_material.py index 7b39e75b5..7583b85b5 100644 --- a/fast64_internal/f3d/f3d_material.py +++ b/fast64_internal/f3d/f3d_material.py @@ -189,11 +189,9 @@ def rendermode_preset_to_advanced(material: bpy.types.Material): return def get_with_default(preset, default): - # Use the default either if we are not setting rendermode, or if the - # preset is not in the GBI. We do want to set the advanced settings - # even if not setting rendermode, because they are read for nodes preview. - if not settings.set_rendermode: - return default + # Use the material's settings even if we are not setting rendermode. + # This allows the user to enable setting rendermode, set it up as they + # want, then disable it, and have it still previewed that way. return getattr(f3d, preset, default) is_two_cycle = settings.g_mdsft_cycletype == "G_CYC_2CYCLE" @@ -273,7 +271,7 @@ def is_blender_lerp( ) -def is_blender_doing_fog(settings: "RDPSettings") -> bool: +def is_blender_doing_fog(settings: "RDPSettings", default_for_no_rendermode: bool) -> bool: return is_blender_lerp( settings, # If 2 cycle, fog must be in first cycle. @@ -285,9 +283,7 @@ def is_blender_doing_fog(settings: "RDPSettings") -> bool: # is color in and 1-A. "G_BL_CLR_IN", "G_BL_1MA", - # if NOT setting rendermode, it is more likely that the user is setting - # rendermodes in code, so to be safe we'll enable fog - True, + default_for_no_rendermode, ) @@ -1557,9 +1553,12 @@ def update_fog_nodes(material: Material, context: Context): nodes["Shade Color"].inputs["Fog"].default_value = int(shade_alpha_is_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) + if shade_alpha_is_fog and is_blender_doing_fog(material.f3d_mat.rdp_settings, True) else "FogBlender_Off" ] diff --git a/fast64_internal/f3d/f3d_material_presets.py b/fast64_internal/f3d/f3d_material_presets.py index bcdfa0722..004968bba 100644 --- a/fast64_internal/f3d/f3d_material_presets.py +++ b/fast64_internal/f3d/f3d_material_presets.py @@ -3888,7 +3888,7 @@ f3d_mat.rdp_settings.clip_ratio = 1 f3d_mat.rdp_settings.set_rendermode = True f3d_mat.rdp_settings.rendermode_advanced_enabled = False -f3d_mat.rdp_settings.rendermode_preset_cycle_1 = 'G_RM_OPA_SURF' +f3d_mat.rdp_settings.rendermode_preset_cycle_1 = 'G_RM_PASS' f3d_mat.rdp_settings.rendermode_preset_cycle_2 = 'G_RM_AA_ZB_XLU_SURF2' f3d_mat.rdp_settings.aa_en = False f3d_mat.rdp_settings.z_cmp = False @@ -4020,7 +4020,7 @@ f3d_mat.rdp_settings.clip_ratio = 1 f3d_mat.rdp_settings.set_rendermode = True f3d_mat.rdp_settings.rendermode_advanced_enabled = False -f3d_mat.rdp_settings.rendermode_preset_cycle_1 = 'G_RM_OPA_SURF' +f3d_mat.rdp_settings.rendermode_preset_cycle_1 = 'G_RM_PASS' f3d_mat.rdp_settings.rendermode_preset_cycle_2 = 'G_RM_AA_ZB_XLU_SURF2' f3d_mat.rdp_settings.aa_en = False f3d_mat.rdp_settings.z_cmp = False @@ -6228,7 +6228,7 @@ f3d_mat.rdp_settings.clip_ratio = 1 f3d_mat.rdp_settings.set_rendermode = True f3d_mat.rdp_settings.rendermode_advanced_enabled = False -f3d_mat.rdp_settings.rendermode_preset_cycle_1 = 'G_RM_OPA_SURF' +f3d_mat.rdp_settings.rendermode_preset_cycle_1 = 'G_RM_PASS' f3d_mat.rdp_settings.rendermode_preset_cycle_2 = 'G_RM_AA_ZB_XLU_SURF2' f3d_mat.rdp_settings.aa_en = False f3d_mat.rdp_settings.z_cmp = False @@ -6978,7 +6978,7 @@ f3d_mat.rdp_settings.clip_ratio = 1 f3d_mat.rdp_settings.set_rendermode = True f3d_mat.rdp_settings.rendermode_advanced_enabled = False -f3d_mat.rdp_settings.rendermode_preset_cycle_1 = 'G_RM_OPA_SURF' +f3d_mat.rdp_settings.rendermode_preset_cycle_1 = 'G_RM_PASS' f3d_mat.rdp_settings.rendermode_preset_cycle_2 = 'G_RM_AA_ZB_XLU_SURF2' f3d_mat.rdp_settings.aa_en = False f3d_mat.rdp_settings.z_cmp = False From bb3a64f12350157bd9011c440acdbb1b77585462 Mon Sep 17 00:00:00 2001 From: Sauraen Date: Sun, 11 Feb 2024 16:07:30 -0800 Subject: [PATCH 7/8] Fixed not updating rendermode when creating material from preset in code --- fast64_internal/f3d/f3d_material.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fast64_internal/f3d/f3d_material.py b/fast64_internal/f3d/f3d_material.py index 7583b85b5..bb7b28df4 100644 --- a/fast64_internal/f3d/f3d_material.py +++ b/fast64_internal/f3d/f3d_material.py @@ -2103,6 +2103,7 @@ def update_preset_manual_v4(material, preset): material.f3d_update_flag = True with bpy.context.temp_override(material=material): bpy.ops.script.execute_preset(filepath=findF3DPresetPath(preset), menu_idname="MATERIAL_MT_f3d_presets") + rendermode_preset_to_advanced(material) material.f3d_update_flag = False From 6f699835e6c8286b75d328da5a1b249c51597f6f Mon Sep 17 00:00:00 2001 From: Sauraen Date: Tue, 13 Feb 2024 21:49:32 -0800 Subject: [PATCH 8/8] Updated function name for Dragorn --- fast64_internal/f3d/f3d_material.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fast64_internal/f3d/f3d_material.py b/fast64_internal/f3d/f3d_material.py index bb7b28df4..eba909095 100644 --- a/fast64_internal/f3d/f3d_material.py +++ b/fast64_internal/f3d/f3d_material.py @@ -255,7 +255,7 @@ def does_blender_use_mix(settings: "RDPSettings", mix: str, default_for_no_rende return settings.blend_b1 == mix or (is_two_cycle and settings.blend_b2 == mix) -def is_blender_lerp( +def is_blender_equation_equal( settings: "RDPSettings", cycle: int, p: str, a: str, m: str, b: str, default_for_no_rendermode: bool = False ) -> bool: assert cycle in {1, 2, -1} # -1 = last cycle @@ -272,7 +272,7 @@ def is_blender_lerp( def is_blender_doing_fog(settings: "RDPSettings", default_for_no_rendermode: bool) -> bool: - return is_blender_lerp( + return is_blender_equation_equal( settings, # If 2 cycle, fog must be in first cycle. 1, @@ -293,7 +293,9 @@ def get_blend_method(material: bpy.types.Material) -> str: return drawLayerSM64Alpha[material.f3d_mat.draw_layer.sm64] if settings.cvg_x_alpha: return "CLIP" - if settings.force_bl and is_blender_lerp(settings, -1, "G_BL_CLR_IN", "G_BL_A_IN", "G_BL_CLR_MEM", "G_BL_1MA"): + if settings.force_bl and is_blender_equation_equal( + settings, -1, "G_BL_CLR_IN", "G_BL_A_IN", "G_BL_CLR_MEM", "G_BL_1MA" + ): return "BLEND" return "OPAQUE"