From b1ef06fcd15627dc4169ff809bb7fae943da1463 Mon Sep 17 00:00:00 2001 From: thecozies <79979276+thecozies@users.noreply.github.com> Date: Sat, 23 Sep 2023 15:05:30 -0500 Subject: [PATCH] remap scale with fov and avoid copy when world scale is 1 --- src/game/rendering_graph_node.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/game/rendering_graph_node.c b/src/game/rendering_graph_node.c index 295d6c4e..18c5c533 100644 --- a/src/game/rendering_graph_node.c +++ b/src/game/rendering_graph_node.c @@ -576,8 +576,11 @@ void geo_process_perspective(struct GraphNodePerspective *node) { #ifdef VERTICAL_CULLING node->halfFovVertical = tans(vHalfFov); #endif - - guPerspective(mtx, &perspNorm, node->fov, sAspectRatio, node->near / WORLD_SCALE, node->far / WORLD_SCALE, 1.0f); + + // With low fovs, coordinate overflow can occur more easily. This slightly reduces precision only while zoomed in. + f32 scale = node->fov < 28.0f ? remap(MAX(node->fov, 15), 15, 28, 0.5f, 1.0f): 1.0f; + guPerspective(mtx, &perspNorm, node->fov, sAspectRatio, node->near / WORLD_SCALE, node->far / WORLD_SCALE, scale); + gSPPerspNormalize(gDisplayListHead++, perspNorm); gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(mtx), G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH); @@ -697,6 +700,7 @@ void geo_process_camera(struct GraphNodeCamera *node) { gCurLookAt->l[1].l.dir[2] = (s8)(127.0f * -(*cameraMatrix)[2][1]); #endif // F3DEX_GBI_2 +#if WORLD_SCALE > 1 // Make a copy of the view matrix and scale its translation based on WORLD_SCALE Mat4 scaledCamera; mtxf_copy(scaledCamera, gCameraTransform); @@ -706,6 +710,9 @@ void geo_process_camera(struct GraphNodeCamera *node) { // Convert the scaled matrix to fixed-point and integrate it into the projection matrix stack guMtxF2L(scaledCamera, viewMtx); +#else + guMtxF2L(gCameraTransform, viewMtx); +#endif gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(viewMtx), G_MTX_PROJECTION | G_MTX_MUL | G_MTX_NOPUSH); setup_global_light();