sm64coopdx/mods/day-night-cycle/skybox.lua

61 lines
2.6 KiB
Lua
Raw Normal View History

2023-12-18 22:01:33 +00:00
-- localize functions to improve performance
2024-06-30 19:38:31 +00:00
local set_override_far,obj_mark_for_deletion,vec3f_to_object_pos,get_skybox,clampf = set_override_far,obj_mark_for_deletion,vec3f_to_object_pos,get_skybox,clampf
2023-12-18 22:01:33 +00:00
--- @param o Object
function bhv_skybox_init(o)
o.header.gfx.skipInViewCheck = true
2024-06-30 19:38:31 +00:00
set_override_far(200000)
2023-12-18 22:01:33 +00:00
end
--- @param o Object
function bhv_skybox_loop(o)
2024-06-30 19:38:31 +00:00
if not is_dnc_enabled() then
2023-12-18 22:01:33 +00:00
obj_mark_for_deletion(o)
return
end
vec3f_to_object_pos(o, gLakituState.pos)
local skybox = get_skybox()
-- do not rotate BITDW skybox
if skybox == BACKGROUND_GREEN_SKY then return end
2024-06-30 19:38:31 +00:00
local minutes = get_time_minutes()
2023-12-18 22:01:33 +00:00
2024-06-30 19:38:31 +00:00
o.oFaceAngleYaw = (minutes / 24) * 0x10000
2023-12-18 22:01:33 +00:00
if o.oBehParams2ndByte == SKYBOX_DAY then
2024-06-30 19:38:31 +00:00
o.oOpacity = 255
2023-12-18 22:01:33 +00:00
elseif o.oBehParams2ndByte == SKYBOX_SUNSET then
if minutes >= HOUR_SUNRISE_START and minutes <= HOUR_SUNRISE_END then
2024-06-30 19:38:31 +00:00
o.oOpacity = lerp_ceil(0, 255, clampf((minutes - HOUR_SUNRISE_START) / HOUR_SUNRISE_DURATION, 0, 1))
2023-12-18 22:01:33 +00:00
elseif minutes >= HOUR_SUNRISE_END and minutes <= HOUR_DAY_START then
2024-06-30 19:38:31 +00:00
o.oOpacity = lerp_ceil(255, 0, clampf((minutes - HOUR_SUNRISE_END) / HOUR_SUNRISE_DURATION, 0, 1))
2023-12-18 22:01:33 +00:00
elseif minutes >= HOUR_SUNSET_START and minutes <= HOUR_SUNSET_END then
2024-06-30 19:38:31 +00:00
o.oOpacity = lerp_ceil(0, 255, clampf((minutes - HOUR_SUNSET_START) / HOUR_SUNSET_DURATION, 0, 1))
2023-12-18 22:01:33 +00:00
elseif minutes >= HOUR_SUNSET_END and minutes <= HOUR_NIGHT_START then
o.oOpacity = 255
else
o.oOpacity = 0
end
if minutes < 12 then
2024-06-30 19:38:31 +00:00
o.oAnimState = if_then_else(skybox == BACKGROUND_BELOW_CLOUDS, BACKGROUND_BELOW_CLOUDS_SUNRISE, BACKGROUND_SUNRISE)
2023-12-18 22:01:33 +00:00
else
2024-06-30 19:38:31 +00:00
o.oAnimState = if_then_else(skybox == BACKGROUND_BELOW_CLOUDS, BACKGROUND_BELOW_CLOUDS_SUNSET, BACKGROUND_SUNSET)
2023-12-18 22:01:33 +00:00
end
2024-06-30 19:38:31 +00:00
o.oFaceAngleYaw = o.oFaceAngleYaw - if_then_else(minutes < 12, 0x3000, 0x6000)
2023-12-18 22:01:33 +00:00
elseif o.oBehParams2ndByte == SKYBOX_NIGHT then
if minutes >= HOUR_SUNRISE_START and minutes <= HOUR_SUNRISE_END then
2024-06-30 19:38:31 +00:00
o.oOpacity = lerp_ceil(255, 0, clampf((minutes - HOUR_SUNRISE_START) / HOUR_SUNRISE_DURATION, 0, 1))
2023-12-18 22:01:33 +00:00
elseif minutes >= HOUR_SUNSET_END and minutes <= HOUR_NIGHT_START then
2024-06-30 19:38:31 +00:00
o.oOpacity = lerp_ceil(0, 255, clampf((minutes - HOUR_SUNSET_END) / HOUR_SUNSET_DURATION, 0, 1))
2023-12-18 22:01:33 +00:00
elseif minutes > HOUR_SUNRISE_END and minutes < HOUR_SUNSET_END then
o.oOpacity = 0
elseif minutes > HOUR_NIGHT_START or minutes < HOUR_SUNRISE_START then
o.oOpacity = 255
end
end
end