Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[F3D] Backport point lit ucode from AC pr #460

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,9 @@ def upgrade_changed_props():
OOT_ObjectProperties.upgrade_changed_props()
for scene in bpy.data.scenes:
settings: Fast64Settings_Properties = scene.fast64.settings
if settings.internal_game_update_ver != 1:
if settings.internal_game_update_ver < 2:
set_game_defaults(scene, False)
settings.internal_game_update_ver = 1
settings.internal_game_update_ver = 2
if scene.get("decomp_compatible", False):
scene.gameEditorMode = "Homebrew"
del scene["decomp_compatible"]
Expand Down
15 changes: 8 additions & 7 deletions fast64_internal/f3d/f3d_bleed.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
GfxList,
FTriGroup,
GbiMacro,
get_F3D_GBI,
)


Expand All @@ -58,8 +59,7 @@ class BleedGraphics:
def __init__(self):
self.bled_gfx_lists = dict()
# build world default cmds to compare against, f3d types needed for reset cmd building
self.is_f3d_old = bpy.context.scene.f3d_type == "F3D"
self.is_f3dex2 = "F3DEX2" in bpy.context.scene.f3d_type
self.f3d = get_F3D_GBI()
self.build_default_geo()
self.build_default_othermodes()

Expand All @@ -84,19 +84,20 @@ def place_in_flaglist(flag: bool, enum: str, set_list: SPSetGeometryMode, clear_
place_in_flaglist(defaults.g_tex_gen, "G_TEXTURE_GEN", setGeo, clearGeo)
place_in_flaglist(defaults.g_tex_gen_linear, "G_TEXTURE_GEN_LINEAR", setGeo, clearGeo)
place_in_flaglist(defaults.g_shade_smooth, "G_SHADING_SMOOTH", setGeo, clearGeo)
if bpy.context.scene.f3d_type == "F3DEX_GBI_2" or bpy.context.scene.f3d_type == "F3DEX_GBI":
if self.f3d.F3DEX_GBI:
place_in_flaglist(defaults.g_clipping, "G_CLIPPING", setGeo, clearGeo)

if self.f3d.POINT_LIT_GBI:
place_in_flaglist(defaults.g_lighting_positional, "G_LIGHTING_POSITIONAL", setGeo, clearGeo)
self.default_load_geo = SPLoadGeometryMode(setGeo.flagList)
self.default_set_geo = setGeo
self.default_clear_geo = clearGeo

def build_default_othermodes(self):
defaults = create_or_get_world(bpy.context.scene).rdp_defaults

othermode_H = SPSetOtherMode("G_SETOTHERMODE_H", 4, 20 - self.is_f3d_old, [])
othermode_H = SPSetOtherMode("G_SETOTHERMODE_H", 4, 20 - self.f3d.F3D_OLD_GBI, [])
# if the render mode is set, it will be consider non-default a priori
othermode_L = SPSetOtherMode("G_SETOTHERMODE_L", 0, 3 - self.is_f3d_old, [])
othermode_L = SPSetOtherMode("G_SETOTHERMODE_L", 0, 3 - self.f3d.F3D_OLD_GBI, [])

othermode_L.flagList.append(defaults.g_mdsft_alpha_compare)
othermode_L.flagList.append(defaults.g_mdsft_zsrcsel)
Expand Down Expand Up @@ -399,7 +400,7 @@ def create_reset_cmds(self, reset_cmd_dict: dict[GbiMacro], default_render_mode:
SPSetOtherMode(
"G_SETOTHERMODE_L",
0,
32 - self.is_f3d_old,
32 - self.f3d.F3D_OLD_GBI,
[*self.default_othermode_L.flagList, *default_render_mode],
)
)
Expand Down
25 changes: 18 additions & 7 deletions fast64_internal/f3d/f3d_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,24 @@
}

enumF3D = [
("F3D", "F3D", "Original microcode used in SM64"),
("F3DEX/LX", "F3DEX/LX", "F3DEX version 1"),
("F3DLX.Rej", "F3DLX.Rej", "F3DLX.Rej"),
("F3DLP.Rej", "F3DLP.Rej", "F3DLP.Rej"),
("F3DEX2/LX2", "F3DEX2/LX2/ZEX", "Family of microcodes used in later N64 games including OoT and MM"),
("F3DEX2.Rej/LX2.Rej", "F3DEX2.Rej/LX2.Rej", "Variant of F3DEX2 family using vertex rejection instead of clipping"),
("F3DEX3", "F3DEX3", "Custom microcode by Sauraen"),
("F3D", "F3D", "Original microcode used in SM64", 0),
("F3DEX/LX", "F3DEX/LX", "F3DEX version 1", 1),
("F3DLX.Rej", "F3DLX.Rej", "F3DLX.Rej", 2),
("F3DLP.Rej", "F3DLP.Rej", "F3DLP.Rej", 3),
("F3DEX2/LX2", "F3DEX2/LX2/ZEX", "Family of microcodes used in later N64 games including OoT", 4),
(
"F3DEX2.Rej/LX2.Rej",
"F3DEX2.Rej/LX2.Rej",
"Variant of F3DEX2 family using vertex rejection instead of clipping",
5,
),
(
"F3DEX2_PL",
"F3DEX2 (Point Lit)",
"Variant of F3DEX2 family with support for point lighting used in a few games including MM",
7,
),
("F3DEX3", "F3DEX3", "Custom microcode by Sauraen", 6),
]

enumLargeEdges = [
Expand Down
13 changes: 10 additions & 3 deletions fast64_internal/f3d/f3d_gbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class GfxMatWriteMethod(enum.Enum):
"F3DLX.Rej": (64, 32),
"F3DLP.Rej": (80, 32),
"F3DEX2/LX2": (32, 32),
"F3DEX2_PL": (32, 32),
"F3DEX2.Rej/LX2.Rej": (64, 64),
"F3DEX3": (56, 56),
}
Expand Down Expand Up @@ -137,13 +138,17 @@ def isUcodeF3DEX1(F3D_VER: str) -> bool:


def isUcodeF3DEX2(F3D_VER: str) -> bool:
return F3D_VER in {"F3DEX2.Rej/LX2.Rej", "F3DEX2/LX2"}
return F3D_VER in {"F3DEX2.Rej/LX2.Rej", "F3DEX2/LX2", "F3DEX2_PL"}


def isUcodeF3DEX3(F3D_VER: str) -> bool:
return F3D_VER == "F3DEX3"


def is_ucode_point_lit(F3D_VER: str) -> bool:
return F3D_VER in {"F3DEX3", "F3DEX2_PL"}


class F3D:
"""NOTE: do not initialize this class manually! use get_F3D_GBI so that the single instance is cached from the microcode type."""

Expand All @@ -154,6 +159,7 @@ def __init__(self, F3D_VER):
F3DEX_GBI_3 = self.F3DEX_GBI_3 = isUcodeF3DEX3(F3D_VER)
F3DLP_GBI = self.F3DLP_GBI = self.F3DEX_GBI
self.F3D_OLD_GBI = not (F3DEX_GBI or F3DEX_GBI_2 or F3DEX_GBI_3)
POINT_LIT_GBI = self.POINT_LIT_GBI = is_ucode_point_lit(F3D_VER)

# F3DEX2 is F3DEX1 and F3DEX3 is F3DEX2, but F3DEX3 is not F3DEX1
if F3DEX_GBI_2:
Expand Down Expand Up @@ -358,7 +364,6 @@ def __init__(self, F3D_VER):
self.G_LIGHTING_SPECULAR = 0x00002000
self.G_FRESNEL_COLOR = 0x00004000
self.G_FRESNEL_ALPHA = 0x00008000
self.G_LIGHTING_POSITIONAL = 0x00400000 # Ignored, always on

self.allGeomModeFlags = {
"G_ZBUFFER",
Expand All @@ -373,7 +378,6 @@ def __init__(self, F3D_VER):
"G_TEXTURE_GEN_LINEAR",
"G_LOD",
"G_SHADING_SMOOTH",
"G_LIGHTING_POSITIONAL",
"G_CLIPPING",
}
if F3DEX_GBI_3:
Expand All @@ -387,6 +391,9 @@ def __init__(self, F3D_VER):
"G_FRESNEL_COLOR",
"G_FRESNEL_ALPHA",
}
if POINT_LIT_GBI:
self.G_LIGHTING_POSITIONAL = 0x00400000
self.allGeomModeFlags.add("G_LIGHTING_POSITIONAL")

self.G_FOG_H = self.G_FOG / 0x10000
self.G_LIGHTING_H = self.G_LIGHTING / 0x10000
Expand Down
33 changes: 26 additions & 7 deletions fast64_internal/f3d/f3d_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,9 @@ def indentGroup(parent: UILayout, textOrProp: Union[str, "F3DMaterialProperty"],
c.enabled = enable or not disable_dependent
return c

isF3DEX3 = bpy.context.scene.f3d_type == "F3DEX3"
lightFxPrereq = isF3DEX3 and settings.g_lighting
f3d = get_F3D_GBI()

lightFxPrereq = f3d.F3DEX_GBI_3 and settings.g_lighting
ccWarnings = shadeInCC = False
blendWarnings = shadeInBlender = zInBlender = False
if isinstance(dataHolder, F3DMaterialProperty):
Expand All @@ -487,11 +488,13 @@ def indentGroup(parent: UILayout, textOrProp: Union[str, "F3DMaterialProperty"],
c = indentGroup(inputGroup, "g_lighting", False)
if ccWarnings and not shadeInCC and settings.g_lighting and not settings.g_tex_gen:
multilineLabel(c, "Shade not used in CC, can disable\nlighting.", icon="INFO")
if isF3DEX3:
if f3d.F3DEX_GBI_3:
c.prop(settings, "g_packed_normals")
c.prop(settings, "g_lighting_specular")
c.prop(settings, "g_ambocclusion")
c.prop(settings, "g_fresnel_color")
elif f3d.POINT_LIT_GBI: # Draw this flag in Not Useful for f3dex3
c.prop(settings, "g_lighting_positional")
d = indentGroup(c, "g_tex_gen", False)
d.prop(settings, "g_tex_gen_linear")

Expand All @@ -518,7 +521,7 @@ def indentGroup(parent: UILayout, textOrProp: Union[str, "F3DMaterialProperty"],
else:
shadeAlphaLabel = "Vtx alpha"
c = indentGroup(inputGroup, f"Shade alpha = {shadeAlphaLabel}:", True)
if isF3DEX3:
if f3d.F3DEX_GBI_3:
lighting_group = c.column(align=True)
lighting_group.enabled = settings.g_lighting or not disable_dependent
lighting_group.prop(settings, "g_lighttoalpha")
Expand All @@ -539,7 +542,7 @@ def indentGroup(parent: UILayout, textOrProp: Union[str, "F3DMaterialProperty"],
elif blendWarnings and not shadeInBlender and settings.g_fog:
c.label(text="Fog not used in rendermode / blender, can disable.", icon="INFO")

if isF3DEX3:
if f3d.F3DEX_GBI_3:
c = indentGroup(inputGroup, "Attribute offsets:", True)
c.prop(settings, "g_attroffset_st_enable")
c.prop(settings, "g_attroffset_z_enable")
Expand Down Expand Up @@ -570,8 +573,10 @@ def indentGroup(parent: UILayout, textOrProp: Union[str, "F3DMaterialProperty"],

c = indentGroup(inputGroup, "Not useful:", True)
c.prop(settings, "g_lod")
if isUcodeF3DEX1(bpy.context.scene.f3d_type):
if f3d.F3DEX_GBI:
Lilaa3 marked this conversation as resolved.
Show resolved Hide resolved
c.prop(settings, "g_clipping")
elif f3d.F3DEX_GBI_3:
c.prop(settings, "g_lighting_positional", text="Positional Lighting (Always enabled in EX3)")


def ui_upper_mode(settings, dataHolder, layout: UILayout, useDropdown):
Expand Down Expand Up @@ -3314,6 +3319,12 @@ class RDPSettings(PropertyGroup):
update=update_node_values_with_preset,
description="F3DEX1/LX only, exact function unknown",
)
g_lighting_positional: bpy.props.BoolProperty(
name="Positional Lighting",
default=False,
update=update_node_values_with_preset,
description="F3DEX2 (Point Lit): Enables calculating shade color using positional lights along with directional, ignored in F3DEX3",
)

# upper half mode
# v2 only
Expand Down Expand Up @@ -3594,6 +3605,10 @@ def attributes_from_dict(self, data: dict, info: dict):
("clipping", "g_clipping", True),
]

geo_mode_pl_attributes = [
("positionalLighting", "g_lighting_positional", False),
]

geo_mode_f3dex3_attributes = [
("ambientOcclusion", "g_ambocclusion", False),
("attroffsetZ", "g_attroffset_z_enable", False),
Expand All @@ -3604,13 +3619,17 @@ def attributes_from_dict(self, data: dict, info: dict):
("fresnelToColor", "g_fresnel_color", False),
("fresnelToAlpha", "g_fresnel_alpha", False),
]
geo_mode_attributes = geo_mode_all_attributes + geo_mode_f3dex_attributes + geo_mode_f3dex3_attributes
geo_mode_attributes = (
geo_mode_all_attributes + geo_mode_f3dex_attributes + geo_mode_pl_attributes + geo_mode_f3dex3_attributes
)

def geo_mode_to_dict(self, f3d=None):
f3d = f3d if f3d else get_F3D_GBI()
data = self.attributes_to_dict(self.geo_mode_all_attributes)
if f3d.F3DEX_GBI or f3d.F3DLP_GBI:
data.update(self.attributes_to_dict(self.geo_mode_f3dex_attributes))
if f3d.POINT_LIT_GBI:
data.update(self.attributes_to_dict(self.geo_mode_pl_attributes))
if f3d.F3DEX_GBI_3:
data.update(self.attributes_to_dict(self.geo_mode_f3dex3_attributes))
return data
Expand Down
Loading
Loading