Skip to content

Commit

Permalink
Fixed fog issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sauraen committed Jul 7, 2024
1 parent f8afc22 commit 37ab683
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 15 deletions.
Binary file modified fast64_internal/f3d/f3d_material_library.blend
Binary file not shown.
2 changes: 1 addition & 1 deletion fast64_internal/oot/oot_level_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self):
self.diffuseDir1 = (0, 0, 0)
self.fogColor = (0, 0, 0)
self.fogNear = 0
self.fogFar = 0
self.zFar = 0
self.transitionSpeed = 0

def getBlendFogNear(self):
Expand Down
4 changes: 2 additions & 2 deletions fast64_internal/oot/oot_level_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ def parseLightList(
blendFogShort = hexOrDecInt(lightParams[18])
fogNear = blendFogShort & ((1 << 10) - 1)
transitionSpeed = blendFogShort >> 10
fogFar = hexOrDecInt(lightParams[19])
zFar = hexOrDecInt(lightParams[19])

lightHeader = sceneHeader.lightList.add()
lightHeader.ambient = ambientColor + (1,)
Expand All @@ -1097,7 +1097,7 @@ def parseLightList(

lightHeader.fogColor = fogColor + (1,)
lightHeader.fogNear = fogNear
lightHeader.fogFar = fogFar
lightHeader.zFar = zFar
lightHeader.transitionSpeed = transitionSpeed

index += 1
Expand Down
2 changes: 1 addition & 1 deletion fast64_internal/oot/oot_level_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def getLightData(lightProp):
light.fogColor = exportColor(lightProp.fogColor)
light.fogNear = lightProp.fogNear
light.transitionSpeed = lightProp.transitionSpeed
light.fogFar = lightProp.fogFar
light.zFar = lightProp.zFar
return light


Expand Down
2 changes: 1 addition & 1 deletion fast64_internal/oot/scene/exporter/to_c/scene_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def getLightSettingsEntry(light: OOTLight, lightMode: str, isLightingCustom: boo

fogData = [
(light.getBlendFogNear(), "Blend Rate & Fog Near"),
(f"{light.fogFar}", "Fog Far"),
(f"{light.zFar}", "Z Far"),
]

lightDescs = ["Dawn", "Day", "Dusk", "Night"]
Expand Down
6 changes: 3 additions & 3 deletions fast64_internal/oot/scene/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class OOTLightProperty(PropertyGroup):
)
fogNear: IntProperty(name="", default=993, min=0, max=2**10 - 1, update=on_update_oot_render_settings)
transitionSpeed: IntProperty(name="", default=1, min=0, max=63, update=on_update_oot_render_settings)
fogFar: IntProperty(name="", default=0x3200, min=0, max=2**16 - 1, update=on_update_oot_render_settings)
zFar: IntProperty(name="", default=0x3200, min=0, max=2**15 - 1, update=on_update_oot_render_settings)
expandTab: BoolProperty(name="Expand Tab")

def draw_props(
Expand Down Expand Up @@ -212,8 +212,8 @@ def draw_props(
box.prop(self, "useCustomDiffuse1")

prop_split(box, self, "fogColor", "Fog Color")
prop_split(box, self, "fogNear", "Fog Near")
prop_split(box, self, "fogFar", "Fog Far")
prop_split(box, self, "fogNear", "Fog Near (Fog Far=1000)")
prop_split(box, self, "zFar", "Z Far (Draw Distance)")
prop_split(box, self, "transitionSpeed", "Transition Speed")


Expand Down
16 changes: 9 additions & 7 deletions fast64_internal/render_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def on_update_sm64_render_settings(self, context: bpy.types.Context):
area: bpy.types.Object = renderSettings.sm64Area
renderSettings.fogPreviewColor = tuple(c for c in area.area_fog_color)
renderSettings.fogPreviewPosition = tuple(round(p) for p in area.area_fog_position)

renderSettings.clippingPlanes = tuple(float(p) for p in area.clipPlanes)


Expand Down Expand Up @@ -38,7 +37,8 @@ def on_update_oot_render_settings(self, context: bpy.types.Context):
renderSettings.light1Color = tuple(c for c in col1)
renderSettings.light1Direction = tuple(d for d in dir1)
renderSettings.fogPreviewColor = tuple(c for c in l.fogColor)
renderSettings.fogPreviewPosition = (l.fogNear, l.fogFar)
renderSettings.fogPreviewPosition = (l.fogNear, 1000) # fogFar is always 1000 in OoT
renderSettings.clippingPlanes = (10.0, l.zFar) # zNear seems to always be 10 in OoT
else:
if lMode == "LIGHT_MODE_TIME":
tod = header.timeOfDayLights
Expand Down Expand Up @@ -81,10 +81,12 @@ def interpColors(cola, colb, fade):
)
).normalized()
renderSettings.light1Direction = -renderSettings.light0Direction
renderSettings.fogColor = interpColors(la.fogColor, lb.fogColor, fade)
renderSettings.fogPreviewPosition = (
la.fogNear + int(float(lb.fogNear - la.fogNear) * fade),
la.fogFar + int(float(lb.fogFar - la.fogFar) * fade),
renderSettings.fogPreviewColor = interpColors(la.fogColor, lb.fogColor, fade)
renderSettings.fogPreviewPosition = ( # fogFar is always 1000 in OoT
la.fogNear + int(float(lb.fogNear - la.fogNear) * fade), 1000
)
renderSettings.clippingPlanes = ( # zNear seems to always be 10 in OoT
10.0, la.zFar + float(lb.zFar - la.zFar) * fade
)


Expand Down Expand Up @@ -239,7 +241,7 @@ class Fast64RenderSettings_Properties(bpy.types.PropertyGroup):
)
# Fog Preview is int because values reflect F3D values
fogPreviewPosition: bpy.props.IntVectorProperty(
name="Fog Position", size=2, min=0, max=0x7FFFFFFF, default=(985, 1000), update=on_update_render_preview_nodes
name="Fog Position", size=2, min=0, max=1000, default=(985, 1000), update=on_update_render_preview_nodes
)
# Clipping planes are float because values reflect F3D values
clippingPlanes: bpy.props.FloatVectorProperty(
Expand Down

0 comments on commit 37ab683

Please sign in to comment.