remap scale with fov and avoid copy when world scale is 1

This commit is contained in:
thecozies
2023-09-23 15:05:30 -05:00
parent 00b4475427
commit b1ef06fcd1

View File

@@ -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();