From d2191a5d48b21472a2c46bec32ee9bc758abc367 Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Wed, 2 Nov 2022 00:00:38 +0100 Subject: [PATCH] Some doc on env light settings (#1307) * remove `LightSettings` struct, typedef for zapd * more decimal * fog far -> z far * `LIGHTCTX_FOGNEAR_MAX`, `LIGHTCTX_ZFAR_MAX` * name sp88,sp8C in `Environment_Update` * `EnvLightSettings.fogNear` -> `blendRateAndFogNear` and macros * A different struct for `EnvironmentContext.lightSettings` * Uniform zapd compat typedefs todos * `LIGHTCTX_` -> `ENV_` * Comment on `blendRateAndFogNear` + "fogFar" * Move fogFar~1000 comment to zFar * comment rewrite attempt * move relevant macros down Co-authored-by: fig02 --- include/functions.h | 2 +- include/regs.h | 2 +- include/z64bgcheck.h | 4 +- include/z64environment.h | 32 ++++- include/z64light.h | 7 +- include/z64scene.h | 14 +- src/code/z_demo.c | 4 +- src/code/z_kankyo.c | 133 +++++++++--------- src/code/z_lights.c | 6 +- src/code/z_play.c | 2 +- src/code/z_room.c | 2 +- src/overlays/actors/ovl_Boss_Va/z_boss_va.c | 58 ++++---- .../ovl_En_Weather_Tag/z_en_weather_tag.c | 6 +- src/overlays/actors/ovl_Fishing/z_fishing.c | 4 +- 14 files changed, 151 insertions(+), 125 deletions(-) diff --git a/include/functions.h b/include/functions.h index af21740cdd..fded37cd10 100644 --- a/include/functions.h +++ b/include/functions.h @@ -911,7 +911,7 @@ void Lights_Draw(Lights* lights, GraphicsContext* gfxCtx); void Lights_BindAll(Lights* lights, LightNode* listHead, Vec3f* vec); void LightContext_Init(PlayState* play, LightContext* lightCtx); void LightContext_SetAmbientColor(LightContext* lightCtx, u8 r, u8 g, u8 b); -void LightContext_SetFog(LightContext* lightCtx, u8 r, u8 g, u8 b, s16 fogNear, s16 fogFar); +void LightContext_SetFog(LightContext* lightCtx, u8 r, u8 g, u8 b, s16 fogNear, s16 zFar); Lights* LightContext_NewLights(LightContext* lightCtx, GraphicsContext* gfxCtx); void LightContext_InitList(PlayState* play, LightContext* lightCtx); void LightContext_DestroyList(PlayState* play, LightContext* lightCtx); diff --git a/include/regs.h b/include/regs.h index 8fe910dd86..e9f6af90e2 100644 --- a/include/regs.h +++ b/include/regs.h @@ -43,7 +43,7 @@ #define R_ENV_LIGHT2_COLOR(i) REG(6 + (i)) #define R_ENV_DISABLE_DBG REG(9) #define R_ENV_FOG_COLOR(i) REG(10 + (i)) -#define R_ENV_FOG_FAR REG(13) +#define R_ENV_Z_FAR REG(13) #define R_ENV_FOG_NEAR REG(14) #define R_ENV_TIME_SPEED_OLD REG(15) // Most likely used during development. Unused in the final game. #define R_RUN_SPEED_LIMIT REG(45) diff --git a/include/z64bgcheck.h b/include/z64bgcheck.h index 6d04483475..fa90ab78d8 100644 --- a/include/z64bgcheck.h +++ b/include/z64bgcheck.h @@ -55,7 +55,9 @@ typedef struct { /* 0x4 */ Vec3s* bgCamFuncData; // s16 data grouped in threes (ex. Vec3s), is usually of type `BgCamFuncData`, but can be a list of points of type `Vec3s` for crawlspaces } BgCamInfo; // size = 0x8 -typedef BgCamInfo CamData; // Todo: Zapd compatibility +// ZAPD compatibility typedefs +// TODO: Remove when ZAPD adds support for them +typedef BgCamInfo CamData; // The structure used for all instances of s16 data from `BgCamInfo` with the exception of crawlspaces. // See `Camera_Subj4` for Vec3s data usage in crawlspaces diff --git a/include/z64environment.h b/include/z64environment.h index 5944607b88..1aa5d7490e 100644 --- a/include/z64environment.h +++ b/include/z64environment.h @@ -139,10 +139,34 @@ typedef struct { /* 0x09 */ s8 light2Dir[3]; /* 0x0C */ u8 light2Color[3]; /* 0x0F */ u8 fogColor[3]; - /* 0x12 */ s16 fogNear; - /* 0x14 */ s16 fogFar; + /* 0x12 */ s16 fogNear; // ranges from 0-1000 (0: starts immediately, 1000: no fog), but is clamped to ENV_FOGNEAR_MAX + /* 0x14 */ s16 zFar; // Max depth (render distance) of the view as a whole. fogFar will always match zFar +} CurrentEnvLightSettings; // size = 0x16 + +// `EnvLightSettings` is very similar to `CurrentEnvLightSettings` with one key difference. +// The light settings data in the scene packs blend rate information with the fog near value. +// The blendRate determines how fast the current light settings fade to the next one +// (under LIGHT_MODE_SETTINGS, otherwise unused). + +// Get blend rate from `EnvLightSettings.blendRateAndFogNear` in 0-255 range +#define ENV_LIGHT_SETTINGS_BLEND_RATE_U8(blendRateAndFogNear) (((blendRateAndFogNear) >> 10) * 4) +#define ENV_LIGHT_SETTINGS_FOG_NEAR(blendRateAndFogNear) ((blendRateAndFogNear) & 0x3FF) + +typedef struct { + /* 0x00 */ u8 ambientColor[3]; + /* 0x03 */ s8 light1Dir[3]; + /* 0x06 */ u8 light1Color[3]; + /* 0x09 */ s8 light2Dir[3]; + /* 0x0C */ u8 light2Color[3]; + /* 0x0F */ u8 fogColor[3]; + /* 0x12 */ s16 blendRateAndFogNear; + /* 0x14 */ s16 zFar; } EnvLightSettings; // size = 0x16 +// ZAPD compatibility typedefs +// TODO: Remove when ZAPD adds support for them +typedef EnvLightSettings LightSettings; + typedef struct { /* 0x00 */ char unk_00[0x02]; /* 0x02 */ u16 sceneTimeSpeed; // time speed value from the scene file @@ -178,7 +202,7 @@ typedef struct { /* 0x92 */ s16 adjLight1Color[3]; /* 0x98 */ s16 adjFogColor[3]; /* 0x9E */ s16 adjFogNear; - /* 0xA0 */ s16 adjFogFar; + /* 0xA0 */ s16 adjZFar; /* 0xA2 */ char unk_A2[0x06]; /* 0xA8 */ Vec3s windDirection; /* 0xB0 */ f32 windSpeed; @@ -188,7 +212,7 @@ typedef struct { /* 0xBD */ u8 lightSetting; // only used with `LIGHT_MODE_SETTINGS` or on override /* 0xBE */ u8 prevLightSetting; /* 0xBF */ u8 lightSettingOverride; - /* 0xC0 */ EnvLightSettings lightSettings; // settings for the currently "live" lights + /* 0xC0 */ CurrentEnvLightSettings lightSettings; // settings for the currently "live" lights /* 0xD6 */ u16 lightBlendRateOverride; /* 0xD8 */ f32 lightBlend; // only used with `LIGHT_MODE_SETTINGS` or on setting override /* 0xDC */ u8 lightBlendOverride; diff --git a/include/z64light.h b/include/z64light.h index 639490022a..7e11dd32c8 100644 --- a/include/z64light.h +++ b/include/z64light.h @@ -43,12 +43,15 @@ typedef struct LightNode { /* 0x8 */ struct LightNode* next; } LightNode; // size = 0xC +#define ENV_FOGNEAR_MAX 996 +#define ENV_ZFAR_MAX 12800 + typedef struct { /* 0x0 */ LightNode* listHead; /* 0x4 */ u8 ambientColor[3]; /* 0x7 */ u8 fogColor[3]; - /* 0xA */ s16 fogNear; // how close until fog starts taking effect. range 0 - 1000 - /* 0xC */ s16 fogFar; // how far until fog starts to saturate. range 0 - 1000 + /* 0xA */ s16 fogNear; // how close until fog starts taking effect. range 0 - ENV_FOGNEAR_MAX + /* 0xC */ s16 zFar; // draw distance. range 0 - ENV_ZFAR_MAX } LightContext; // size = 0x10 typedef enum { diff --git a/include/z64scene.h b/include/z64scene.h index fd12ee3c0b..043ac88479 100644 --- a/include/z64scene.h +++ b/include/z64scene.h @@ -45,17 +45,6 @@ typedef struct { // TODO: ZAPD Compatibility typedef Spawn EntranceEntry; -typedef struct { - /* 0x00 */ u8 ambientColor[3]; - /* 0x03 */ s8 diffuseDir1[3]; - /* 0x06 */ u8 diffuseColor1[3]; - /* 0x09 */ s8 diffuseDir2[3]; - /* 0x0C */ u8 diffuseColor2[3]; - /* 0x0F */ u8 fogColor[3]; - /* 0x12 */ u16 fogNear; - /* 0x14 */ u16 fogFar; -} LightSettings; // size = 0x16 - typedef struct { /* 0x00 */ u8 count; // number of points in the path /* 0x04 */ Vec3s* points; // Segment Address to the array of points @@ -157,7 +146,8 @@ typedef union { RoomShapeCullable cullable; } RoomShape; // "Ground Shape" -// TODO update ZAPD +// ZAPD compatibility typedefs +// TODO: Remove when ZAPD adds support for them typedef RoomShapeDListsEntry PolygonDlist; typedef RoomShapeNormal PolygonType0; typedef RoomShapeImageSingle MeshHeader1Single; diff --git a/src/code/z_demo.c b/src/code/z_demo.c index de50eeaa33..4a7f344ab6 100644 --- a/src/code/z_demo.c +++ b/src/code/z_demo.c @@ -248,8 +248,8 @@ void func_80064824(PlayState* play, CutsceneContext* csCtx, CsCmdBase* cmd) { } break; case 6: - if (play->envCtx.adjFogFar < 12800) { - play->envCtx.adjFogFar += 35; + if (play->envCtx.adjZFar < ENV_ZFAR_MAX) { + play->envCtx.adjZFar += 35; } break; case 7: diff --git a/src/code/z_kankyo.c b/src/code/z_kankyo.c index 1b6ce5b4c3..dee1f13e94 100644 --- a/src/code/z_kankyo.c +++ b/src/code/z_kankyo.c @@ -319,7 +319,7 @@ void Environment_Init(PlayState* play2, EnvironmentContext* envCtx, s32 unused) envCtx->adjAmbientColor[0] = envCtx->adjAmbientColor[1] = envCtx->adjAmbientColor[2] = envCtx->adjLight1Color[0] = envCtx->adjLight1Color[1] = envCtx->adjLight1Color[2] = envCtx->adjFogColor[0] = envCtx->adjFogColor[1] = - envCtx->adjFogColor[2] = envCtx->adjFogNear = envCtx->adjFogFar = 0; + envCtx->adjFogColor[2] = envCtx->adjFogNear = envCtx->adjZFar = 0; envCtx->sunPos.x = -(Math_SinS(((void)0, gSaveContext.dayTime) - CLOCK_TIME(12, 0)) * 120.0f) * 25.0f; envCtx->sunPos.y = +(Math_CosS(((void)0, gSaveContext.dayTime) - CLOCK_TIME(12, 0)) * 120.0f) * 25.0f; @@ -873,8 +873,8 @@ void Environment_UpdateRain(PlayState* play); void Environment_Update(PlayState* play, EnvironmentContext* envCtx, LightContext* lightCtx, PauseContext* pauseCtx, MessageContext* msgCtx, GameOverContext* gameOverCtx, GraphicsContext* gfxCtx) { - f32 sp8C; - f32 sp88 = 0.0f; + f32 timeChangeBlend; + f32 configChangeBlend = 0.0f; u16 i; u16 j; u16 time; @@ -986,16 +986,18 @@ void Environment_Update(PlayState* play, EnvironmentContext* envCtx, LightContex u8 blend8[2]; s16 blend16[2]; - sp8C = Environment_LerpWeight(sTimeBasedLightConfigs[envCtx->lightConfig][i].endTime, - sTimeBasedLightConfigs[envCtx->lightConfig][i].startTime, - ((void)0, gSaveContext.skyboxTime)); + timeChangeBlend = + Environment_LerpWeight(sTimeBasedLightConfigs[envCtx->lightConfig][i].endTime, + sTimeBasedLightConfigs[envCtx->lightConfig][i].startTime, + ((void)0, gSaveContext.skyboxTime)); sSandstormColorIndex = sTimeBasedLightConfigs[envCtx->lightConfig][i].lightSetting & 3; sNextSandstormColorIndex = sTimeBasedLightConfigs[envCtx->lightConfig][i].nextLightSetting & 3; - sSandstormLerpScale = sp8C; + sSandstormLerpScale = timeChangeBlend; if (envCtx->changeLightEnabled) { - sp88 = ((f32)envCtx->changeDuration - envCtx->changeLightTimer) / envCtx->changeDuration; + configChangeBlend = + ((f32)envCtx->changeDuration - envCtx->changeLightTimer) / envCtx->changeDuration; envCtx->changeLightTimer--; if (envCtx->changeLightTimer <= 0) { @@ -1011,15 +1013,15 @@ void Environment_Update(PlayState* play, EnvironmentContext* envCtx, LightContex .ambientColor[j], lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].nextLightSetting] .ambientColor[j], - sp8C); + timeChangeBlend); blend8[1] = LERP( lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].lightSetting] .ambientColor[j], lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i] .nextLightSetting] .ambientColor[j], - sp8C); - *(envCtx->lightSettings.ambientColor + j) = LERP(blend8[0], blend8[1], sp88); + timeChangeBlend); + *(envCtx->lightSettings.ambientColor + j) = LERP(blend8[0], blend8[1], configChangeBlend); } // set light1 direction for the sun @@ -1042,15 +1044,15 @@ void Environment_Update(PlayState* play, EnvironmentContext* envCtx, LightContex .light1Color[j], lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].nextLightSetting] .light1Color[j], - sp8C); + timeChangeBlend); blend8[1] = LERP( lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].lightSetting] .light1Color[j], lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i] .nextLightSetting] .light1Color[j], - sp8C); - *(envCtx->lightSettings.light1Color + j) = LERP(blend8[0], blend8[1], sp88); + timeChangeBlend); + *(envCtx->lightSettings.light1Color + j) = LERP(blend8[0], blend8[1], configChangeBlend); // blend light2Color blend8[0] = @@ -1058,15 +1060,15 @@ void Environment_Update(PlayState* play, EnvironmentContext* envCtx, LightContex .light2Color[j], lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].nextLightSetting] .light2Color[j], - sp8C); + timeChangeBlend); blend8[1] = LERP( lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].lightSetting] .light2Color[j], lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i] .nextLightSetting] .light2Color[j], - sp8C); - *(envCtx->lightSettings.light2Color + j) = LERP(blend8[0], blend8[1], sp88); + timeChangeBlend); + *(envCtx->lightSettings.light2Color + j) = LERP(blend8[0], blend8[1], configChangeBlend); } // blend fogColor @@ -1076,47 +1078,49 @@ void Environment_Update(PlayState* play, EnvironmentContext* envCtx, LightContex .fogColor[j], lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].nextLightSetting] .fogColor[j], - sp8C); + timeChangeBlend); blend8[1] = LERP( lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].lightSetting] .fogColor[j], lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i] .nextLightSetting] .fogColor[j], - sp8C); - *(envCtx->lightSettings.fogColor + j) = LERP(blend8[0], blend8[1], sp88); + timeChangeBlend); + *(envCtx->lightSettings.fogColor + j) = LERP(blend8[0], blend8[1], configChangeBlend); } blend16[0] = LERP16( - (lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].lightSetting].fogNear & - 0x3FF), - (lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].nextLightSetting] - .fogNear & - 0x3FF), - sp8C); + ENV_LIGHT_SETTINGS_FOG_NEAR( + lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].lightSetting] + .blendRateAndFogNear), + ENV_LIGHT_SETTINGS_FOG_NEAR( + lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].nextLightSetting] + .blendRateAndFogNear), + timeChangeBlend); blend16[1] = LERP16( - lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].lightSetting] - .fogNear & - 0x3FF, - lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].nextLightSetting] - .fogNear & - 0x3FF, - sp8C); + ENV_LIGHT_SETTINGS_FOG_NEAR( + lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].lightSetting] + .blendRateAndFogNear), + ENV_LIGHT_SETTINGS_FOG_NEAR( + lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i] + .nextLightSetting] + .blendRateAndFogNear), + timeChangeBlend); - envCtx->lightSettings.fogNear = LERP16(blend16[0], blend16[1], sp88); + envCtx->lightSettings.fogNear = LERP16(blend16[0], blend16[1], configChangeBlend); blend16[0] = LERP16( - lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].lightSetting].fogFar, - lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].nextLightSetting].fogFar, - sp8C); + lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].lightSetting].zFar, + lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].nextLightSetting].zFar, + timeChangeBlend); blend16[1] = LERP16( lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].lightSetting] - .fogFar, + .zFar, lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].nextLightSetting] - .fogFar, - sp8C); + .zFar, + timeChangeBlend); - envCtx->lightSettings.fogFar = LERP16(blend16[0], blend16[1], sp88); + envCtx->lightSettings.zFar = LERP16(blend16[0], blend16[1], configChangeBlend); if (sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].nextLightSetting >= envCtx->numLightSettings) { @@ -1142,11 +1146,13 @@ void Environment_Update(PlayState* play, EnvironmentContext* envCtx, LightContex envCtx->lightSettings.fogColor[i] = lightSettingsList[envCtx->lightSetting].fogColor[i]; } - envCtx->lightSettings.fogNear = lightSettingsList[envCtx->lightSetting].fogNear & 0x3FF; - envCtx->lightSettings.fogFar = lightSettingsList[envCtx->lightSetting].fogFar; + envCtx->lightSettings.fogNear = + ENV_LIGHT_SETTINGS_FOG_NEAR(lightSettingsList[envCtx->lightSetting].blendRateAndFogNear); + envCtx->lightSettings.zFar = lightSettingsList[envCtx->lightSetting].zFar; envCtx->lightBlend = 1.0f; } else { - u8 blendRate = (lightSettingsList[envCtx->lightSetting].fogNear >> 0xA) * 4; + u8 blendRate = + ENV_LIGHT_SETTINGS_BLEND_RATE_U8(lightSettingsList[envCtx->lightSetting].blendRateAndFogNear); if (blendRate == 0) { blendRate++; @@ -1184,12 +1190,13 @@ void Environment_Update(PlayState* play, EnvironmentContext* envCtx, LightContex LERP(lightSettingsList[envCtx->prevLightSetting].fogColor[i], lightSettingsList[envCtx->lightSetting].fogColor[i], envCtx->lightBlend); } - envCtx->lightSettings.fogNear = - LERP16(lightSettingsList[envCtx->prevLightSetting].fogNear & 0x3FF, - lightSettingsList[envCtx->lightSetting].fogNear & 0x3FF, envCtx->lightBlend); - envCtx->lightSettings.fogFar = - LERP16(lightSettingsList[envCtx->prevLightSetting].fogFar, - lightSettingsList[envCtx->lightSetting].fogFar, envCtx->lightBlend); + envCtx->lightSettings.fogNear = LERP16( + ENV_LIGHT_SETTINGS_FOG_NEAR(lightSettingsList[envCtx->prevLightSetting].blendRateAndFogNear), + ENV_LIGHT_SETTINGS_FOG_NEAR(lightSettingsList[envCtx->lightSetting].blendRateAndFogNear), + envCtx->lightBlend); + envCtx->lightSettings.zFar = + LERP16(lightSettingsList[envCtx->prevLightSetting].zFar, + lightSettingsList[envCtx->lightSetting].zFar, envCtx->lightBlend); } if (envCtx->lightSetting >= envCtx->numLightSettings) { @@ -1254,18 +1261,18 @@ void Environment_Update(PlayState* play, EnvironmentContext* envCtx, LightContex // Adjust fog near and far if necessary adjustment = envCtx->lightSettings.fogNear + envCtx->adjFogNear; - if (adjustment <= 996) { + if (adjustment <= ENV_FOGNEAR_MAX) { lightCtx->fogNear = adjustment; } else { - lightCtx->fogNear = 996; + lightCtx->fogNear = ENV_FOGNEAR_MAX; } - adjustment = envCtx->lightSettings.fogFar + envCtx->adjFogFar; + adjustment = envCtx->lightSettings.zFar + envCtx->adjZFar; - if (adjustment <= 12800) { - lightCtx->fogFar = adjustment; + if (adjustment <= ENV_ZFAR_MAX) { + lightCtx->zFar = adjustment; } else { - lightCtx->fogFar = 12800; + lightCtx->zFar = ENV_ZFAR_MAX; } // When environment debug is enabled, various environment related variables can be configured via the reg editor @@ -1286,7 +1293,7 @@ void Environment_Update(PlayState* play, EnvironmentContext* envCtx, LightContex R_ENV_FOG_COLOR(1) = lightCtx->fogColor[1]; R_ENV_FOG_COLOR(2) = lightCtx->fogColor[2]; - R_ENV_FOG_FAR = lightCtx->fogFar; + R_ENV_Z_FAR = lightCtx->zFar; R_ENV_FOG_NEAR = lightCtx->fogNear; R_ENV_LIGHT1_DIR(0) = envCtx->dirLight1.params.dir.x; @@ -1317,7 +1324,7 @@ void Environment_Update(PlayState* play, EnvironmentContext* envCtx, LightContex lightCtx->fogColor[1] = R_ENV_FOG_COLOR(1); lightCtx->fogColor[2] = R_ENV_FOG_COLOR(2); lightCtx->fogNear = R_ENV_FOG_NEAR; - lightCtx->fogFar = R_ENV_FOG_FAR; + lightCtx->zFar = R_ENV_Z_FAR; if (cREG(14)) { R_ENV_LIGHT1_DIR(0) = Math_CosS(cREG(10)) * Math_CosS(cREG(11)) * 120.0f; @@ -1593,7 +1600,7 @@ void Environment_DrawLensFlare(PlayState* play, EnvironmentContext* envCtx, View alpha = alpha * lensFlareAlphas[i]; alpha = CLAMP_MIN(alpha, 0.0f); - fogInfluence = (996 - play->lightCtx.fogNear) / 50.0f; + fogInfluence = (ENV_FOGNEAR_MAX - play->lightCtx.fogNear) / 50.0f; fogInfluence = CLAMP_MAX(fogInfluence, 1.0f); @@ -1640,7 +1647,7 @@ void Environment_DrawLensFlare(PlayState* play, EnvironmentContext* envCtx, View alpha = alpha * glareStrength; alpha = CLAMP_MIN(alpha, 0.0f); - fogInfluence = (996 - play->lightCtx.fogNear) / 50.0f; + fogInfluence = (ENV_FOGNEAR_MAX - play->lightCtx.fogNear) / 50.0f; fogInfluence = CLAMP_MAX(fogInfluence, 1.0f); @@ -2233,8 +2240,8 @@ void Environment_FadeInGameOverLights(PlayState* play) { play->envCtx.adjFogColor[i] = -255; } - if (play->envCtx.lightSettings.fogFar + play->envCtx.adjFogFar > 900) { - play->envCtx.adjFogFar -= 100; + if (play->envCtx.lightSettings.zFar + play->envCtx.adjZFar > 900) { + play->envCtx.adjZFar -= 100; } if (play->envCtx.lightSettings.fogNear + play->envCtx.adjFogNear > 950) { @@ -2277,7 +2284,7 @@ void Environment_FadeOutGameOverLights(PlayState* play) { Math_SmoothStepToS(&play->envCtx.adjLight1Color[i], 0, 5, 12, 1); play->envCtx.adjFogColor[i] = 0; } - play->envCtx.adjFogFar = 0; + play->envCtx.adjZFar = 0; play->envCtx.adjFogNear = 0; } else { play->envCtx.fillScreen = true; diff --git a/src/code/z_lights.c b/src/code/z_lights.c index 4d91bf4620..b230100bce 100644 --- a/src/code/z_lights.c +++ b/src/code/z_lights.c @@ -195,7 +195,7 @@ s32 Lights_FreeNode(LightNode* light) { void LightContext_Init(PlayState* play, LightContext* lightCtx) { LightContext_InitList(play, lightCtx); LightContext_SetAmbientColor(lightCtx, 80, 80, 80); - LightContext_SetFog(lightCtx, 0, 0, 0, 996, 12800); + LightContext_SetFog(lightCtx, 0, 0, 0, ENV_FOGNEAR_MAX, ENV_ZFAR_MAX); bzero(&sLightsBuffer, sizeof(sLightsBuffer)); } @@ -205,12 +205,12 @@ void LightContext_SetAmbientColor(LightContext* lightCtx, u8 r, u8 g, u8 b) { lightCtx->ambientColor[2] = b; } -void LightContext_SetFog(LightContext* lightCtx, u8 r, u8 g, u8 b, s16 fogNear, s16 fogFar) { +void LightContext_SetFog(LightContext* lightCtx, u8 r, u8 g, u8 b, s16 fogNear, s16 zFar) { lightCtx->fogColor[0] = r; lightCtx->fogColor[1] = g; lightCtx->fogColor[2] = b; lightCtx->fogNear = fogNear; - lightCtx->fogFar = fogFar; + lightCtx->zFar = zFar; } /** diff --git a/src/code/z_play.c b/src/code/z_play.c index f768d7a9d8..64a7387b52 100644 --- a/src/code/z_play.c +++ b/src/code/z_play.c @@ -1051,7 +1051,7 @@ void Play_Draw(PlayState* this) { POLY_OPA_DISP = Play_SetFog(this, POLY_OPA_DISP); POLY_XLU_DISP = Play_SetFog(this, POLY_XLU_DISP); - View_SetPerspective(&this->view, this->view.fovy, this->view.zNear, this->lightCtx.fogFar); + View_SetPerspective(&this->view, this->view.fovy, this->view.zNear, this->lightCtx.zFar); View_Apply(&this->view, VIEW_ALL); // The billboard matrix temporarily stores the viewing matrix diff --git a/src/code/z_room.c b/src/code/z_room.c index 8447a04605..c43a093cfc 100644 --- a/src/code/z_room.c +++ b/src/code/z_room.c @@ -153,7 +153,7 @@ void Room_DrawCullable(PlayState* play, Room* room, u32 flags) { entryBoundsNearZ = projectedPos.z - roomShapeCullableEntry->boundsSphereRadius; // If the entry bounding sphere isn't fully beyond the rendered depth range - if (entryBoundsNearZ < play->lightCtx.fogFar) { + if (entryBoundsNearZ < play->lightCtx.zFar) { // This entry will be rendered insert->entry = roomShapeCullableEntry; diff --git a/src/overlays/actors/ovl_Boss_Va/z_boss_va.c b/src/overlays/actors/ovl_Boss_Va/z_boss_va.c index 6f753d732c..c99958ee2e 100644 --- a/src/overlays/actors/ovl_Boss_Va/z_boss_va.c +++ b/src/overlays/actors/ovl_Boss_Va/z_boss_va.c @@ -507,33 +507,33 @@ void BossVa_Tumor(PlayState* play, BossVa* this, s32 count, s16 scale, f32 xzSpr } void BossVa_SetSparkEnv(PlayState* play) { - play->envCtx.adjAmbientColor[0] = 0xA; - play->envCtx.adjAmbientColor[1] = 0xA; - play->envCtx.adjAmbientColor[2] = 0xA; - play->envCtx.adjLight1Color[0] = 0x73; - play->envCtx.adjLight1Color[1] = 0x41; - play->envCtx.adjLight1Color[2] = 0x64; - play->envCtx.adjFogColor[0] = 0x78; - play->envCtx.adjFogColor[1] = 0x78; - play->envCtx.adjFogColor[2] = 0x46; + play->envCtx.adjAmbientColor[0] = 10; + play->envCtx.adjAmbientColor[1] = 10; + play->envCtx.adjAmbientColor[2] = 10; + play->envCtx.adjLight1Color[0] = 115; + play->envCtx.adjLight1Color[1] = 65; + play->envCtx.adjLight1Color[2] = 100; + play->envCtx.adjFogColor[0] = 120; + play->envCtx.adjFogColor[1] = 120; + play->envCtx.adjFogColor[2] = 70; } void BossVa_SetDeathEnv(PlayState* play) { - play->envCtx.adjFogColor[0] = 0xDC; - play->envCtx.adjFogColor[1] = 0xDC; - play->envCtx.adjFogColor[2] = 0x96; - play->envCtx.adjFogNear = -0x3E8; - play->envCtx.adjFogFar = -0x384; - play->envCtx.adjAmbientColor[0] = 0xC8; - play->envCtx.adjAmbientColor[1] = 0xC8; - play->envCtx.adjAmbientColor[2] = 0xC8; - play->envCtx.adjLight1Color[0] = 0xD7; - play->envCtx.adjLight1Color[1] = 0xA5; - play->envCtx.adjLight1Color[2] = 0xC8; - play->envCtx.screenFillColor[0] = 0xDC; - play->envCtx.screenFillColor[1] = 0xDC; - play->envCtx.screenFillColor[2] = 0x96; - play->envCtx.screenFillColor[3] = 0x64; + play->envCtx.adjFogColor[0] = 220; + play->envCtx.adjFogColor[1] = 220; + play->envCtx.adjFogColor[2] = 150; + play->envCtx.adjFogNear = -1000; + play->envCtx.adjZFar = -900; + play->envCtx.adjAmbientColor[0] = 200; + play->envCtx.adjAmbientColor[1] = 200; + play->envCtx.adjAmbientColor[2] = 200; + play->envCtx.adjLight1Color[0] = 215; + play->envCtx.adjLight1Color[1] = 165; + play->envCtx.adjLight1Color[2] = 200; + play->envCtx.screenFillColor[0] = 220; + play->envCtx.screenFillColor[1] = 220; + play->envCtx.screenFillColor[2] = 150; + play->envCtx.screenFillColor[3] = 100; } EnBoom* BossVa_FindBoomerang(PlayState* play) { @@ -3185,16 +3185,16 @@ void BossVa_Draw(Actor* thisx, PlayState* play) { switch (this->actor.params) { case BOSSVA_BODY: if (play->envCtx.adjFogNear != 0) { - play->envCtx.adjFogNear += 0x15E; + play->envCtx.adjFogNear += 350; if (play->envCtx.adjFogNear > 0) { play->envCtx.adjFogNear = 0; } } - if (play->envCtx.adjFogFar != 0) { - play->envCtx.adjFogFar += 0x15E; - if (play->envCtx.adjFogFar > 0) { - play->envCtx.adjFogFar = 0; + if (play->envCtx.adjZFar != 0) { + play->envCtx.adjZFar += 350; + if (play->envCtx.adjZFar > 0) { + play->envCtx.adjZFar = 0; } } diff --git a/src/overlays/actors/ovl_En_Weather_Tag/z_en_weather_tag.c b/src/overlays/actors/ovl_En_Weather_Tag/z_en_weather_tag.c index 3786f85b37..f391631c92 100644 --- a/src/overlays/actors/ovl_En_Weather_Tag/z_en_weather_tag.c +++ b/src/overlays/actors/ovl_En_Weather_Tag/z_en_weather_tag.c @@ -291,11 +291,11 @@ void EnWeatherTag_SetSandstormIntensity(EnWeatherTag* this, PlayState* play) { Player* player = GET_PLAYER(play); if (Actor_WorldDistXZToActor(&player->actor, &this->actor) < WEATHER_TAG_RANGE100(this->actor.params)) { - Math_SmoothStepToS(&play->envCtx.adjFogNear, -0x50, 1, 2, 1); - Math_SmoothStepToS(&play->envCtx.adjFogFar, -0x7D0, 1, 50, 1); + Math_SmoothStepToS(&play->envCtx.adjFogNear, -80, 1, 2, 1); + Math_SmoothStepToS(&play->envCtx.adjZFar, -2000, 1, 50, 1); } else { Math_SmoothStepToS(&play->envCtx.adjFogNear, 0, 1, 1, 1); - Math_SmoothStepToS(&play->envCtx.adjFogFar, 0, 1, 25, 1); + Math_SmoothStepToS(&play->envCtx.adjZFar, 0, 1, 25, 1); } } diff --git a/src/overlays/actors/ovl_Fishing/z_fishing.c b/src/overlays/actors/ovl_Fishing/z_fishing.c index 2231c310bf..ac33818ddc 100644 --- a/src/overlays/actors/ovl_Fishing/z_fishing.c +++ b/src/overlays/actors/ovl_Fishing/z_fishing.c @@ -5516,9 +5516,9 @@ void Fishing_UpdateOwner(Actor* thisx, PlayState* play2) { if (sSubCamEye.y <= (WATER_SURFACE_Y(play) + 1.0f)) { Environment_EnableUnderwaterLights(play, 1); if (D_80B7E076 != 0) { - play->envCtx.adjFogNear = -0xB2; + play->envCtx.adjFogNear = -178; } else { - play->envCtx.adjFogNear = -0x2E; + play->envCtx.adjFogNear = -46; } } else { Environment_EnableUnderwaterLights(play, 0);