From 3359ebba0bdaf2935bb93e613559cf5b5cc17f8a Mon Sep 17 00:00:00 2001 From: Agent X <44549182+AgentXLP@users.noreply.github.com> Date: Thu, 27 Jun 2024 16:54:13 -0400 Subject: [PATCH] Add AWESOME new lighting color functions --- autogen/lua_definitions/functions.lua | 16 ++++++++ docs/lua/functions-3.md | 18 +++++++++ docs/lua/functions-5.md | 41 ++++++++++++++++++++ docs/lua/functions.md | 3 ++ src/pc/gfx/gfx_pc.c | 17 ++++----- src/pc/gfx/gfx_pc.h | 2 +- src/pc/lua/smlua_functions_autogen.c | 54 +++++++++++++++++++++++++++ src/pc/lua/utils/smlua_gfx_utils.c | 15 +++++++- src/pc/lua/utils/smlua_gfx_utils.h | 2 + src/pc/network/network.c | 9 +++-- 10 files changed, 161 insertions(+), 16 deletions(-) diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index 0e6df384..9aaf3ee8 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -2946,6 +2946,10 @@ function shake_camera_yaw(pos, focus) -- ... end +function skip_camera_interpolation() + -- ... +end + --- @param c Camera function soft_reset_camera(c) -- ... @@ -7885,6 +7889,12 @@ function get_lighting_color(index) -- ... end +--- @param index integer +--- @return integer +function get_lighting_color_ambient(index) + -- ... +end + --- @param index integer --- @return number function get_lighting_dir(index) @@ -7925,6 +7935,12 @@ function set_lighting_color(index, value) -- ... end +--- @param index integer +--- @param value integer +function set_lighting_color_ambient(index, value) + -- ... +end + --- @param index integer --- @param value number function set_lighting_dir(index, value) diff --git a/docs/lua/functions-3.md b/docs/lua/functions-3.md index 4b95ec89..5ec6be4e 100644 --- a/docs/lua/functions-3.md +++ b/docs/lua/functions-3.md @@ -1706,6 +1706,24 @@
+## [skip_camera_interpolation](#skip_camera_interpolation) + +### Lua Example +`skip_camera_interpolation()` + +### Parameters +- None + +### Returns +- None + +### C Prototype +`void skip_camera_interpolation(void);` + +[:arrow_up_small:](#) + +
+ ## [soft_reset_camera](#soft_reset_camera) ### Lua Example diff --git a/docs/lua/functions-5.md b/docs/lua/functions-5.md index ae73a115..bd2532b9 100644 --- a/docs/lua/functions-5.md +++ b/docs/lua/functions-5.md @@ -1135,6 +1135,26 @@
+## [get_lighting_color_ambient](#get_lighting_color_ambient) + +### Lua Example +`local integerValue = get_lighting_color_ambient(index)` + +### Parameters +| Field | Type | +| ----- | ---- | +| index | `integer` | + +### Returns +- `integer` + +### C Prototype +`u8 get_lighting_color_ambient(u8 index);` + +[:arrow_up_small:](#) + +
+ ## [get_lighting_dir](#get_lighting_dir) ### Lua Example @@ -1275,6 +1295,27 @@
+## [set_lighting_color_ambient](#set_lighting_color_ambient) + +### Lua Example +`set_lighting_color_ambient(index, value)` + +### Parameters +| Field | Type | +| ----- | ---- | +| index | `integer` | +| value | `integer` | + +### Returns +- None + +### C Prototype +`void set_lighting_color_ambient(u8 index, u8 value);` + +[:arrow_up_small:](#) + +
+ ## [set_lighting_dir](#set_lighting_dir) ### Lua Example diff --git a/docs/lua/functions.md b/docs/lua/functions.md index 4560b450..3ed696f3 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -710,6 +710,7 @@ - [shake_camera_pitch](functions-3.md#shake_camera_pitch) - [shake_camera_roll](functions-3.md#shake_camera_roll) - [shake_camera_yaw](functions-3.md#shake_camera_yaw) + - [skip_camera_interpolation](functions-3.md#skip_camera_interpolation) - [soft_reset_camera](functions-3.md#soft_reset_camera) - [start_cutscene](functions-3.md#start_cutscene) - [start_object_cutscene_without_focus](functions-3.md#start_object_cutscene_without_focus) @@ -1655,6 +1656,7 @@ - [get_fog_color](functions-5.md#get_fog_color) - [get_fog_intensity](functions-5.md#get_fog_intensity) - [get_lighting_color](functions-5.md#get_lighting_color) + - [get_lighting_color_ambient](functions-5.md#get_lighting_color_ambient) - [get_lighting_dir](functions-5.md#get_lighting_dir) - [get_skybox](functions-5.md#get_skybox) - [get_skybox_color](functions-5.md#get_skybox_color) @@ -1662,6 +1664,7 @@ - [set_fog_color](functions-5.md#set_fog_color) - [set_fog_intensity](functions-5.md#set_fog_intensity) - [set_lighting_color](functions-5.md#set_lighting_color) + - [set_lighting_color_ambient](functions-5.md#set_lighting_color_ambient) - [set_lighting_dir](functions-5.md#set_lighting_dir) - [set_override_far](functions-5.md#set_override_far) - [set_override_fov](functions-5.md#set_override_fov) diff --git a/src/pc/gfx/gfx_pc.c b/src/pc/gfx/gfx_pc.c index eb0e72c7..fd888d9c 100644 --- a/src/pc/gfx/gfx_pc.c +++ b/src/pc/gfx/gfx_pc.c @@ -184,7 +184,7 @@ static f32 sDepthZMult = 1; static f32 sDepthZSub = 0; Vec3f gLightingDir; -Color gLightingColor = { 255, 255, 255 }; +Color gLightingColor[2] = { { 255, 255, 255 }, { 255, 255, 255 } }; Color gVertexColor = { 255, 255, 255 }; Color gFogColor = { 255, 255, 255 }; f32 gFogIntensity = 1; @@ -792,9 +792,9 @@ static void OPTIMIZE_O3 gfx_sp_vertex(size_t n_vertices, size_t dest_index, cons rsp.lights_changed = false; } - int r = rsp.current_lights[rsp.current_num_lights - 1].col[0]; - int g = rsp.current_lights[rsp.current_num_lights - 1].col[1]; - int b = rsp.current_lights[rsp.current_num_lights - 1].col[2]; + int r = rsp.current_lights[rsp.current_num_lights - 1].col[0] * gLightingColor[1][0] / 255.0f; + int g = rsp.current_lights[rsp.current_num_lights - 1].col[1] * gLightingColor[1][1] / 255.0f; + int b = rsp.current_lights[rsp.current_num_lights - 1].col[2] * gLightingColor[1][2] / 255.0f; for (int32_t i = 0; i < rsp.current_num_lights - 1; i++) { float intensity = 0; @@ -803,15 +803,12 @@ static void OPTIMIZE_O3 gfx_sp_vertex(size_t n_vertices, size_t dest_index, cons intensity += vn->n[2] * rsp.current_lights_coeffs[i][2]; intensity /= 127.0f; if (intensity > 0.0f) { - r += intensity * rsp.current_lights[i].col[0]; - g += intensity * rsp.current_lights[i].col[1]; - b += intensity * rsp.current_lights[i].col[2]; + r += intensity * rsp.current_lights[i].col[0] * gLightingColor[0][0] / 255.0f; + g += intensity * rsp.current_lights[i].col[1] * gLightingColor[0][1] / 255.0f; + b += intensity * rsp.current_lights[i].col[2] * gLightingColor[0][2] / 255.0f; } } - r *= gLightingColor[0] / 255.0f; - g *= gLightingColor[1] / 255.0f; - b *= gLightingColor[2] / 255.0f; d->color.r = r > 255 ? 255 : r; d->color.g = g > 255 ? 255 : g; d->color.b = b > 255 ? 255 : b; diff --git a/src/pc/gfx/gfx_pc.h b/src/pc/gfx/gfx_pc.h index 175c14d9..02a27221 100644 --- a/src/pc/gfx/gfx_pc.h +++ b/src/pc/gfx/gfx_pc.h @@ -14,7 +14,7 @@ struct GfxDimensions { extern struct GfxDimensions gfx_current_dimensions; extern Vec3f gLightingDir; -extern Color gLightingColor; +extern Color gLightingColor[2]; extern Color gVertexColor; extern Color gFogColor; extern f32 gFogIntensity; diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index 5edcf529..dc323db3 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -11868,6 +11868,21 @@ int smlua_func_shake_camera_yaw(lua_State* L) { return 1; } +int smlua_func_skip_camera_interpolation(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", "skip_camera_interpolation", 0, top); + return 0; + } + + + skip_camera_interpolation(); + + return 1; +} + int smlua_func_soft_reset_camera(lua_State* L) { if (L == NULL) { return 0; } @@ -29276,6 +29291,23 @@ int smlua_func_get_lighting_color(lua_State* L) { return 1; } +int smlua_func_get_lighting_color_ambient(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", "get_lighting_color_ambient", 1, top); + return 0; + } + + u8 index = smlua_to_integer(L, 1); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "get_lighting_color_ambient"); return 0; } + + lua_pushinteger(L, get_lighting_color_ambient(index)); + + return 1; +} + int smlua_func_get_lighting_dir(lua_State* L) { if (L == NULL) { return 0; } @@ -29397,6 +29429,25 @@ int smlua_func_set_lighting_color(lua_State* L) { return 1; } +int smlua_func_set_lighting_color_ambient(lua_State* L) { + if (L == NULL) { return 0; } + + int top = lua_gettop(L); + if (top != 2) { + LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "set_lighting_color_ambient", 2, top); + return 0; + } + + u8 index = smlua_to_integer(L, 1); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "set_lighting_color_ambient"); return 0; } + u8 value = smlua_to_integer(L, 2); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "set_lighting_color_ambient"); return 0; } + + set_lighting_color_ambient(index, value); + + return 1; +} + int smlua_func_set_lighting_dir(lua_State* L) { if (L == NULL) { return 0; } @@ -33481,6 +33532,7 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "shake_camera_pitch", smlua_func_shake_camera_pitch); smlua_bind_function(L, "shake_camera_roll", smlua_func_shake_camera_roll); smlua_bind_function(L, "shake_camera_yaw", smlua_func_shake_camera_yaw); + smlua_bind_function(L, "skip_camera_interpolation", smlua_func_skip_camera_interpolation); smlua_bind_function(L, "soft_reset_camera", smlua_func_soft_reset_camera); smlua_bind_function(L, "start_cutscene", smlua_func_start_cutscene); smlua_bind_function(L, "start_object_cutscene_without_focus", smlua_func_start_object_cutscene_without_focus); @@ -34371,6 +34423,7 @@ void smlua_bind_functions_autogen(void) { 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_lighting_color", smlua_func_get_lighting_color); + smlua_bind_function(L, "get_lighting_color_ambient", smlua_func_get_lighting_color_ambient); smlua_bind_function(L, "get_lighting_dir", smlua_func_get_lighting_dir); smlua_bind_function(L, "get_skybox", smlua_func_get_skybox); smlua_bind_function(L, "get_skybox_color", smlua_func_get_skybox_color); @@ -34378,6 +34431,7 @@ void smlua_bind_functions_autogen(void) { 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_lighting_color", smlua_func_set_lighting_color); + smlua_bind_function(L, "set_lighting_color_ambient", smlua_func_set_lighting_color_ambient); smlua_bind_function(L, "set_lighting_dir", smlua_func_set_lighting_dir); smlua_bind_function(L, "set_override_far", smlua_func_set_override_far); smlua_bind_function(L, "set_override_fov", smlua_func_set_override_fov); diff --git a/src/pc/lua/utils/smlua_gfx_utils.c b/src/pc/lua/utils/smlua_gfx_utils.c index 5d107a3c..ee7cf4d8 100644 --- a/src/pc/lua/utils/smlua_gfx_utils.c +++ b/src/pc/lua/utils/smlua_gfx_utils.c @@ -34,12 +34,23 @@ void set_lighting_dir(u8 index, f32 value) { u8 get_lighting_color(u8 index) { if (index > 2) { return 0; } - return gLightingColor[index]; + return gLightingColor[0][index]; +} + +u8 get_lighting_color_ambient(u8 index) { + if (index > 2) { return 0; } + return gLightingColor[1][index]; } void set_lighting_color(u8 index, u8 value) { if (index > 2) { return; } - gLightingColor[index] = value; + gLightingColor[0][index] = value; + gLightingColor[1][index] = value; +} + +void set_lighting_color_ambient(u8 index, u8 value) { + if (index > 2) { return; } + gLightingColor[1][index] = value; } /// diff --git a/src/pc/lua/utils/smlua_gfx_utils.h b/src/pc/lua/utils/smlua_gfx_utils.h index c4804d44..12801a47 100644 --- a/src/pc/lua/utils/smlua_gfx_utils.h +++ b/src/pc/lua/utils/smlua_gfx_utils.h @@ -11,7 +11,9 @@ f32 get_lighting_dir(u8 index); void set_lighting_dir(u8 index, f32 value); u8 get_lighting_color(u8 index); +u8 get_lighting_color_ambient(u8 index); void set_lighting_color(u8 index, u8 value); +void set_lighting_color_ambient(u8 index, u8 value); u8 get_vertex_color(u8 index); void set_vertex_color(u8 index, u8 value); diff --git a/src/pc/network/network.c b/src/pc/network/network.c index 7999a2d5..ccedac3c 100644 --- a/src/pc/network/network.c +++ b/src/pc/network/network.c @@ -669,9 +669,12 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnect gLightingDir[0] = 0; gLightingDir[1] = 0; gLightingDir[2] = 0; - gLightingColor[0] = 255; - gLightingColor[1] = 255; - gLightingColor[2] = 255; + gLightingColor[0][0] = 255; + gLightingColor[0][1] = 255; + gLightingColor[0][2] = 255; + gLightingColor[1][0] = 255; + gLightingColor[1][1] = 255; + gLightingColor[1][2] = 255; gVertexColor[0] = 255; gVertexColor[1] = 255; gVertexColor[2] = 255;