From 2f949a325052e7c82fa166d2d982b18fc605ad1f Mon Sep 17 00:00:00 2001 From: Sonicxryan <38291306+Sonicxryan@users.noreply.github.com> Date: Thu, 6 Jul 2023 21:21:37 +0100 Subject: [PATCH] Shading (#439) --- autogen/lua_definitions/structs.lua | 6 ++++++ docs/lua/structs.md | 6 ++++++ include/types.h | 6 ++++++ src/game/mario.c | 8 ++++++++ src/game/mario_misc.c | 16 ++++++++++------ src/pc/lua/smlua_cobject_autogen.c | 8 +++++++- 6 files changed, 43 insertions(+), 7 deletions(-) diff --git a/autogen/lua_definitions/structs.lua b/autogen/lua_definitions/structs.lua index c54febad..955da147 100644 --- a/autogen/lua_definitions/structs.lua +++ b/autogen/lua_definitions/structs.lua @@ -708,8 +708,14 @@ --- @field public headAngle Vec3s --- @field public headPos Vec3f --- @field public heldObjLastPosition Vec3f +--- @field public lightB number +--- @field public lightG number +--- @field public lightR number --- @field public modelState integer --- @field public punchState integer +--- @field public shadeB number +--- @field public shadeG number +--- @field public shadeR number --- @field public torsoAngle Vec3s --- @field public torsoPos Vec3f --- @field public updateTorsoTime integer diff --git a/docs/lua/structs.md b/docs/lua/structs.md index d5066a2c..03b1016d 100644 --- a/docs/lua/structs.md +++ b/docs/lua/structs.md @@ -1035,8 +1035,14 @@ | headAngle | [Vec3s](structs.md#Vec3s) | read-only | | headPos | [Vec3f](structs.md#Vec3f) | read-only | | heldObjLastPosition | [Vec3f](structs.md#Vec3f) | read-only | +| lightB | `number` | | +| lightG | `number` | | +| lightR | `number` | | | modelState | `integer` | | | punchState | `integer` | | +| shadeB | `number` | | +| shadeG | `number` | | +| shadeR | `number` | | | torsoAngle | [Vec3s](structs.md#Vec3s) | read-only | | torsoPos | [Vec3f](structs.md#Vec3f) | read-only | | updateTorsoTime | `integer` | read-only | diff --git a/include/types.h b/include/types.h index 819ac393..5e0cb8c3 100644 --- a/include/types.h +++ b/include/types.h @@ -307,6 +307,12 @@ struct MarioBodyState /*????*/ u32 updateTorsoTime; /*????*/ Vec3f headPos; //u8 padding[4]; + /*????*/ f32 shadeR; // Shadow Red Value + /*????*/ f32 shadeG; // Shadow Green Value + /*????*/ f32 shadeB; // Shadow Blue Value + /*????*/ f32 lightR; // Shadow Red Value + /*????*/ f32 lightG; // Shadow Green Value + /*????*/ f32 lightB; // Shadow Blue Value }; struct OffsetSizePair diff --git a/src/game/mario.c b/src/game/mario.c index 2d5b6215..775e95f6 100644 --- a/src/game/mario.c +++ b/src/game/mario.c @@ -2291,6 +2291,14 @@ void init_single_mario(struct MarioState* m) { update_mario_info_for_cam(m); m->marioBodyState->punchState = 0; + m->marioBodyState->shadeR = 127.0f; + m->marioBodyState->shadeG = 127.0f; + m->marioBodyState->shadeB = 127.0f; + + m->marioBodyState->lightR = 255.0f; + m->marioBodyState->lightG = 255.0f; + m->marioBodyState->lightB = 255.0f; + m->marioObj->oPosX = m->pos[0]; m->marioObj->oPosY = m->pos[1]; m->marioObj->oPosZ = m->pos[2]; diff --git a/src/game/mario_misc.c b/src/game/mario_misc.c index 2a3b322f..6783a4f4 100644 --- a/src/game/mario_misc.c +++ b/src/game/mario_misc.c @@ -750,14 +750,18 @@ Gfx* geo_mirror_mario_backface_culling(s32 callContext, struct GraphNode* node, static struct PlayerColor geo_mario_get_player_color(const struct PlayerPalette *palette) { struct PlayerColor color = { 0 }; + u8 index = geo_get_processing_object_index(); + struct MarioBodyState* bodyState = &gBodyStates[index]; for (s32 part = 0; part != PLAYER_PART_MAX; ++part) { color.parts[part] = (Lights1) gdSPDefLights1( - palette->parts[part][0] / 2, - palette->parts[part][1] / 2, - palette->parts[part][2] / 2, - palette->parts[part][0], - palette->parts[part][1], - palette->parts[part][2], + // Shadow + palette->parts[part][0] * bodyState->shadeR/255.0f, + palette->parts[part][1] * bodyState->shadeG/255.0f, + palette->parts[part][2] * bodyState->shadeB/255.0f, + // Light + palette->parts[part][0] * bodyState->lightR/255.0f, + palette->parts[part][1] * bodyState->lightG/255.0f, + palette->parts[part][2] * bodyState->lightB/255.0f, 0x28, 0x28, 0x28 ); } diff --git a/src/pc/lua/smlua_cobject_autogen.c b/src/pc/lua/smlua_cobject_autogen.c index 77dc8362..8531e9b8 100644 --- a/src/pc/lua/smlua_cobject_autogen.c +++ b/src/pc/lua/smlua_cobject_autogen.c @@ -809,7 +809,7 @@ static struct LuaObjectField sMarioAnimationFields[LUA_MARIO_ANIMATION_FIELD_COU { "targetAnim", LVT_COBJECT_P, offsetof(struct MarioAnimation, targetAnim), false, LOT_ANIMATION }, }; -#define LUA_MARIO_BODY_STATE_FIELD_COUNT 14 +#define LUA_MARIO_BODY_STATE_FIELD_COUNT 20 static struct LuaObjectField sMarioBodyStateFields[LUA_MARIO_BODY_STATE_FIELD_COUNT] = { { "action", LVT_U32, offsetof(struct MarioBodyState, action), false, LOT_NONE }, { "capState", LVT_S8, offsetof(struct MarioBodyState, capState), false, LOT_NONE }, @@ -820,8 +820,14 @@ static struct LuaObjectField sMarioBodyStateFields[LUA_MARIO_BODY_STATE_FIELD_CO { "headAngle", LVT_COBJECT, offsetof(struct MarioBodyState, headAngle), true, LOT_VEC3S }, { "headPos", LVT_COBJECT, offsetof(struct MarioBodyState, headPos), true, LOT_VEC3F }, { "heldObjLastPosition", LVT_COBJECT, offsetof(struct MarioBodyState, heldObjLastPosition), true, LOT_VEC3F }, + { "lightB", LVT_F32, offsetof(struct MarioBodyState, lightB), false, LOT_NONE }, + { "lightG", LVT_F32, offsetof(struct MarioBodyState, lightG), false, LOT_NONE }, + { "lightR", LVT_F32, offsetof(struct MarioBodyState, lightR), false, LOT_NONE }, { "modelState", LVT_S16, offsetof(struct MarioBodyState, modelState), false, LOT_NONE }, { "punchState", LVT_U8, offsetof(struct MarioBodyState, punchState), false, LOT_NONE }, + { "shadeB", LVT_F32, offsetof(struct MarioBodyState, shadeB), false, LOT_NONE }, + { "shadeG", LVT_F32, offsetof(struct MarioBodyState, shadeG), false, LOT_NONE }, + { "shadeR", LVT_F32, offsetof(struct MarioBodyState, shadeR), false, LOT_NONE }, { "torsoAngle", LVT_COBJECT, offsetof(struct MarioBodyState, torsoAngle), true, LOT_VEC3S }, { "torsoPos", LVT_COBJECT, offsetof(struct MarioBodyState, torsoPos), true, LOT_VEC3F }, { "updateTorsoTime", LVT_U32, offsetof(struct MarioBodyState, updateTorsoTime), true, LOT_NONE },