From 3a7532fd9bd702858431d8ecaffaf6cbab93bc1c Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sun, 6 Nov 2016 11:39:28 +0100 Subject: [PATCH] Improve flat mipmap selection --- src/r_draw.cpp | 1 + src/r_draw.h | 1 + src/r_draw_rgba.cpp | 17 ++++++----------- src/r_plane.cpp | 10 ++++++++++ 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/r_draw.cpp b/src/r_draw.cpp index 0ff047238..bd53889a1 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -1046,6 +1046,7 @@ dsfixed_t ds_xstep; dsfixed_t ds_ystep; int ds_xbits; int ds_ybits; +double ds_lod; // start of a floor/ceiling tile image const BYTE* ds_source; diff --git a/src/r_draw.h b/src/r_draw.h index 005897de6..196e26bea 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -316,6 +316,7 @@ extern "C" dsfixed_t ds_ystep; extern "C" int ds_xbits; extern "C" int ds_ybits; extern "C" fixed_t ds_alpha; +extern "C" double ds_lod; // start of a 64*64 tile image extern "C" const BYTE* ds_source; diff --git a/src/r_draw_rgba.cpp b/src/r_draw_rgba.cpp index 34c79b3aa..a649572cc 100644 --- a/src/r_draw_rgba.cpp +++ b/src/r_draw_rgba.cpp @@ -97,7 +97,7 @@ public: args.flags = 0; if (ds_shade_constants.simple_shade) args.flags |= DrawSpanArgs::simple_shade; - if (!sampler_setup(args.source, args.xbits, args.ybits, args.xstep, args.ystep, ds_source_mipmapped)) + if (!sampler_setup(args.source, args.xbits, args.ybits, ds_source_mipmapped)) args.flags |= DrawSpanArgs::nearest_filter; } @@ -117,18 +117,13 @@ protected: DrawSpanArgs args; private: - inline static bool sampler_setup(const uint32_t * &source, int &xbits, int &ybits, fixed_t xstep, fixed_t ystep, bool mipmapped) + inline static bool sampler_setup(const uint32_t * &source, int &xbits, int &ybits, bool mipmapped) { - // Is this a magfilter or minfilter? - fixed_t xmagnitude = abs(xstep) >> (32 - xbits - FRACBITS); - fixed_t ymagnitude = abs(ystep) >> (32 - ybits - FRACBITS); - fixed_t magnitude = (xmagnitude + ymagnitude) * 2 + (1 << (FRACBITS - 1)); - bool magnifying = (magnitude >> FRACBITS == 0); - + bool magnifying = ds_lod < 0.0f; if (r_mipmap && mipmapped) { - int level = magnitude >> (FRACBITS + 1); - while (level != 0) + int level = (int)ds_lod; + while (level > 0) { if (xbits <= 2 || ybits <= 2) break; @@ -136,7 +131,7 @@ private: source += (1 << (xbits)) * (1 << (ybits)); xbits -= 1; ybits -= 1; - level >>= 1; + level--; } } diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 21cea7bcf..96225729b 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -245,6 +245,16 @@ void R_MapPlane (int y, int x1) ds_yfrac = 0; } + if (r_swtruecolor) + { + double distance2 = planeheight * yslope[(y + 1 < viewheight) ? y + 1 : y - 1]; + double xmagnitude = fabs(ystepscale * (distance2 - distance) * FocalLengthX); + double ymagnitude = fabs(xstepscale * (distance2 - distance) * FocalLengthX); + double magnitude = MAX(ymagnitude, xmagnitude); + double min_lod = -1000.0; + ds_lod = MAX(log2(magnitude) + r_lod_bias, min_lod); + } + if (plane_shade) { // Determine lighting based on the span's distance from the viewer.