mirror of
https://github.com/zeldaret/oot.git
synced 2025-07-05 07:24:34 +00:00
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 <fig02srl@gmail.com>
This commit is contained in:
parent
451e855dbc
commit
d2191a5d48
14 changed files with 151 additions and 125 deletions
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue