From 395ac5053290c128be26e554a35c6409edbff631 Mon Sep 17 00:00:00 2001 From: Agent X <44549182+Agent-11@users.noreply.github.com> Date: Wed, 1 Nov 2023 21:21:46 -0400 Subject: [PATCH] Add ability to set fog intensity multiplier (ramps up quickly) --- autogen/lua_definitions/functions.lua | 11 ++++++++ docs/lua/functions-5.md | 38 +++++++++++++++++++++++++++ docs/lua/functions.md | 2 ++ src/pc/gfx/gfx_pc.c | 5 ++-- src/pc/gfx/gfx_pc.h | 1 + src/pc/lua/smlua_functions_autogen.c | 34 ++++++++++++++++++++++++ src/pc/lua/utils/smlua_misc_utils.c | 8 ++++++ src/pc/lua/utils/smlua_misc_utils.h | 2 ++ src/pc/network/network.c | 1 + 9 files changed, 100 insertions(+), 2 deletions(-) diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index 47b8d8b1..9a1354c7 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -8676,6 +8676,11 @@ function get_fog_color(index) -- ... end +--- @return number +function get_fog_intensity() + -- ... +end + --- @return boolean function get_got_file_coin_hi_score() -- ... @@ -8883,6 +8888,12 @@ function set_fog_color(index, value) -- ... end +--- @param intensity number +--- @return nil +function set_fog_intensity(intensity) + -- ... +end + --- @param value boolean --- @return nil function set_got_file_coin_hi_score(value) diff --git a/docs/lua/functions-5.md b/docs/lua/functions-5.md index 70ecb702..80739dd1 100644 --- a/docs/lua/functions-5.md +++ b/docs/lua/functions-5.md @@ -813,6 +813,24 @@
+## [get_fog_intensity](#get_fog_intensity) + +### Lua Example +`local numberValue = get_fog_intensity()` + +### Parameters +- None + +### Returns +- `number` + +### C Prototype +`f32 get_fog_intensity(void);` + +[:arrow_up_small:](#) + +
+ ## [get_got_file_coin_hi_score](#get_got_file_coin_hi_score) ### Lua Example @@ -1466,6 +1484,26 @@
+## [set_fog_intensity](#set_fog_intensity) + +### Lua Example +`set_fog_intensity(intensity)` + +### Parameters +| Field | Type | +| ----- | ---- | +| intensity | `number` | + +### Returns +- None + +### C Prototype +`void set_fog_intensity(f32 intensity);` + +[:arrow_up_small:](#) + +
+ ## [set_got_file_coin_hi_score](#set_got_file_coin_hi_score) ### Lua Example diff --git a/docs/lua/functions.md b/docs/lua/functions.md index 8dce1a7a..cd86f053 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -1625,6 +1625,7 @@ - [get_envfx](functions-5.md#get_envfx) - [get_environment_region](functions-5.md#get_environment_region) - [get_fog_color](functions-5.md#get_fog_color) + - [get_fog_intensity](functions-5.md#get_fog_intensity) - [get_got_file_coin_hi_score](functions-5.md#get_got_file_coin_hi_score) - [get_hand_foot_pos_x](functions-5.md#get_hand_foot_pos_x) - [get_hand_foot_pos_y](functions-5.md#get_hand_foot_pos_y) @@ -1658,6 +1659,7 @@ - [save_file_set_using_backup_slot](functions-5.md#save_file_set_using_backup_slot) - [set_environment_region](functions-5.md#set_environment_region) - [set_fog_color](functions-5.md#set_fog_color) + - [set_fog_intensity](functions-5.md#set_fog_intensity) - [set_got_file_coin_hi_score](functions-5.md#set_got_file_coin_hi_score) - [set_last_completed_course_num](functions-5.md#set_last_completed_course_num) - [set_last_completed_star_num](functions-5.md#set_last_completed_star_num) diff --git a/src/pc/gfx/gfx_pc.c b/src/pc/gfx/gfx_pc.c index 2afb381c..4f150b5b 100644 --- a/src/pc/gfx/gfx_pc.c +++ b/src/pc/gfx/gfx_pc.c @@ -184,6 +184,7 @@ Vec3f gLightingDir; Color gLightingColor = { 255, 255, 255 }; Color gVertexColor = { 255, 255, 255 }; Color gFogColor = { 255, 255, 255 }; +f32 gFogIntensity = 1; // 4x4 pink-black checkerboard texture to indicate missing textures #define MISSING_W 4 @@ -848,7 +849,7 @@ static void OPTIMIZE_O3 gfx_sp_vertex(size_t n_vertices, size_t dest_index, cons z *= sDepthZMult; z += sDepthZAdd; - float fog_z = z * winv * rsp.fog_mul + rsp.fog_offset; + float fog_z = z * winv * rsp.fog_mul * gFogIntensity + rsp.fog_offset; if (fog_z < 0) fog_z = 0; if (fog_z > 255) fog_z = 255; @@ -1013,7 +1014,7 @@ static void OPTIMIZE_O3 gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t float u = (v_arr[i]->u - rdp.texture_tile.uls * 8) / 32.0f; float v = (v_arr[i]->v - rdp.texture_tile.ult * 8) / 32.0f; if ((rdp.other_mode_h & (3U << G_MDSFT_TEXTFILT)) != G_TF_POINT) { - // Linear filter adds 0.5f to the coordinates + // Linear filter adds 0.5f to the coordinates (why?) u += 0.5f; v += 0.5f; } diff --git a/src/pc/gfx/gfx_pc.h b/src/pc/gfx/gfx_pc.h index 91cf3d0c..3fcbf7c1 100644 --- a/src/pc/gfx/gfx_pc.h +++ b/src/pc/gfx/gfx_pc.h @@ -17,6 +17,7 @@ extern Vec3f gLightingDir; extern Color gLightingColor; extern Color gVertexColor; extern Color gFogColor; +extern f32 gFogIntensity; #ifdef __cplusplus extern "C" { diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index ee9866e1..646d14d2 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -28687,6 +28687,21 @@ int smlua_func_get_fog_color(lua_State* L) { return 1; } +int smlua_func_get_fog_intensity(UNUSED lua_State* L) { + if (L == NULL) { return 0; } + + int top = lua_gettop(L); + if (top != 0) { + LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "get_fog_intensity", 0, top); + return 0; + } + + + lua_pushnumber(L, get_fog_intensity()); + + return 1; +} + int smlua_func_get_got_file_coin_hi_score(UNUSED lua_State* L) { if (L == NULL) { return 0; } @@ -29266,6 +29281,23 @@ int smlua_func_set_fog_color(lua_State* L) { return 1; } +int smlua_func_set_fog_intensity(lua_State* L) { + if (L == NULL) { return 0; } + + int top = lua_gettop(L); + if (top != 1) { + LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "set_fog_intensity", 1, top); + return 0; + } + + f32 intensity = smlua_to_number(L, 1); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "set_fog_intensity"); return 0; } + + set_fog_intensity(intensity); + + return 1; +} + int smlua_func_set_got_file_coin_hi_score(lua_State* L) { if (L == NULL) { return 0; } @@ -32709,6 +32741,7 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "get_envfx", smlua_func_get_envfx); smlua_bind_function(L, "get_environment_region", smlua_func_get_environment_region); smlua_bind_function(L, "get_fog_color", smlua_func_get_fog_color); + smlua_bind_function(L, "get_fog_intensity", smlua_func_get_fog_intensity); smlua_bind_function(L, "get_got_file_coin_hi_score", smlua_func_get_got_file_coin_hi_score); smlua_bind_function(L, "get_hand_foot_pos_x", smlua_func_get_hand_foot_pos_x); smlua_bind_function(L, "get_hand_foot_pos_y", smlua_func_get_hand_foot_pos_y); @@ -32742,6 +32775,7 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "save_file_set_using_backup_slot", smlua_func_save_file_set_using_backup_slot); smlua_bind_function(L, "set_environment_region", smlua_func_set_environment_region); smlua_bind_function(L, "set_fog_color", smlua_func_set_fog_color); + smlua_bind_function(L, "set_fog_intensity", smlua_func_set_fog_intensity); smlua_bind_function(L, "set_got_file_coin_hi_score", smlua_func_set_got_file_coin_hi_score); smlua_bind_function(L, "set_last_completed_course_num", smlua_func_set_last_completed_course_num); smlua_bind_function(L, "set_last_completed_star_num", smlua_func_set_last_completed_star_num); diff --git a/src/pc/lua/utils/smlua_misc_utils.c b/src/pc/lua/utils/smlua_misc_utils.c index a82b3296..17c940a6 100644 --- a/src/pc/lua/utils/smlua_misc_utils.c +++ b/src/pc/lua/utils/smlua_misc_utils.c @@ -558,6 +558,14 @@ void set_fog_color(u8 index, u8 value) { gFogColor[index] = value; } +f32 get_fog_intensity(void) { + return gFogIntensity; +} + +void set_fog_intensity(f32 intensity) { + gFogIntensity = intensity; +} + /// s8 get_skybox(void) { diff --git a/src/pc/lua/utils/smlua_misc_utils.h b/src/pc/lua/utils/smlua_misc_utils.h index b3778175..1f82b142 100644 --- a/src/pc/lua/utils/smlua_misc_utils.h +++ b/src/pc/lua/utils/smlua_misc_utils.h @@ -132,6 +132,8 @@ void set_vertex_color(u8 index, u8 value); u8 get_fog_color(u8 index); void set_fog_color(u8 index, u8 value); +f32 get_fog_intensity(void); +void set_fog_intensity(f32 intensity); s8 get_skybox(void); void set_override_skybox(s8 background); diff --git a/src/pc/network/network.c b/src/pc/network/network.c index aefd3881..fadfce61 100644 --- a/src/pc/network/network.c +++ b/src/pc/network/network.c @@ -653,6 +653,7 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnect gFogColor[0] = 255; gFogColor[1] = 255; gFogColor[2] = 255; + gFogIntensity = 1; gOverrideBackground = -1; gOverrideEnvFx = -1; gDjuiRenderBehindHud = false;