Skip to content

Commit

Permalink
[F3D] Fog Export Fix (#350)
Browse files Browse the repository at this point in the history
* fog exports now when using fog, changed checking of blend inputs to class property of rdpsettings

* fixed small bug

* fixed generator for blend_inputs, made some code more clear

---------

Co-authored-by: scut <scut>
  • Loading branch information
jesusyoshi54 authored Jun 11, 2024
1 parent a062be6 commit 2f96875
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
48 changes: 23 additions & 25 deletions fast64_internal/f3d/f3d_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,24 +230,6 @@ 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:
if not settings.set_rendermode:
return default_for_no_rendermode
is_two_cycle = settings.g_mdsft_cycletype == "G_CYC_2CYCLE"
return (
settings.blend_p1 == color
or settings.blend_m1 == 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_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
Expand Down Expand Up @@ -450,7 +432,7 @@ def indentGroup(parent: UILayout, textOrProp: Union[str, "F3DMaterialProperty"],
shadeInCC = ccUse["Shade"] or ccUse["Shade Alpha"]
if settings.set_rendermode:
blendWarnings = True
shadeInBlender = does_blender_use_alpha(settings, "G_BL_A_SHADE")
shadeInBlender = settings.does_blender_use_input("G_BL_A_SHADE")
zInBlender = settings.z_cmp or settings.z_upd

inputGroup.prop(settings, "g_shade_smooth")
Expand Down Expand Up @@ -959,11 +941,7 @@ 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
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 f3dMat.rdp_settings.using_fog:
if showCheckBox or f3dMat.set_fog:
inputGroup = inputCol.column()
if showCheckBox:
Expand Down Expand Up @@ -1070,7 +1048,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
anyUseShadeAlpha = useDict["Shade Alpha"] or does_blender_use_alpha(settings, "G_BL_A_SHADE")
anyUseShadeAlpha = useDict["Shade Alpha"] or settings.does_blender_use_input("G_BL_A_SHADE")

g_lighting = settings.g_lighting
g_fog = settings.g_fog
Expand Down Expand Up @@ -3316,6 +3294,26 @@ class RDPSettings(PropertyGroup):
update=update_node_values_with_preset,
)

@property
def using_fog(self):
return self.g_fog or self.does_blender_use_input("G_BL_CLR_FOG") or self.does_blender_use_input("G_BL_A_FOG")

@property
def blend_color_inputs(self):
yield from (getattr(self, f"blend_{val}") for val in ("p1", "p2", "m1", "m2"))

@property
def blend_alpha_inputs(self):
yield from (getattr(self, f"blend_{val}") for val in ("a1", "a2", "b1", "b2"))

@property
def blend_inputs(self):
yield from self.blend_color_inputs
yield from self.blend_alpha_inputs

def does_blender_use_input(self, setting: str) -> bool:
return any(input == setting for input in self.blend_inputs)

def key(self):
setRM = self.set_rendermode
rmAdv = self.rendermode_advanced_enabled
Expand Down
2 changes: 1 addition & 1 deletion fast64_internal/f3d/f3d_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ def saveOrGetF3DMaterial(material, fModel, obj, drawLayer, convertTextureData):
if f3dMat.set_attroffs_z:
fMaterial.mat_only_DL.commands.append(SPAttrOffsetZ(f3dMat.attroffs_z))

if f3dMat.set_fog:
if f3dMat.set_fog and f3dMat.rdp_settings.using_fog:
if f3dMat.use_global_fog and fModel.global_data.getCurrentAreaData() is not None:
fogData = fModel.global_data.getCurrentAreaData().fog_data
fog_position = fogData.position
Expand Down

0 comments on commit 2f96875

Please sign in to comment.