diff options
| author | Archez <Archez@users.noreply.github.com> | 2024-02-10 19:53:19 -0500 |
|---|---|---|
| committer | Garrett Cox <garrettjcox@gmail.com> | 2024-05-22 09:04:59 -0500 |
| commit | 32caecabfc442c9f3aeec8d213449e15c30bd422 (patch) | |
| tree | 78622fb5e3894b892beb93a2d33b724cbf5093a8 /mm/src/code | |
| parent | fb2f6fd67b3f7f24965ddc920b97d9188eb2e9c5 (diff) | |
read proper depth values from the renderer (#124)
Diffstat (limited to 'mm/src/code')
| -rw-r--r-- | mm/src/code/sys_cfb.c | 9 | ||||
| -rw-r--r-- | mm/src/code/z_kankyo.c | 4 | ||||
| -rw-r--r-- | mm/src/code/z_lights.c | 29 |
3 files changed, 41 insertions, 1 deletions
diff --git a/mm/src/code/sys_cfb.c b/mm/src/code/sys_cfb.c index 98a99ceba..66350d666 100644 --- a/mm/src/code/sys_cfb.c +++ b/mm/src/code/sys_cfb.c @@ -121,6 +121,9 @@ void* SysCfb_GetWorkBuffer(void) { } u16 SysCfb_GetZBufferPixel(s32 x, s32 y) { + // 2S2H [Port] Get the zbuffer pixel value from the renderer directly + return OTRGetPixelDepth(x, y); +#if 0 u16* zBuff = SysCfb_GetZBuffer(); u16 val; @@ -130,8 +133,12 @@ u16 SysCfb_GetZBufferPixel(s32 x, s32 y) { val = 0; } return val; +#endif } s32 SysCfb_GetZBufferInt(s32 x, s32 y) { - return Environment_ZBufValToFixedPoint(SysCfb_GetZBufferPixel(x, y) << 2) >> 3; + // 2S2H [Port] The value from the renderer does not need to be converted to a fixed point + // Simply shifting is all we need to get the proper value + return SysCfb_GetZBufferPixel(x, y) >> 1; + // return Environment_ZBufValToFixedPoint(SysCfb_GetZBufferPixel(x, y) << 2) >> 3; } diff --git a/mm/src/code/z_kankyo.c b/mm/src/code/z_kankyo.c index e2255504a..d2b120555 100644 --- a/mm/src/code/z_kankyo.c +++ b/mm/src/code/z_kankyo.c @@ -490,6 +490,10 @@ void Environment_JumpForwardInTime(void); void Environment_GraphCallback(GraphicsContext* gfxCtx, void* arg) { PlayState* play = (PlayState*)arg; + // 2S2H [Port] Batch all the coordinates that need their depth checked by calling prepare + OTRGetPixelDepthPrepare(sSunDepthTestX, sSunDepthTestY); + Lights_GlowCheckPrepare(play); + sSunScreenDepth = SysCfb_GetZBufferPixel(sSunDepthTestX, sSunDepthTestY); Lights_GlowCheck(play); } diff --git a/mm/src/code/z_lights.c b/mm/src/code/z_lights.c index 9936a0c2d..b60090d06 100644 --- a/mm/src/code/z_lights.c +++ b/mm/src/code/z_lights.c @@ -372,6 +372,35 @@ Lights* Lights_New(GraphicsContext* gfxCtx, u8 ambientR, u8 ambientG, u8 ambient return lights; } +// 2S2H [Port] Similar to Lights_GlowCheck, but only submits the coordinates to the depth prepare +// for batching and then will be read after when Lights_GlowCheck is called +void Lights_GlowCheckPrepare(PlayState* play) { + LightNode* light = play->lightCtx.listHead; + + while (light != NULL) { + LightPoint* params = &light->info->params.point; + + if (light->info->type == LIGHT_POINT_GLOW) { + Vec3f worldPos; + Vec3f projectedPos; + f32 invW; + + worldPos.x = params->x; + worldPos.y = params->y; + worldPos.z = params->z; + Actor_GetProjectedPos(play, &worldPos, &projectedPos, &invW); + + if ((projectedPos.z > 1) && (fabsf(projectedPos.x * invW) < 1) && (fabsf(projectedPos.y * invW) < 1)) { + s32 screenPosX = PROJECTED_TO_SCREEN_X(projectedPos, invW); + s32 screenPosY = PROJECTED_TO_SCREEN_Y(projectedPos, invW); + OTRGetPixelDepthPrepare(screenPosX, screenPosY); + } + } + + light = light->next; + } +} + void Lights_GlowCheck(PlayState* play) { LightNode* light = play->lightCtx.listHead; |
