From 84fda053ba306e6f7419fc81caca2af819f93938 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sat, 14 Nov 2009 03:08:35 +0000 Subject: [PATCH] - More sky changes: Textures taller than 200 pixels but shorter than 241 are scaled to the height of a 200 pixel tall sky. Skies taller than 240 use the same scale as a 240 tall sky but are shifted down to make the top of the texture align with the top of the screen when looking fully up. Thus, by using a sky texture with a height of 240 or more pixels, the sky will be drawn with square pixels instead of the vertically elongated ones imposed by Doom's native 320x200 resolution. SVN r1978 (trunk) --- docs/rh-log.txt | 9 +++++++++ src/r_plane.cpp | 8 ++++++++ src/r_sky.cpp | 41 ++++++++++++++++++++++++++++------------- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index e3b3ffad9..19826e030 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,3 +1,12 @@ +November 13, 2009 +- More sky changes: Textures taller than 200 pixels but shorter than 241 + are scaled to the height of a 200 pixel tall sky. Skies taller than 240 + use the same scale as a 240 tall sky but are shifted down to make the + top of the texture align with the top of the screen when looking fully up. + Thus, by using a sky texture with a height of 240 or more pixels, the sky + will be drawn with square pixels instead of the vertically elongated ones + imposed by Doom's native 320x200 resolution. + November 12, 2009 - Improved sky stretching a bit: It now only stretches the sky as tall as it needs to be: 228 pixels, not 256. It no longer stretches horizontally, diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 7e1a1e7b0..54f68799f 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -866,6 +866,14 @@ static void R_DrawSky (visplane_t *pl) { // The texture does not tile nicely frontyScale = DivScale16 (skyscale, frontyScale); frontiScale = DivScale32 (1, frontyScale); + // Sodding crap. Fixed point sucks when you want precision. + // TODO (if I'm feeling adventurous): Rewrite the renderer to use floating point + // coordinates to keep as much precision as possible until the final + // rasterization stage so fudges like this aren't needed. + if (viewheight <= 600) + { + skymid -= FRACUNIT; + } R_DrawSkyStriped (pl); } } diff --git a/src/r_sky.cpp b/src/r_sky.cpp index 7463be49e..83231fe70 100644 --- a/src/r_sky.cpp +++ b/src/r_sky.cpp @@ -82,27 +82,36 @@ void R_InitSkyMap () sky2texture = sky1texture; } - // Skies between [128,200) are stretched to 200 pixels. Shorter skies do - // not stretch because it is assumed they are meant to tile, and taller - // skies do not stretch because they provide enough information for no - // repetition when looking all the way up. + // There are various combinations for sky rendering depending on how tall the sky is: + // h < 128: Unstretched and tiled, centered on horizon + // 128 <= h < 200: Can possibly be stretched. When unstretched, the baseline is + // 28 rows below the horizon so that the top of the texture + // aligns with the top of the screen when looking straight ahead. + // When stretched, it is scaled to 228 pixels with the baseline + // in the same location as an unstretched 128-tall sky, so the top + // of the texture aligns with the top of the screen when looking + // fully up. + // h == 200: Unstretched, baseline is on horizon, and top is at the top of + // the screen when looking fully up. + // 200 < h <= 240: Squashed to consume the same height as a 200-pixel tall sky + // and aligned on the horizon. + // h > 240: Same scale as a 240-tall sky, but the baseline is shifted down + // so that the top of the texture is at the top of the screen + // when looking fully up. skyheight = skytex1->GetScaledHeight(); - if (skyheight < 200) + skystretch = false; + skytexturemid = 0; + if (skyheight >= 128 && skyheight < 200) { skystretch = (r_stretchsky && skyheight >= 128 && level.IsFreelookAllowed() && !(level.flags & LEVEL_FORCENOSKYSTRETCH)) ? 1 : 0; - // The sky is shifted down from center so that it is entirely visible - // when looking straight ahead. skytexturemid = -28*FRACUNIT; } - else + else if (skyheight > 240) { - // The sky is directly centered so that it is entirely visible when - // looking fully up. - skytexturemid = 0; - skystretch = false; + skytexturemid = (240 - skyheight) << FRACBITS; } if (viewwidth != 0 && viewheight != 0) @@ -115,7 +124,13 @@ void R_InitSkyMap () skyscale = Scale (skyscale, 2048, FieldOfView); } - if (skystretch) + if (skyheight > 200) + { + int sheight = MIN(skyheight, 240); + skyscale = Scale(skyscale, 200, sheight); + skyiscale = Scale(skyiscale, sheight, 200); + } + else if (skystretch) { skyscale = Scale(skyscale, SKYSTRETCH_HEIGHT, skyheight); skyiscale = Scale(skyiscale, skyheight, SKYSTRETCH_HEIGHT);