From c25e9696760afa898f24acab9ff43378e4156499 Mon Sep 17 00:00:00 2001 From: fickleheart Date: Tue, 14 Jan 2020 23:29:56 -0600 Subject: [PATCH 01/17] wip viewroll stuff --- src/d_main.c | 6 ++ src/d_player.h | 2 + src/lua_playerlib.c | 4 ++ src/p_user.c | 2 + src/r_main.c | 141 +++++++++++++++++++++++++++++++++++++++++++- src/r_main.h | 3 + 6 files changed, 157 insertions(+), 1 deletion(-) diff --git a/src/d_main.c b/src/d_main.c index 8a7c446bb..763814a5a 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -266,6 +266,9 @@ static void D_Display(void) #endif } + if (rendermode == render_soft && !splitscreen) + R_CheckViewMorph(); + // change the view size if needed if (setsizeneeded || setrenderstillneeded) { @@ -446,6 +449,9 @@ static void D_Display(void) // Image postprocessing effect if (rendermode == render_soft) { + if (!splitscreen) + R_ApplyViewMorph(); + if (postimgtype) V_DoPostProcessor(0, postimgtype, postimgparam); if (postimgtype2) diff --git a/src/d_player.h b/src/d_player.h index 62f38193f..6a1750113 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -324,6 +324,8 @@ typedef struct player_s // bounded/scaled total momentum. fixed_t bob; + angle_t viewrollangle; + // Mouse aiming, where the guy is looking at! // It is updated with cmd->aiming. angle_t aiming; diff --git a/src/lua_playerlib.c b/src/lua_playerlib.c index c501fbbb2..8b9397663 100644 --- a/src/lua_playerlib.c +++ b/src/lua_playerlib.c @@ -120,6 +120,8 @@ static int player_get(lua_State *L) lua_pushfixed(L, plr->deltaviewheight); else if (fastcmp(field,"bob")) lua_pushfixed(L, plr->bob); + else if (fastcmp(field,"viewrollangle")) + lua_pushangle(L, plr->viewrollangle); else if (fastcmp(field,"aiming")) lua_pushangle(L, plr->aiming); else if (fastcmp(field,"drawangle")) @@ -415,6 +417,8 @@ static int player_set(lua_State *L) plr->deltaviewheight = luaL_checkfixed(L, 3); else if (fastcmp(field,"bob")) plr->bob = luaL_checkfixed(L, 3); + else if (fastcmp(field,"viewrollangle")) + plr->viewrollangle = luaL_checkangle(L, 3); else if (fastcmp(field,"aiming")) { plr->aiming = luaL_checkangle(L, 3); if (plr == &players[consoleplayer]) diff --git a/src/p_user.c b/src/p_user.c index 0c4d25554..5d7383c4b 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -7432,6 +7432,8 @@ static void P_NiGHTSMovement(player_t *player) else // AngleFixed(R_PointToAngle2()) results in slight inaccuracy! Don't use it unless movement is on both axises. newangle = (INT16)FixedInt(AngleFixed(R_PointToAngle2(0,0, cmd->sidemove*FRACUNIT, cmd->forwardmove*FRACUNIT))); + newangle -= player->viewrollangle / ANG1; + if (newangle < 0 && moved) newangle = (INT16)(360+newangle); } diff --git a/src/r_main.c b/src/r_main.c index 3c6aaf6a6..fbb3c7047 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -551,6 +551,145 @@ static inline void R_InitLightTables(void) } } +static struct { + angle_t rollangle; // pre-shifted by fineshift + fixed_t fisheye; + + fixed_t zoomneeded; + INT32 *scrmap; + size_t scrmapsize; + boolean use; +} viewmorph = {0, 0, FRACUNIT, NULL, 0, false}; + +void R_CheckViewMorph(void) +{ + float zoomfactor, rollcos, rollsin; + float x1, y1, x2, y2; + fixed_t temp; + size_t end, vx, vy, pos, usedpos; + INT32 usedx, usedy, halfwidth = vid.width/2, halfheight = vid.height/2; + + angle_t rollangle = players[displayplayer].viewrollangle; + //fixed_t fisheye = players[displayplayer].viewfisheye; + + // temp values + //angle_t rollangle = leveltime << (ANGLETOFINESHIFT); + fixed_t fisheye = 0; + + rollangle >>= ANGLETOFINESHIFT; + rollangle = (((rollangle+1)/2)*2) & FINEMASK; // Limit the distinct number of angles to reduce recalcs from angles changing a lot. + + fisheye &= ~0xFF; // Same limiter logic for fisheye + + if (rollangle == viewmorph.rollangle && fisheye == viewmorph.fisheye) + return; // No change + + viewmorph.rollangle = rollangle; + viewmorph.fisheye = fisheye; + + if (viewmorph.rollangle == 0 && viewmorph.fisheye == 0) + { + viewmorph.use = false; + if (viewmorph.zoomneeded != FRACUNIT) + R_SetViewSize(); + viewmorph.zoomneeded = FRACUNIT; + + return; + } + + if (viewmorph.scrmapsize != vid.width*vid.height) + { + if (viewmorph.scrmap) + free(viewmorph.scrmap); + viewmorph.scrmap = malloc(vid.width*vid.height * sizeof(INT32)); + viewmorph.scrmapsize = vid.width*vid.height; + } + + temp = FINECOSINE(rollangle); + rollcos = FIXED_TO_FLOAT(temp); + temp = FINESINE(rollangle); + rollsin = FIXED_TO_FLOAT(temp); + + // Calculate maximum zoom needed + x1 = (vid.width*fabsf(rollcos) + vid.height*fabsf(rollsin)) / vid.width; + y1 = (vid.height*fabsf(rollcos) + vid.width*fabsf(rollsin)) / vid.height; + + temp = max(x1, y1)*FRACUNIT; + if (temp < FRACUNIT) + temp = FRACUNIT; + else + temp |= 0xFFF; // Limit how many times the viewport needs to be recalculated + + //CONS_Printf("Setting zoom to %f\n", FIXED_TO_FLOAT(temp)); + + if (temp != viewmorph.zoomneeded) + { + viewmorph.zoomneeded = temp; + R_SetViewSize(); + } + + zoomfactor = FIXED_TO_FLOAT(viewmorph.zoomneeded); + + end = vid.width * vid.height - 1; + + pos = 0; + + // Pre-multiply rollcos and rollsin to use for positional stuff + rollcos /= zoomfactor; + rollsin /= zoomfactor; + + x1 = -(halfwidth * rollcos - halfheight * rollsin); + y1 = -(halfheight * rollcos + halfwidth * rollsin); + + //CONS_Printf("Top left corner is %f %f\n", x1, y1); + + for (vy = 0; vy < halfheight; vy++) + { + x2 = x1; + y2 = y1; + x1 -= rollsin; + y1 += rollcos; + + for (vx = 0; vx < vid.width; vx++) + { + usedx = halfwidth+x2; + usedy = halfheight+y2; + + if (usedx < 0) usedx = 0; + else if (usedx >= vid.width) usedx = vid.width-1; + if (usedy < 0) usedy = 0; + else if (usedy >= vid.height) usedy = vid.height-1; + + usedpos = usedx + usedy*vid.width; + + viewmorph.scrmap[pos] = usedpos; + viewmorph.scrmap[end-pos] = end-usedpos; + + x2 += rollcos; + y2 += rollsin; + pos++; + } + } + + viewmorph.use = true; +} + +void R_ApplyViewMorph(void) +{ + UINT8 *tmpscr = screens[4]; + UINT8 *srcscr = screens[0]; + INT32 p, end = vid.width * vid.height; + + if (!viewmorph.use) + return; + + for (p = 0; p < end; p++) + tmpscr[p] = srcscr[viewmorph.scrmap[p]]; + + VID_BlitLinearScreen(tmpscr, screens[0], + vid.width*vid.bpp, vid.height, vid.width*vid.bpp, vid.width); +} + // // R_SetViewSize @@ -599,7 +738,7 @@ void R_ExecuteSetViewSize(void) centeryfrac = centery<> ANGLETOFINESHIFT); + fovtan = FixedMul(FINETANGENT(fov >> ANGLETOFINESHIFT), viewmorph.zoomneeded); if (splitscreen == 1) // Splitscreen FOV should be adjusted to maintain expected vertical view fovtan = 17*fovtan/10; diff --git a/src/r_main.h b/src/r_main.h index 998bb50ef..92876ce25 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -95,6 +95,9 @@ void R_InitHardwareMode(void); #endif void R_ReloadHUDGraphics(void); +void R_CheckViewMorph(void); +void R_ApplyViewMorph(void); + // just sets setsizeneeded true extern boolean setsizeneeded; void R_SetViewSize(void); From cd957d84f7332fc71ebd1924aaa2b533684cc07d Mon Sep 17 00:00:00 2001 From: fickleheart Date: Tue, 14 Jan 2020 23:30:19 -0600 Subject: [PATCH 02/17] LMAO fisheye --- src/r_main.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index fbb3c7047..6efc7d99b 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -564,7 +564,7 @@ static struct { void R_CheckViewMorph(void) { float zoomfactor, rollcos, rollsin; - float x1, y1, x2, y2; + float x1, y1, x2, y2, fisheyef; fixed_t temp; size_t end, vx, vy, pos, usedpos; INT32 usedx, usedy, halfwidth = vid.width/2, halfheight = vid.height/2; @@ -574,14 +574,14 @@ void R_CheckViewMorph(void) // temp values //angle_t rollangle = leveltime << (ANGLETOFINESHIFT); - fixed_t fisheye = 0; + fixed_t fisheye = FRACUNIT; rollangle >>= ANGLETOFINESHIFT; rollangle = (((rollangle+1)/2)*2) & FINEMASK; // Limit the distinct number of angles to reduce recalcs from angles changing a lot. fisheye &= ~0xFF; // Same limiter logic for fisheye - if (rollangle == viewmorph.rollangle && fisheye == viewmorph.fisheye) + if (rollangle == viewmorph.rollangle && fisheye == viewmorph.fisheye && viewmorph.scrmapsize == vid.width*vid.height) return; // No change viewmorph.rollangle = rollangle; @@ -614,6 +614,13 @@ void R_CheckViewMorph(void) x1 = (vid.width*fabsf(rollcos) + vid.height*fabsf(rollsin)) / vid.width; y1 = (vid.height*fabsf(rollcos) + vid.width*fabsf(rollsin)) / vid.height; + if (fisheye) + { + float dist = powf(2, (fisheyef = FIXED_TO_FLOAT(fisheye))/2); + x1 *= dist; + y1 *= dist; + } + temp = max(x1, y1)*FRACUNIT; if (temp < FRACUNIT) temp = FRACUNIT; @@ -652,8 +659,20 @@ void R_CheckViewMorph(void) for (vx = 0; vx < vid.width; vx++) { - usedx = halfwidth+x2; - usedy = halfheight+y2; + if (fisheye) + { + float dist = sqrtf(x2*x2 + y2*y2) * zoomfactor / sqrtf(halfwidth*halfwidth + halfheight*halfheight); + dist += (1 - sqrtf(1 - dist*dist)) / dist; + dist = powf(dist, fisheyef); + usedx = halfwidth+x2*dist; + usedy = halfheight+y2*dist; + + } + else + { + usedx = halfwidth+x2; + usedy = halfheight+y2; + } if (usedx < 0) usedx = 0; else if (usedx >= vid.width) usedx = vid.width-1; From cdbea0be26067a5774778ba51a18df7aa661ce80 Mon Sep 17 00:00:00 2001 From: fickleheart Date: Tue, 14 Jan 2020 23:30:39 -0600 Subject: [PATCH 03/17] Revert "LMAO fisheye" This reverts commit cd957d84f7332fc71ebd1924aaa2b533684cc07d. --- src/r_main.c | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index 6efc7d99b..fbb3c7047 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -564,7 +564,7 @@ static struct { void R_CheckViewMorph(void) { float zoomfactor, rollcos, rollsin; - float x1, y1, x2, y2, fisheyef; + float x1, y1, x2, y2; fixed_t temp; size_t end, vx, vy, pos, usedpos; INT32 usedx, usedy, halfwidth = vid.width/2, halfheight = vid.height/2; @@ -574,14 +574,14 @@ void R_CheckViewMorph(void) // temp values //angle_t rollangle = leveltime << (ANGLETOFINESHIFT); - fixed_t fisheye = FRACUNIT; + fixed_t fisheye = 0; rollangle >>= ANGLETOFINESHIFT; rollangle = (((rollangle+1)/2)*2) & FINEMASK; // Limit the distinct number of angles to reduce recalcs from angles changing a lot. fisheye &= ~0xFF; // Same limiter logic for fisheye - if (rollangle == viewmorph.rollangle && fisheye == viewmorph.fisheye && viewmorph.scrmapsize == vid.width*vid.height) + if (rollangle == viewmorph.rollangle && fisheye == viewmorph.fisheye) return; // No change viewmorph.rollangle = rollangle; @@ -614,13 +614,6 @@ void R_CheckViewMorph(void) x1 = (vid.width*fabsf(rollcos) + vid.height*fabsf(rollsin)) / vid.width; y1 = (vid.height*fabsf(rollcos) + vid.width*fabsf(rollsin)) / vid.height; - if (fisheye) - { - float dist = powf(2, (fisheyef = FIXED_TO_FLOAT(fisheye))/2); - x1 *= dist; - y1 *= dist; - } - temp = max(x1, y1)*FRACUNIT; if (temp < FRACUNIT) temp = FRACUNIT; @@ -659,20 +652,8 @@ void R_CheckViewMorph(void) for (vx = 0; vx < vid.width; vx++) { - if (fisheye) - { - float dist = sqrtf(x2*x2 + y2*y2) * zoomfactor / sqrtf(halfwidth*halfwidth + halfheight*halfheight); - dist += (1 - sqrtf(1 - dist*dist)) / dist; - dist = powf(dist, fisheyef); - usedx = halfwidth+x2*dist; - usedy = halfheight+y2*dist; - - } - else - { - usedx = halfwidth+x2; - usedy = halfheight+y2; - } + usedx = halfwidth+x2; + usedy = halfheight+y2; if (usedx < 0) usedx = 0; else if (usedx >= vid.width) usedx = vid.width-1; From e23f632cdbc687039ec25297ae0105142135e1a1 Mon Sep 17 00:00:00 2001 From: fickleheart Date: Tue, 14 Jan 2020 23:44:21 -0600 Subject: [PATCH 04/17] Clean up fisheye and fix crashes --- src/r_main.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index fbb3c7047..628ba078f 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -553,13 +553,12 @@ static inline void R_InitLightTables(void) static struct { angle_t rollangle; // pre-shifted by fineshift - fixed_t fisheye; fixed_t zoomneeded; INT32 *scrmap; size_t scrmapsize; boolean use; -} viewmorph = {0, 0, FRACUNIT, NULL, 0, false}; +} viewmorph = {0, FRACUNIT, NULL, 0, false}; void R_CheckViewMorph(void) { @@ -570,24 +569,16 @@ void R_CheckViewMorph(void) INT32 usedx, usedy, halfwidth = vid.width/2, halfheight = vid.height/2; angle_t rollangle = players[displayplayer].viewrollangle; - //fixed_t fisheye = players[displayplayer].viewfisheye; - - // temp values - //angle_t rollangle = leveltime << (ANGLETOFINESHIFT); - fixed_t fisheye = 0; rollangle >>= ANGLETOFINESHIFT; rollangle = (((rollangle+1)/2)*2) & FINEMASK; // Limit the distinct number of angles to reduce recalcs from angles changing a lot. - fisheye &= ~0xFF; // Same limiter logic for fisheye - - if (rollangle == viewmorph.rollangle && fisheye == viewmorph.fisheye) + if (rollangle == viewmorph.rollangle && viewmorph.scrmapsize == vid.width*vid.height) return; // No change viewmorph.rollangle = rollangle; - viewmorph.fisheye = fisheye; - if (viewmorph.rollangle == 0 && viewmorph.fisheye == 0) + if (viewmorph.rollangle == 0) { viewmorph.use = false; if (viewmorph.zoomneeded != FRACUNIT) @@ -655,11 +646,6 @@ void R_CheckViewMorph(void) usedx = halfwidth+x2; usedy = halfheight+y2; - if (usedx < 0) usedx = 0; - else if (usedx >= vid.width) usedx = vid.width-1; - if (usedy < 0) usedy = 0; - else if (usedy >= vid.height) usedy = vid.height-1; - usedpos = usedx + usedy*vid.width; viewmorph.scrmap[pos] = usedpos; From 7cf563eadd0c2a4e1977c7024ef40975159e5aff Mon Sep 17 00:00:00 2001 From: fickleheart Date: Fri, 17 Jan 2020 18:32:13 -0600 Subject: [PATCH 05/17] Un/archive viewrollangle in netsaves --- src/p_saveg.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/p_saveg.c b/src/p_saveg.c index 2b6a474bf..e0b6d9579 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -116,6 +116,7 @@ static void P_NetArchivePlayers(void) WRITEANGLE(save_p, players[i].aiming); WRITEANGLE(save_p, players[i].drawangle); + WRITEANGLE(save_p, players[i].viewrollangle); WRITEANGLE(save_p, players[i].awayviewaiming); WRITEINT32(save_p, players[i].awayviewtics); WRITEINT16(save_p, players[i].rings); @@ -325,6 +326,7 @@ static void P_NetUnArchivePlayers(void) players[i].aiming = READANGLE(save_p); players[i].drawangle = READANGLE(save_p); + players[i].viewrollangle = READANGLE(save_p); players[i].awayviewaiming = READANGLE(save_p); players[i].awayviewtics = READINT32(save_p); players[i].rings = READINT16(save_p); From 84329fcd2677a42860f986e06b901434bc44966e Mon Sep 17 00:00:00 2001 From: fickleheart Date: Fri, 17 Jan 2020 19:01:45 -0600 Subject: [PATCH 06/17] OGL can have little a viewroll --- src/hardware/hw_main.c | 6 ++++++ src/hardware/r_opengl/r_opengl.c | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 74be53db5..e1b5d23ff 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5969,6 +5969,8 @@ static void HWR_DrawSkyBackground(player_t *player) dometransform.scalez = 1; dometransform.fovxangle = fpov; // Tails dometransform.fovyangle = fpov; // Tails + dometransform.roll = (player->viewrollangle != 0); + dometransform.rollangle = FIXED_TO_FLOAT(AngleFixed(player->viewrollangle)); dometransform.splitscreen = splitscreen; HWR_GetTexture(texturetranslation[skytexture]); @@ -6192,6 +6194,8 @@ void HWR_RenderSkyboxView(INT32 viewnumber, player_t *player) atransform.scalez = 1; atransform.fovxangle = fpov; // Tails atransform.fovyangle = fpov; // Tails + atransform.roll = (player->viewrollangle != 0); + atransform.rollangle = FIXED_TO_FLOAT(AngleFixed(player->viewrollangle)); atransform.splitscreen = splitscreen; gr_fovlud = (float)(1.0l/tan((double)(fpov*M_PIl/360l))); @@ -6412,6 +6416,8 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player) atransform.scalez = 1; atransform.fovxangle = fpov; // Tails atransform.fovyangle = fpov; // Tails + atransform.roll = (player->viewrollangle != 0); + atransform.rollangle = FIXED_TO_FLOAT(AngleFixed(player->viewrollangle)); atransform.splitscreen = splitscreen; gr_fovlud = (float)(1.0l/tan((double)(fpov*M_PIl/360l))); diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index becce9fa3..a3ed3c8d2 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -2238,6 +2238,8 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform) else pglScalef(stransform->scalex, stransform->scaley, -stransform->scalez); + if (stransform->roll) + pglRotatef(stransform->rollangle, 0.0f, 0.0f, 1.0f); pglRotatef(stransform->anglex , 1.0f, 0.0f, 0.0f); pglRotatef(stransform->angley+270.0f, 0.0f, 1.0f, 0.0f); pglTranslatef(-stransform->x, -stransform->z, -stransform->y); From 2b7d75126e8e8641a4b413c74b3c65da87e0d309 Mon Sep 17 00:00:00 2001 From: fickleheart Date: Fri, 17 Jan 2020 20:39:15 -0600 Subject: [PATCH 07/17] Add DBG_VIEWMORPH to view pre-transformed view --- src/doomdef.h | 1 + src/r_main.c | 30 ++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index 3d02871e4..565d1aadf 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -490,6 +490,7 @@ extern INT32 cv_debug; #define DBG_SETUP 0x0400 #define DBG_LUA 0x0800 #define DBG_RANDOMIZER 0x1000 +#define DBG_VIEWMORPH 0x2000 // ======================= // Misc stuff for later... diff --git a/src/r_main.c b/src/r_main.c index d4d05ad44..91e1b3fe7 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -667,8 +667,34 @@ void R_ApplyViewMorph(void) if (!viewmorph.use) return; - for (p = 0; p < end; p++) - tmpscr[p] = srcscr[viewmorph.scrmap[p]]; + if (cv_debug & DBG_VIEWMORPH) + { + UINT8 border = 32; + UINT8 grid = 160; + INT32 ws = vid.width / 4; + INT32 hs = vid.width * (vid.height / 4); + + memcpy(tmpscr, srcscr, vid.width*vid.height); + for (p = 0; p < vid.width; p++) + { + tmpscr[viewmorph.scrmap[p]] = border; + tmpscr[viewmorph.scrmap[p + hs]] = grid; + tmpscr[viewmorph.scrmap[p + hs*2]] = grid; + tmpscr[viewmorph.scrmap[p + hs*3]] = grid; + tmpscr[viewmorph.scrmap[end - 1 - p]] = border; + } + for (p = vid.width; p < end; p += vid.width) + { + tmpscr[viewmorph.scrmap[p]] = border; + tmpscr[viewmorph.scrmap[p + ws]] = grid; + tmpscr[viewmorph.scrmap[p + ws*2]] = grid; + tmpscr[viewmorph.scrmap[p + ws*3]] = grid; + tmpscr[viewmorph.scrmap[end - 1 - p]] = border; + } + } + else + for (p = 0; p < end; p++) + tmpscr[p] = srcscr[viewmorph.scrmap[p]]; VID_BlitLinearScreen(tmpscr, screens[0], vid.width*vid.bpp, vid.height, vid.width*vid.bpp, vid.width); From 64c4a4c02c6a59264446e9a43593e7397b774baa Mon Sep 17 00:00:00 2001 From: fickleheart Date: Fri, 17 Jan 2020 20:39:38 -0600 Subject: [PATCH 08/17] Fisheye lens experiments --- src/r_main.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 3 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index 91e1b3fe7..689f18f2b 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -549,14 +549,29 @@ static inline void R_InitLightTables(void) } } +//#define WOUGHMP_WOUGHMP // I got a fish-eye lens - I'll make a rap video with a couple of friends +// it's kinda laggy sometimes + static struct { angle_t rollangle; // pre-shifted by fineshift +#ifdef WOUGHMP_WOUGHMP + fixed_t fisheye; +#endif fixed_t zoomneeded; INT32 *scrmap; size_t scrmapsize; boolean use; -} viewmorph = {0, FRACUNIT, NULL, 0, false}; +} viewmorph = { + 0, +#ifdef WOUGHMP_WOUGHMP + 0, +#endif + FRACUNIT, + NULL, + 0, + false +}; void R_CheckViewMorph(void) { @@ -565,18 +580,39 @@ void R_CheckViewMorph(void) fixed_t temp; size_t end, vx, vy, pos, usedpos; INT32 usedx, usedy, halfwidth = vid.width/2, halfheight = vid.height/2; +#ifdef WOUGHMP_WOUGHMP + float fisheyemap[MAXVIDWIDTH/2 + 1]; +#endif angle_t rollangle = players[displayplayer].viewrollangle; +#ifdef WOUGHMP_WOUGHMP + fixed_t fisheye = cv_cam2_turnmultiplier.value; // temporary test value +#endif rollangle >>= ANGLETOFINESHIFT; rollangle = (((rollangle+1)/2)*2) & FINEMASK; // Limit the distinct number of angles to reduce recalcs from angles changing a lot. - if (rollangle == viewmorph.rollangle && viewmorph.scrmapsize == vid.width*vid.height) +#ifdef WOUGHMP_WOUGHMP + fisheye &= ~0x7FF; // Same +#endif + + if (rollangle == viewmorph.rollangle && +#ifdef WOUGHMP_WOUGHMP + fisheye == viewmorph.fisheye && +#endif + viewmorph.scrmapsize == vid.width*vid.height) return; // No change viewmorph.rollangle = rollangle; +#ifdef WOUGHMP_WOUGHMP + viewmorph.fisheye = fisheye; +#endif - if (viewmorph.rollangle == 0) + if (viewmorph.rollangle == 0 +#ifdef WOUGHMP_WOUGHMP + && viewmorph.fisheye == 0 +#endif + ) { viewmorph.use = false; if (viewmorph.zoomneeded != FRACUNIT) @@ -603,6 +639,22 @@ void R_CheckViewMorph(void) x1 = (vid.width*fabsf(rollcos) + vid.height*fabsf(rollsin)) / vid.width; y1 = (vid.height*fabsf(rollcos) + vid.width*fabsf(rollsin)) / vid.height; +#ifdef WOUGHMP_WOUGHMP + if (fisheye) + { + float f = FIXED_TO_FLOAT(fisheye); + for (vx = 0; vx <= halfwidth; vx++) + fisheyemap[vx] = 1.0f / cos(atan(vx * f / halfwidth)); + + f = cos(atan(f)); + if (f < 1.0f) + { + x1 /= f; + y1 /= f; + } + } +#endif + temp = max(x1, y1)*FRACUNIT; if (temp < FRACUNIT) temp = FRACUNIT; @@ -632,6 +684,34 @@ void R_CheckViewMorph(void) //CONS_Printf("Top left corner is %f %f\n", x1, y1); +#ifdef WOUGHMP_WOUGHMP + if (fisheye) + { + for (vy = 0; vy < halfheight; vy++) + { + x2 = x1; + y2 = y1; + x1 -= rollsin; + y1 += rollcos; + + for (vx = 0; vx < vid.width; vx++) + { + usedx = halfwidth + x2*fisheyemap[(int) floorf(fabsf(y2*zoomfactor))]; + usedy = halfheight + y2*fisheyemap[(int) floorf(fabsf(x2*zoomfactor))]; + + usedpos = usedx + usedy*vid.width; + + viewmorph.scrmap[pos] = usedpos; + viewmorph.scrmap[end-pos] = end-usedpos; + + x2 += rollcos; + y2 += rollsin; + pos++; + } + } + } + else +#endif for (vy = 0; vy < halfheight; vy++) { x2 = x1; From 7bd9344dd01cf541d86d3e7965e7037fb85ca494 Mon Sep 17 00:00:00 2001 From: fickleheart Date: Fri, 17 Jan 2020 21:55:16 -0600 Subject: [PATCH 09/17] I think this fixes the compile errors --- src/hardware/hw_main.c | 24 ++++++++++++++++++------ src/r_main.c | 4 ++-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index e1b5d23ff..cf78c0cc0 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5969,8 +5969,12 @@ static void HWR_DrawSkyBackground(player_t *player) dometransform.scalez = 1; dometransform.fovxangle = fpov; // Tails dometransform.fovyangle = fpov; // Tails - dometransform.roll = (player->viewrollangle != 0); - dometransform.rollangle = FIXED_TO_FLOAT(AngleFixed(player->viewrollangle)); + if (player->viewrollangle != 0) + { + fixed_t rol = AngleFixed(player->viewrollangle); + dometransform.rollangle = FIXED_TO_FLOAT(rol); + dometransform.roll = true; + } dometransform.splitscreen = splitscreen; HWR_GetTexture(texturetranslation[skytexture]); @@ -6194,8 +6198,12 @@ void HWR_RenderSkyboxView(INT32 viewnumber, player_t *player) atransform.scalez = 1; atransform.fovxangle = fpov; // Tails atransform.fovyangle = fpov; // Tails - atransform.roll = (player->viewrollangle != 0); - atransform.rollangle = FIXED_TO_FLOAT(AngleFixed(player->viewrollangle)); + if (player->viewrollangle != 0) + { + fixed_t rol = AngleFixed(player->viewrollangle); + atransform.rollangle = FIXED_TO_FLOAT(rol); + atransform.roll = true; + } atransform.splitscreen = splitscreen; gr_fovlud = (float)(1.0l/tan((double)(fpov*M_PIl/360l))); @@ -6416,8 +6424,12 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player) atransform.scalez = 1; atransform.fovxangle = fpov; // Tails atransform.fovyangle = fpov; // Tails - atransform.roll = (player->viewrollangle != 0); - atransform.rollangle = FIXED_TO_FLOAT(AngleFixed(player->viewrollangle)); + if (player->viewrollangle != 0) + { + fixed_t rol = AngleFixed(player->viewrollangle); + atransform.rollangle = FIXED_TO_FLOAT(rol); + atransform.roll = true; + } atransform.splitscreen = splitscreen; gr_fovlud = (float)(1.0l/tan((double)(fpov*M_PIl/360l))); diff --git a/src/r_main.c b/src/r_main.c index 689f18f2b..27c444d88 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -560,7 +560,7 @@ static struct { fixed_t zoomneeded; INT32 *scrmap; - size_t scrmapsize; + INT32 scrmapsize; boolean use; } viewmorph = { 0, @@ -578,7 +578,7 @@ void R_CheckViewMorph(void) float zoomfactor, rollcos, rollsin; float x1, y1, x2, y2; fixed_t temp; - size_t end, vx, vy, pos, usedpos; + INT32 end, vx, vy, pos, usedpos; INT32 usedx, usedy, halfwidth = vid.width/2, halfheight = vid.height/2; #ifdef WOUGHMP_WOUGHMP float fisheyemap[MAXVIDWIDTH/2 + 1]; From 21ccefe4eb96e3b3f3216025f40d6271faaac206 Mon Sep 17 00:00:00 2001 From: fickleheart Date: Fri, 17 Jan 2020 22:03:16 -0600 Subject: [PATCH 10/17] Fix sky texture scaling wrong with fov changes --- src/r_main.h | 1 + src/r_sky.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/r_main.h b/src/r_main.h index 2378661cc..0042015f2 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -26,6 +26,7 @@ extern INT32 centerx, centery; extern fixed_t centerxfrac, centeryfrac; extern fixed_t projection, projectiony; +extern fixed_t fovtan; // field of view extern size_t validcount, linecount, loopcount, framecount; diff --git a/src/r_sky.c b/src/r_sky.c index c9d28cebc..da36eb937 100644 --- a/src/r_sky.c +++ b/src/r_sky.c @@ -76,5 +76,5 @@ void R_SetupSkyDraw(void) void R_SetSkyScale(void) { fixed_t difference = vid.fdupx-(vid.dupx< Date: Fri, 17 Jan 2020 23:21:11 -0600 Subject: [PATCH 11/17] Avoid rendering unused left/right edges of screen while rolling --- src/r_main.c | 24 +++++++++++++++++++++++- src/r_things.c | 39 ++++++--------------------------------- 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index 27c444d88..a49b0519f 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -561,6 +561,7 @@ static struct { fixed_t zoomneeded; INT32 *scrmap; INT32 scrmapsize; + INT32 x1; // clip rendering horizontally for efficiency boolean use; } viewmorph = { 0, @@ -570,6 +571,7 @@ static struct { FRACUNIT, NULL, 0, + 0, false }; @@ -615,6 +617,7 @@ void R_CheckViewMorph(void) ) { viewmorph.use = false; + viewmorph.x1 = 0; if (viewmorph.zoomneeded != FRACUNIT) R_SetViewSize(); viewmorph.zoomneeded = FRACUNIT; @@ -682,6 +685,14 @@ void R_CheckViewMorph(void) x1 = -(halfwidth * rollcos - halfheight * rollsin); y1 = -(halfheight * rollcos + halfwidth * rollsin); +#ifdef WOUGHMP_WOUGHMP + if (fisheye) + viewmorph.x1 = (INT32)(halfwidth - (halfwidth * fabsf(rollcos) + halfheight * fabsf(rollsin)) * fisheyemap[halfwidth]); + else +#endif + viewmorph.x1 = (INT32)(halfwidth - (halfwidth * fabsf(rollcos) + halfheight * fabsf(rollsin))); + //CONS_Printf("saving %d cols\n", viewmorph.x1); + //CONS_Printf("Top left corner is %f %f\n", x1, y1); #ifdef WOUGHMP_WOUGHMP @@ -1316,7 +1327,18 @@ void R_RenderPlayerView(player_t *player) validcount++; // Clear buffers. - R_ClearClipSegs(); + if (viewmorph.use) + { + portalclipstart = viewmorph.x1; + portalclipend = viewwidth-viewmorph.x1-1; + R_PortalClearClipSegs(portalclipstart, portalclipend); + } + else + { + portalclipstart = 0; + portalclipend = viewwidth-1; + R_ClearClipSegs(); + } R_ClearDrawSegs(); R_ClearPlanes(); R_ClearSprites(); diff --git a/src/r_things.c b/src/r_things.c index 8fa0f2d0e..bb98d7f15 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1307,17 +1307,8 @@ static void R_ProjectDropShadow(mobj_t *thing, vissprite_t *vis, fixed_t scale, shadow->mobj = thing; // Easy access! Tails 06-07-2002 - shadow->x1 = x1 < 0 ? 0 : x1; - shadow->x2 = x2 >= viewwidth ? viewwidth-1 : x2; - - // PORTAL SEMI-CLIPPING - if (portalrender) - { - if (shadow->x1 < portalclipstart) - shadow->x1 = portalclipstart; - if (shadow->x2 >= portalclipend) - shadow->x2 = portalclipend-1; - } + shadow->x1 = x1 < portalclipstart ? portalclipstart : x1; + shadow->x2 = x2 >= portalclipend ? portalclipend-1 : x2; shadow->xscale = FixedMul(xscale, shadowxscale); //SoM: 4/17/2000 shadow->scale = FixedMul(yscale, shadowyscale); @@ -1815,17 +1806,8 @@ static void R_ProjectSprite(mobj_t *thing) vis->mobj = thing; // Easy access! Tails 06-07-2002 - vis->x1 = x1 < 0 ? 0 : x1; - vis->x2 = x2 >= viewwidth ? viewwidth-1 : x2; - - // PORTAL SEMI-CLIPPING - if (portalrender) - { - if (vis->x1 < portalclipstart) - vis->x1 = portalclipstart; - if (vis->x2 >= portalclipend) - vis->x2 = portalclipend-1; - } + vis->x1 = x1 < portalclipstart ? portalclipstart : x1; + vis->x2 = x2 >= portalclipend ? portalclipend-1 : x2; vis->xscale = xscale; //SoM: 4/17/2000 vis->sector = thing->subsector->sector; @@ -2034,17 +2016,8 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) vis->shear.tan = 0; vis->shear.offset = 0; - vis->x1 = x1 < 0 ? 0 : x1; - vis->x2 = x2 >= viewwidth ? viewwidth-1 : x2; - - // PORTAL SEMI-CLIPPING - if (portalrender) - { - if (vis->x1 < portalclipstart) - vis->x1 = portalclipstart; - if (vis->x2 >= portalclipend) - vis->x2 = portalclipend-1; - } + vis->x1 = x1 < portalclipstart ? portalclipstart : x1; + vis->x2 = x2 >= portalclipend ? portalclipend-1 : x2; vis->xscale = xscale; //SoM: 4/17/2000 vis->sector = thing->subsector->sector; From 8868fc4d8abce1b6393303155e758921f7ef9e4f Mon Sep 17 00:00:00 2001 From: fickleheart Date: Sat, 18 Jan 2020 00:16:18 -0600 Subject: [PATCH 12/17] Fix lighting discrepancies between different FOVs --- src/r_draw8.c | 9 +++++---- src/r_draw8_npo2.c | 11 +++++++---- src/r_main.h | 2 ++ src/r_segs.c | 14 +++++++------- src/r_things.c | 4 ++-- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/r_draw8.c b/src/r_draw8.c index 015dac2a7..2f6bdcfa4 100644 --- a/src/r_draw8.c +++ b/src/r_draw8.c @@ -644,6 +644,7 @@ void R_CalcTiltedLighting(fixed_t start, fixed_t end) } } +#define PLANELIGHTFLOAT (BASEVIDWIDTH * BASEVIDWIDTH / vid.width / (zeroheight - FIXED_TO_FLOAT(viewz)) / 21.0f * FIXED_TO_FLOAT(fovtan)) /** \brief The R_DrawTiltedSpan_8 function Draw slopes! Holy sheit! @@ -669,7 +670,7 @@ void R_DrawTiltedSpan_8(void) // Lighting is simple. It's just linear interpolation from start to end { - float planelightfloat = BASEVIDWIDTH*BASEVIDWIDTH/vid.width / (zeroheight - FIXED_TO_FLOAT(viewz)) / 21.0f; + float planelightfloat = PLANELIGHTFLOAT; float lightstart, lightend; lightend = (iz + ds_szp->x*width) * planelightfloat; @@ -805,7 +806,7 @@ void R_DrawTiltedTranslucentSpan_8(void) // Lighting is simple. It's just linear interpolation from start to end { - float planelightfloat = BASEVIDWIDTH*BASEVIDWIDTH/vid.width / (zeroheight - FIXED_TO_FLOAT(viewz)) / 21.0f; + float planelightfloat = PLANELIGHTFLOAT; float lightstart, lightend; lightend = (iz + ds_szp->x*width) * planelightfloat; @@ -942,7 +943,7 @@ void R_DrawTiltedTranslucentWaterSpan_8(void) // Lighting is simple. It's just linear interpolation from start to end { - float planelightfloat = BASEVIDWIDTH*BASEVIDWIDTH/vid.width / (zeroheight - FIXED_TO_FLOAT(viewz)) / 21.0f; + float planelightfloat = PLANELIGHTFLOAT; float lightstart, lightend; lightend = (iz + ds_szp->x*width) * planelightfloat; @@ -1078,7 +1079,7 @@ void R_DrawTiltedSplat_8(void) // Lighting is simple. It's just linear interpolation from start to end { - float planelightfloat = BASEVIDWIDTH*BASEVIDWIDTH/vid.width / (zeroheight - FIXED_TO_FLOAT(viewz)) / 21.0f; + float planelightfloat = PLANELIGHTFLOAT; float lightstart, lightend; lightend = (iz + ds_szp->x*width) * planelightfloat; diff --git a/src/r_draw8_npo2.c b/src/r_draw8_npo2.c index 748ca195c..aa38ee2d9 100644 --- a/src/r_draw8_npo2.c +++ b/src/r_draw8_npo2.c @@ -62,6 +62,9 @@ void R_DrawSpan_NPO2_8 (void) } #ifdef ESLOPE + +#define PLANELIGHTFLOAT (BASEVIDWIDTH * BASEVIDWIDTH / vid.width / (zeroheight - FIXED_TO_FLOAT(viewz)) / 21.0f * FIXED_TO_FLOAT(fovtan)) + /** \brief The R_DrawTiltedSpan_NPO2_8 function Draw slopes! Holy sheit! */ @@ -86,7 +89,7 @@ void R_DrawTiltedSpan_NPO2_8(void) // Lighting is simple. It's just linear interpolation from start to end { - float planelightfloat = BASEVIDWIDTH*BASEVIDWIDTH/vid.width / (zeroheight - FIXED_TO_FLOAT(viewz)) / 21.0f; + float planelightfloat = PLANELIGHTFLOAT; float lightstart, lightend; lightend = (iz + ds_szp->x*width) * planelightfloat; @@ -282,7 +285,7 @@ void R_DrawTiltedTranslucentSpan_NPO2_8(void) // Lighting is simple. It's just linear interpolation from start to end { - float planelightfloat = BASEVIDWIDTH*BASEVIDWIDTH/vid.width / (zeroheight - FIXED_TO_FLOAT(viewz)) / 21.0f; + float planelightfloat = PLANELIGHTFLOAT; float lightstart, lightend; lightend = (iz + ds_szp->x*width) * planelightfloat; @@ -476,7 +479,7 @@ void R_DrawTiltedSplat_NPO2_8(void) // Lighting is simple. It's just linear interpolation from start to end { - float planelightfloat = BASEVIDWIDTH*BASEVIDWIDTH/vid.width / (zeroheight - FIXED_TO_FLOAT(viewz)) / 21.0f; + float planelightfloat = PLANELIGHTFLOAT; float lightstart, lightend; lightend = (iz + ds_szp->x*width) * planelightfloat; @@ -869,7 +872,7 @@ void R_DrawTiltedTranslucentWaterSpan_NPO2_8(void) // Lighting is simple. It's just linear interpolation from start to end { - float planelightfloat = BASEVIDWIDTH*BASEVIDWIDTH/vid.width / (zeroheight - FIXED_TO_FLOAT(viewz)) / 21.0f; + float planelightfloat = PLANELIGHTFLOAT; float lightstart, lightend; lightend = (iz + ds_szp->x*width) * planelightfloat; diff --git a/src/r_main.h b/src/r_main.h index 0042015f2..678d3a0a7 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -46,6 +46,8 @@ extern size_t validcount, linecount, loopcount, framecount; #define MAXLIGHTZ 128 #define LIGHTZSHIFT 20 +#define LIGHTRESOLUTIONFIX (640*fovtan/vid.width) + extern lighttable_t *scalelight[LIGHTLEVELS][MAXLIGHTSCALE]; extern lighttable_t *scalelightfixed[MAXLIGHTSCALE]; extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; diff --git a/src/r_segs.c b/src/r_segs.c index dcb5fc160..fb4238448 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -199,7 +199,7 @@ static void R_DrawWallSplats(void) // draw the columns for (dc_x = x1; dc_x <= x2; dc_x++, spryscale += rw_scalestep) { - pindex = FixedMul(spryscale, FixedDiv(640, vid.width))>>LIGHTSCALESHIFT; + pindex = FixedMul(spryscale, LIGHTRESOLUTIONFIX)>>LIGHTSCALESHIFT; if (pindex >= MAXLIGHTSCALE) pindex = MAXLIGHTSCALE - 1; dc_colormap = walllights[pindex]; @@ -599,7 +599,7 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) else xwalllights = scalelight[rlight->lightnum]; - pindex = FixedMul(spryscale, FixedDiv(640, vid.width))>>LIGHTSCALESHIFT; + pindex = FixedMul(spryscale, LIGHTRESOLUTIONFIX)>>LIGHTSCALESHIFT; if (pindex >= MAXLIGHTSCALE) pindex = MAXLIGHTSCALE - 1; @@ -644,7 +644,7 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) } // calculate lighting - pindex = FixedMul(spryscale, FixedDiv(640, vid.width))>>LIGHTSCALESHIFT; + pindex = FixedMul(spryscale, LIGHTRESOLUTIONFIX)>>LIGHTSCALESHIFT; if (pindex >= MAXLIGHTSCALE) pindex = MAXLIGHTSCALE - 1; @@ -1188,7 +1188,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) else xwalllights = scalelight[lightnum]; - pindex = FixedMul(spryscale, FixedDiv(640, vid.width))>>LIGHTSCALESHIFT; + pindex = FixedMul(spryscale, LIGHTRESOLUTIONFIX)>>LIGHTSCALESHIFT; if (pindex >= MAXLIGHTSCALE) pindex = MAXLIGHTSCALE-1; @@ -1281,7 +1281,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) } // calculate lighting - pindex = FixedMul(spryscale, FixedDiv(640, vid.width))>>LIGHTSCALESHIFT; + pindex = FixedMul(spryscale, LIGHTRESOLUTIONFIX)>>LIGHTSCALESHIFT; if (pindex >= MAXLIGHTSCALE) pindex = MAXLIGHTSCALE - 1; @@ -1486,7 +1486,7 @@ static void R_RenderSegLoop (void) if (segtextured) { // calculate lighting - pindex = FixedMul(rw_scale, FixedDiv(640, vid.width))>>LIGHTSCALESHIFT; + pindex = FixedMul(rw_scale, LIGHTRESOLUTIONFIX)>>LIGHTSCALESHIFT; if (pindex >= MAXLIGHTSCALE) pindex = MAXLIGHTSCALE-1; @@ -1521,7 +1521,7 @@ static void R_RenderSegLoop (void) else xwalllights = scalelight[lightnum]; - pindex = FixedMul(rw_scale, FixedDiv(640, vid.width))>>LIGHTSCALESHIFT; + pindex = FixedMul(rw_scale, LIGHTRESOLUTIONFIX)>>LIGHTSCALESHIFT; if (pindex >= MAXLIGHTSCALE) pindex = MAXLIGHTSCALE-1; diff --git a/src/r_things.c b/src/r_things.c index bb98d7f15..cb9d78464 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1097,7 +1097,7 @@ static void R_SplitSprite(vissprite_t *sprite) if (!((newsprite->cut & SC_FULLBRIGHT) && (!newsprite->extra_colormap || !(newsprite->extra_colormap->fog & 1)))) { - lindex = FixedMul(sprite->xscale, FixedDiv(640, vid.width))>>(LIGHTSCALESHIFT); + lindex = FixedMul(sprite->xscale, LIGHTRESOLUTIONFIX)>>(LIGHTSCALESHIFT); if (lindex >= MAXLIGHTSCALE) lindex = MAXLIGHTSCALE-1; @@ -1872,7 +1872,7 @@ static void R_ProjectSprite(mobj_t *thing) else { // diminished light - lindex = FixedMul(xscale, FixedDiv(640, vid.width))>>(LIGHTSCALESHIFT); + lindex = FixedMul(xscale, LIGHTRESOLUTIONFIX)>>(LIGHTSCALESHIFT); if (lindex >= MAXLIGHTSCALE) lindex = MAXLIGHTSCALE-1; From af4479924ad616ddf50daee4d1886a59f159607a Mon Sep 17 00:00:00 2001 From: fickleheart Date: Sat, 18 Jan 2020 10:53:00 -0600 Subject: [PATCH 13/17] Fully clip drawing to roll-used screen bounds --- src/r_main.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/src/r_main.c b/src/r_main.c index a49b0519f..7def18b40 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -561,17 +561,24 @@ static struct { fixed_t zoomneeded; INT32 *scrmap; INT32 scrmapsize; + INT32 x1; // clip rendering horizontally for efficiency + INT16 ceilingclip[MAXVIDWIDTH], floorclip[MAXVIDWIDTH]; + boolean use; } viewmorph = { 0, #ifdef WOUGHMP_WOUGHMP 0, #endif + FRACUNIT, NULL, 0, + 0, + {}, {}, + false }; @@ -693,6 +700,47 @@ void R_CheckViewMorph(void) viewmorph.x1 = (INT32)(halfwidth - (halfwidth * fabsf(rollcos) + halfheight * fabsf(rollsin))); //CONS_Printf("saving %d cols\n", viewmorph.x1); + // Set ceilingclip and floorclip + for (vx = 0; vx < vid.width; vx++) + { + viewmorph.ceilingclip[vx] = vid.height; + viewmorph.floorclip[vx] = -1; + } + x2 = x1; + y2 = y1; + for (vx = 0; vx < vid.width; vx++) + { + INT16 xa, ya, xb, yb; + xa = x2+halfwidth; + ya = y2+halfheight; + xb = vid.width-1-xa; + yb = vid.height-1-ya; + + viewmorph.ceilingclip[xa] = min(viewmorph.ceilingclip[xa], ya); + viewmorph.floorclip[xa] = max(viewmorph.floorclip[xa], ya); + viewmorph.ceilingclip[xb] = min(viewmorph.ceilingclip[xb], yb); + viewmorph.floorclip[xb] = max(viewmorph.floorclip[xb], yb); + x2 += rollcos; + y2 += rollsin; + } + x2 = x1; + y2 = y1; + for (vy = 0; vy < vid.height; vy++) + { + INT16 xa, ya, xb, yb; + xa = x2+halfwidth; + ya = y2+halfheight; + xb = vid.width-1-xa; + yb = vid.height-1-ya; + + viewmorph.ceilingclip[xa] = min(viewmorph.ceilingclip[xa], ya); + viewmorph.floorclip[xa] = max(viewmorph.floorclip[xa], ya); + viewmorph.ceilingclip[xb] = min(viewmorph.ceilingclip[xb], yb); + viewmorph.floorclip[xb] = max(viewmorph.floorclip[xb], yb); + x2 -= rollsin; + y2 += rollcos; + } + //CONS_Printf("Top left corner is %f %f\n", x1, y1); #ifdef WOUGHMP_WOUGHMP @@ -1327,11 +1375,14 @@ void R_RenderPlayerView(player_t *player) validcount++; // Clear buffers. + R_ClearPlanes(); if (viewmorph.use) { portalclipstart = viewmorph.x1; portalclipend = viewwidth-viewmorph.x1-1; R_PortalClearClipSegs(portalclipstart, portalclipend); + memcpy(ceilingclip, viewmorph.ceilingclip, sizeof(INT16)*vid.width); + memcpy(floorclip, viewmorph.floorclip, sizeof(INT16)*vid.width); } else { @@ -1340,7 +1391,6 @@ void R_RenderPlayerView(player_t *player) R_ClearClipSegs(); } R_ClearDrawSegs(); - R_ClearPlanes(); R_ClearSprites(); #ifdef FLOORSPLATS R_ClearVisibleFloorSplats(); From 8679606ebb56975a93b7140184b45170b82bc3fe Mon Sep 17 00:00:00 2001 From: fickleheart Date: Sat, 18 Jan 2020 10:53:23 -0600 Subject: [PATCH 14/17] Remove a couple adds from each pixel of morph mapping --- src/r_main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index 7def18b40..9259c6902 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -770,7 +770,11 @@ void R_CheckViewMorph(void) } } else + { #endif + x1 += halfwidth; + y1 += halfheight; + for (vy = 0; vy < halfheight; vy++) { x2 = x1; @@ -780,8 +784,8 @@ void R_CheckViewMorph(void) for (vx = 0; vx < vid.width; vx++) { - usedx = halfwidth+x2; - usedy = halfheight+y2; + usedx = x2; + usedy = y2; usedpos = usedx + usedy*vid.width; @@ -793,6 +797,9 @@ void R_CheckViewMorph(void) pos++; } } +#ifdef WOUGHMP_WOUGHMP + } +#endif viewmorph.use = true; } From 5757f24342f9dfdebe7bedc226f237bd0aea5cca Mon Sep 17 00:00:00 2001 From: fickleheart Date: Sat, 18 Jan 2020 10:53:45 -0600 Subject: [PATCH 15/17] Reduce the number of distinct roll angles --- src/r_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_main.c b/src/r_main.c index 9259c6902..1592c9ab2 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -599,7 +599,7 @@ void R_CheckViewMorph(void) #endif rollangle >>= ANGLETOFINESHIFT; - rollangle = (((rollangle+1)/2)*2) & FINEMASK; // Limit the distinct number of angles to reduce recalcs from angles changing a lot. + rollangle = ((rollangle+2) & ~3) & FINEMASK; // Limit the distinct number of angles to reduce recalcs from angles changing a lot. #ifdef WOUGHMP_WOUGHMP fisheye &= ~0x7FF; // Same From f6efe19fca206f972ebe567051648b3b11f900c2 Mon Sep 17 00:00:00 2001 From: fickleheart Date: Sat, 18 Jan 2020 11:15:36 -0600 Subject: [PATCH 16/17] Use generally higher zooms and fix fuzzy edges --- src/r_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index 1592c9ab2..548f37f57 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -669,7 +669,7 @@ void R_CheckViewMorph(void) if (temp < FRACUNIT) temp = FRACUNIT; else - temp |= 0xFFF; // Limit how many times the viewport needs to be recalculated + temp |= 0x3FFF; // Limit how many times the viewport needs to be recalculated //CONS_Printf("Setting zoom to %f\n", FIXED_TO_FLOAT(temp)); @@ -712,7 +712,7 @@ void R_CheckViewMorph(void) { INT16 xa, ya, xb, yb; xa = x2+halfwidth; - ya = y2+halfheight; + ya = y2+halfheight-1; xb = vid.width-1-xa; yb = vid.height-1-ya; From ec89015662e12dada02877feb9309b565a07b2a4 Mon Sep 17 00:00:00 2001 From: fickleheart Date: Sat, 18 Jan 2020 11:19:59 -0600 Subject: [PATCH 17/17] Fix loss of aimingtody precision at high FOV --- src/r_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_main.c b/src/r_main.c index 548f37f57..e43e3a1c3 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1045,7 +1045,7 @@ subsector_t *R_IsPointInSubsector(fixed_t x, fixed_t y) static mobj_t *viewmobj; // WARNING: a should be unsigned but to add with 2048, it isn't! -#define AIMINGTODY(a) FixedDiv((FINETANGENT((2048+(((INT32)a)>>ANGLETOFINESHIFT)) & FINEMASK)*160)>>FRACBITS, fovtan) +#define AIMINGTODY(a) ((FINETANGENT((2048+(((INT32)a)>>ANGLETOFINESHIFT)) & FINEMASK)*160)/fovtan) // recalc necessary stuff for mouseaiming // slopes are already calculated for the full possible view (which is 4*viewheight).