Alter fog depth to deal with new near plane value

This commit is contained in:
MysterD 2022-05-27 19:56:38 -07:00
parent 503a6fcfe1
commit 1fec13a0cb
5 changed files with 33 additions and 11 deletions

View file

@ -11802,12 +11802,6 @@ void rom_hack_cam_walk(Vec3f pos, Vec3f dir, f32 dist) {
return;
}
Vec3f prevPos = {
pos[0],
pos[1],
pos[2],
};
// figure out dir normal
Vec3f dirNorm;
vec3f_copy(dirNorm, dir);

View file

@ -42,7 +42,9 @@
#define MATRIX_STACK_SIZE 32
#define MAX_PROJECTION_NEAR_VALUE 5
f32 gProjectionMaxNearValue = 5;
s16 gProjectionVanillaNearValue = 100;
s16 gProjectionVanillaFarValue = 1000;
s16 gMatStackIndex;
Mat4 gMatStack[MATRIX_STACK_SIZE] = {};
@ -224,7 +226,7 @@ void patch_mtx_interpolated(f32 delta) {
if (sPerspectiveNode != NULL) {
u16 perspNorm;
f32 fovInterpolated = delta_interpolate_f32(sPerspectiveNode->prevFov, sPerspectiveNode->fov, delta);
f32 near = MIN(sPerspectiveNode->near, MAX_PROJECTION_NEAR_VALUE);
f32 near = MIN(sPerspectiveNode->near, gProjectionMaxNearValue);
guPerspective(sPerspectiveMtx, &perspNorm, not_zero(fovInterpolated, gOverrideFOV), sPerspectiveAspect, not_zero(near, gOverrideNear), not_zero(sPerspectiveNode->far, gOverrideFar), 1.0f);
gSPMatrix(sPerspectivePos, VIRTUAL_TO_PHYSICAL(sPerspectiveNode), G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH);
}
@ -459,7 +461,9 @@ static void geo_process_perspective(struct GraphNodePerspective *node) {
f32 aspect = (f32) gCurGraphNodeRoot->width / divisor;
#endif
f32 near = MIN(node->near, MAX_PROJECTION_NEAR_VALUE);
gProjectionVanillaNearValue = node->near;
gProjectionVanillaFarValue = node->far;
f32 near = MIN(node->near, gProjectionMaxNearValue);
guPerspective(mtx, &perspNorm, not_zero(node->prevFov, gOverrideFOV), aspect, not_zero(near, gOverrideNear), not_zero(node->far, gOverrideFar), 1.0f);
sPerspectiveNode = node;

View file

@ -5,6 +5,10 @@
#include "engine/graph_node.h"
extern f32 gProjectionMaxNearValue;
extern s16 gProjectionVanillaNearValue;
extern s16 gProjectionVanillaFarValue;
extern struct GraphNodeRoot *gCurGraphNodeRoot;
extern struct GraphNodeMasterList *gCurGraphNodeMasterList;
extern struct GraphNodePerspective *gCurGraphNodeCamFrustum;

View file

@ -15,8 +15,8 @@
#include "pc/lua/smlua.h"
#include "pc/network/socket/socket.h"
static bool sHoldingAlt = false;
static bool sHoldingShift = false;
#define SCANCODE_0 0x0B
#define SCANCODE_1 0x02
@ -30,6 +30,7 @@ static bool sHoldingAlt = false;
#define SCANCODE_9 0x0A
#define SCANCODE_F5 0x3f
#define SCANCODE_ALT 0x38
#define SCANCODE_SHIFT 0x2A
static void debug_breakpoint_here(void) {
// create easy breakpoint position for debugging
@ -96,6 +97,7 @@ void debug_keyboard_on_key_down(int scancode) {
if (gNetworkSystem == &gNetworkSystemSocket) {
switch (scancode & 0xFF) {
case SCANCODE_ALT: sHoldingAlt = true; break;
case SCANCODE_SHIFT: sHoldingShift = true; break;
case SCANCODE_3: debug_breakpoint_here(); break;
#ifdef DEVELOPMENT
case SCANCODE_1: if (sHoldingAlt) { debug_warp_level1(); } break;
@ -114,6 +116,7 @@ void debug_keyboard_on_key_up(int scancode) {
if (gNetworkSystem == &gNetworkSystemSocket) {
switch (scancode & 0xFF) {
case SCANCODE_ALT: sHoldingAlt = false; break;
case SCANCODE_SHIFT: sHoldingShift = false; break;
}
}
}

View file

@ -28,6 +28,8 @@
#include "macros.h"
#include "game/rendering_graph_node.h"
#define SUPPORT_CHECK(x) assert(x)
// SCALE_M_N: upscale/downscale M-bit integer to N-bit
@ -171,6 +173,10 @@ static size_t buf_vbo_num_tris;
static struct GfxWindowManagerAPI *gfx_wapi;
static struct GfxRenderingAPI *gfx_rapi;
static f32 sDepthZAdd = 0;
static f32 sDepthZMult = 1;
static f32 sDepthZSub = 0;
// 4x4 pink-black checkerboard texture to indicate missing textures
#define MISSING_W 4
#define MISSING_H 4
@ -866,8 +872,13 @@ static void OPTIMIZE_O3 gfx_sp_vertex(size_t n_vertices, size_t dest_index, cons
if (winv < 0.0f) {
winv = 32767.0f;
}
z -= sDepthZSub;
z *= sDepthZMult;
z += sDepthZAdd;
float fog_z = z * winv * rsp.fog_mul + rsp.fog_offset;
if (fog_z < 0) fog_z = 0;
if (fog_z > 255) fog_z = 255;
d->color.a = fog_z; // Use alpha variable to store fog factor
@ -1182,6 +1193,12 @@ static void gfx_sp_moveword(uint8_t index, UNUSED uint16_t offset, uint32_t data
case G_MW_FOG:
rsp.fog_mul = (int16_t)(data >> 16);
rsp.fog_offset = (int16_t)data;
// Alter depth buffer to deal with new near plane
sDepthZAdd = (gProjectionMaxNearValue - gProjectionVanillaNearValue) + gProjectionMaxNearValue;
sDepthZMult = (gProjectionVanillaFarValue - gProjectionMaxNearValue) / (gProjectionVanillaFarValue - gProjectionVanillaNearValue);
sDepthZSub = gProjectionVanillaNearValue;
break;
}
}