From bdd1deef595f92f4ba8ba194ee042158acbc623b Mon Sep 17 00:00:00 2001 From: ceski <56656010+ceski-1@users.noreply.github.com> Date: Wed, 14 Feb 2024 21:43:55 -0800 Subject: [PATCH] FOV adjustments for skies (#1474) * Refactor FOV (again) * FOV affects `linearskyangle` calculations * FOV affects sky scale calculations * Apply fade to color for stretched skies To prevent tiling at a large FOV. --- src/r_main.c | 45 +++++++++++++++++++++++++++------------------ src/r_main.h | 1 + src/r_plane.c | 22 +++++++++++++--------- 3 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index 00ed7491..ab70a3ac 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -50,6 +50,7 @@ int centerx, centery; fixed_t centerxfrac, centeryfrac; fixed_t focallength; fixed_t projection; +fixed_t skyiscale; fixed_t viewx, viewy, viewz; angle_t viewangle; localview_t localview; @@ -260,8 +261,10 @@ static fixed_t centerxfrac_nonwide; static void R_InitTextureMapping(void) { register int i,x; + double angle; // tan angle with offset applied like vanilla R_InitTables(). fixed_t slopefrac; angle_t fov; + double slopebam; // Use tangent table to generate viewangletox: // viewangletox will give the next greatest x @@ -270,31 +273,32 @@ static void R_InitTextureMapping(void) // Calc focallength // so FIELDOFVIEW angles covers SCREENWIDTH. - if (custom_fov != FOV_DEFAULT) + if (custom_fov == FOV_DEFAULT) { - const double slope = (tan(custom_fov * M_PI / 360.0) * - centerxfrac / centerxfrac_nonwide); - const double angle = atan(slope) + M_PI / FINEANGLES; // finetangent offset. - fov = angle * FINEANGLES / M_PI; - slopefrac = tan(angle) * FRACUNIT; - focallength = FixedDiv(centerxfrac, slopefrac); - projection = centerxfrac / slope; - } - else - { - fov = FIELDOFVIEW; - slopefrac = finetangent[FINEANGLES / 4 + fov / 2]; + slopefrac = finetangent[FINEANGLES / 4 + FIELDOFVIEW / 2]; focallength = FixedDiv(centerxfrac_nonwide, slopefrac); projection = centerxfrac_nonwide; - if (centerxfrac != centerxfrac_nonwide) + if (centerxfrac == centerxfrac_nonwide) + { + angle = (FIELDOFVIEW / 2.0 + 0.5) * 2.0 * M_PI / FINEANGLES; + } + else { const double slope = (double)centerxfrac / centerxfrac_nonwide; - const double angle = atan(slope) + M_PI / FINEANGLES; // finetangent offset. - fov = angle * FINEANGLES / M_PI; + angle = atan(slope) + M_PI / FINEANGLES; slopefrac = tan(angle) * FRACUNIT; } } + else + { + const double slope = (tan(custom_fov * M_PI / 360.0) * + centerxfrac / centerxfrac_nonwide); + angle = atan(slope) + M_PI / FINEANGLES; + slopefrac = tan(angle) * FRACUNIT; + focallength = FixedDiv(centerxfrac, slopefrac); + projection = centerxfrac / slope; + } for (i=0 ; i x; i++) ; xtoviewangle[x] = (i<>ANGLETOFINESHIFT]); diff --git a/src/r_main.h b/src/r_main.h index 1c4ab2c0..c6dd5ed5 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -39,6 +39,7 @@ extern fixed_t centerxfrac; extern fixed_t centeryfrac; extern fixed_t focallength; extern fixed_t projection; +extern fixed_t skyiscale; extern int validcount; extern int linecount; extern int loopcount; diff --git a/src/r_plane.c b/src/r_plane.c index a3a6e882..fedc184d 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -390,6 +390,7 @@ static void do_draw_plane(visplane_t *pl) int texture; angle_t an, flip; boolean vertically_scrolling = false; + boolean stretch; // killough 10/98: allow skies to come from sidedefs. // Allows scrolling and/or animated skies, as well as @@ -447,19 +448,22 @@ static void do_draw_plane(visplane_t *pl) dc_colormap[0] = dc_colormap[1] = fullcolormap; // killough 3/20/98 dc_texheight = textureheight[texture]>>FRACBITS; // killough - dc_iscale = pspriteiscale; + dc_iscale = skyiscale; // [FG] stretch short skies - if (stretchsky && dc_texheight < 200) - { - dc_iscale = dc_iscale * dc_texheight / SKYSTRETCH_HEIGHT; - dc_texturemid = dc_texturemid * dc_texheight / SKYSTRETCH_HEIGHT; - colfunc = R_DrawColumn; - } - else if (!vertically_scrolling) + stretch = (stretchsky && dc_texheight < 200); + if (stretch || !vertically_scrolling) { + fixed_t diff; + + if (stretch) + { + dc_iscale = dc_iscale * dc_texheight / SKYSTRETCH_HEIGHT; + dc_texturemid = dc_texturemid * dc_texheight / SKYSTRETCH_HEIGHT; + } + // Make sure the fade-to-color effect doesn't happen too early - fixed_t diff = dc_texturemid - SCREENHEIGHT / 2 * FRACUNIT; + diff = dc_texturemid - SCREENHEIGHT / 2 * FRACUNIT; if (diff < 0) { diff += textureheight[texture];