1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-29 03:34:07 +00:00

Reduce hardcoded constants in Lights_GlowCheck, some more comments on the CPU driven depth test and z-buffer value conversion (#1506)

This commit is contained in:
Tharo 2023-07-04 23:37:31 +01:00 committed by GitHub
parent 47ffb59f68
commit 54638f9768
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 10 deletions

View file

@ -12,13 +12,14 @@ typedef enum {
} LightningBoltState; } LightningBoltState;
typedef struct { typedef struct {
/* 0x00 */ s32 mantissa; /* 0x00 */ s32 mantissaShift; // shift applied to the mantissa of the z buffer value
/* 0x04 */ s32 exponent; /* 0x04 */ s32 base; // 15.3 fixed-point base value for the exponent
} ZBufValConversionEntry; // size = 0x8 } ZBufValConversionEntry; // size = 0x8
// This table needs as many values as there are values for the 3-bit exponent
ZBufValConversionEntry sZBufValConversionTable[1 << 3] = { ZBufValConversionEntry sZBufValConversionTable[1 << 3] = {
{ 6, 0x00000 }, { 5, 0x20000 }, { 4, 0x30000 }, { 3, 0x38000 }, { 6, 0x0000 << 3 }, { 5, 0x4000 << 3 }, { 4, 0x6000 << 3 }, { 3, 0x7000 << 3 },
{ 2, 0x3C000 }, { 1, 0x3E000 }, { 0, 0x3F000 }, { 0, 0x3F800 }, { 2, 0x7800 << 3 }, { 1, 0x7C00 << 3 }, { 0, 0x7E00 << 3 }, { 0, 0x7F00 << 3 },
}; };
u8 gWeatherMode = WEATHER_MODE_CLEAR; // "E_wether_flg" u8 gWeatherMode = WEATHER_MODE_CLEAR; // "E_wether_flg"
@ -225,9 +226,9 @@ u16 sSandstormScroll;
* 4: dz value (unused) * 4: dz value (unused)
*/ */
s32 Environment_ZBufValToFixedPoint(s32 zBufferVal) { s32 Environment_ZBufValToFixedPoint(s32 zBufferVal) {
// base[exp] + mantissa << shift[exp] // base[exp] + (mantissa << shift[exp])
s32 ret = (ZBUFVAL_MANTISSA(zBufferVal) << sZBufValConversionTable[ZBUFVAL_EXPONENT(zBufferVal)].mantissa) + s32 ret = (ZBUFVAL_MANTISSA(zBufferVal) << sZBufValConversionTable[ZBUFVAL_EXPONENT(zBufferVal)].mantissaShift) +
sZBufValConversionTable[ZBUFVAL_EXPONENT(zBufferVal)].exponent; sZBufValConversionTable[ZBUFVAL_EXPONENT(zBufferVal)].base;
return ret; return ret;
} }

View file

@ -339,11 +339,18 @@ void Lights_GlowCheck(PlayState* play) {
wY = multDest.y * cappedInvWDest; wY = multDest.y * cappedInvWDest;
if ((multDest.z > 1.0f) && (fabsf(wX) < 1.0f) && (fabsf(wY) < 1.0f)) { if ((multDest.z > 1.0f) && (fabsf(wX) < 1.0f) && (fabsf(wY) < 1.0f)) {
wZ = (s32)((multDest.z * cappedInvWDest) * 16352.0f) + 16352; // Compute screen z value assuming the viewport scale and translation both have value G_MAXZ / 2
zBuf = gZBuffer[(s32)((wY * -120.0f) + 120.0f)][(s32)((wX * 160.0f) + 160.0f)] * 4; // The multiplication by 32 follows from how the RSP microcode computes the screen z value.
wZ = (s32)((multDest.z * cappedInvWDest) * ((G_MAXZ / 2) * 32)) + ((G_MAXZ / 2) * 32);
// Obtain the z-buffer value for the screen pixel corresponding to the center of the glow.
zBuf = gZBuffer[(s32)((wY * -(SCREEN_HEIGHT / 2)) + (SCREEN_HEIGHT / 2))]
[(s32)((wX * (SCREEN_WIDTH / 2)) + (SCREEN_WIDTH / 2))]
<< 2;
if (1) {} if (1) {}
if (1) {} if (1) {}
// Compare the computed screen z value to the integer part of the z-buffer value in fixed point. If
// it is less than the value from the z-buffer the depth test passes and the glow can draw.
if (wZ < (Environment_ZBufValToFixedPoint(zBuf) >> 3)) { if (wZ < (Environment_ZBufValToFixedPoint(zBuf) >> 3)) {
params->drawGlow = true; params->drawGlow = true;
} }