Added support for more texture filtering control

This commit is contained in:
Magnus Norddahl 2016-06-24 19:05:04 +02:00
parent b7f32d1bfc
commit 8ec420a597
5 changed files with 41 additions and 28 deletions

View file

@ -379,6 +379,10 @@ void R_SetDSColorMapLight(FColormap *base_colormap, float light, int shade);
void R_SetTranslationMap(lighttable_t *translation); void R_SetTranslationMap(lighttable_t *translation);
extern bool r_swtruecolor; extern bool r_swtruecolor;
EXTERN_CVAR(Bool, r_bilinear);
EXTERN_CVAR(Bool, r_multithreaded);
EXTERN_CVAR(Bool, r_magfilter_linear);
EXTERN_CVAR(Bool, r_minfilter_linear);
EXTERN_CVAR(Bool, r_mipmap);
#endif #endif

View file

@ -60,9 +60,10 @@ extern float rw_light;
extern float rw_lightstep; extern float rw_lightstep;
extern int wallshade; extern int wallshade;
CVAR(Bool, r_multithreaded, true, 0) CVAR(Bool, r_multithreaded, true, 0);
CVAR(Bool, r_bilinear, true, 0) CVAR(Bool, r_magfilter_linear, false, 0);
CVAR(Bool, r_mipmap, true, 0) CVAR(Bool, r_minfilter_linear, false, 0);
CVAR(Bool, r_mipmap, true, 0);
#ifndef NO_SSE #ifndef NO_SSE
@ -904,7 +905,7 @@ public:
const uint32_t * RESTRICT _source; const uint32_t * RESTRICT _source;
uint32_t _light; uint32_t _light;
ShadeConstants _shade_constants; ShadeConstants _shade_constants;
bool _magnifying; bool _nearest_filter;
uint32_t _srcalpha; uint32_t _srcalpha;
uint32_t _destalpha; uint32_t _destalpha;
@ -925,7 +926,7 @@ public:
_source = (const uint32_t*)ds_source; _source = (const uint32_t*)ds_source;
_light = LightBgra::calc_light_multiplier(ds_light); _light = LightBgra::calc_light_multiplier(ds_light);
_shade_constants = ds_shade_constants; _shade_constants = ds_shade_constants;
_magnifying = !SampleBgra::span_sampler_setup(_source, _xbits, _ybits, _xstep, _ystep); _nearest_filter = !SampleBgra::span_sampler_setup(_source, _xbits, _ybits, _xstep, _ystep);
_srcalpha = dc_srcalpha >> (FRACBITS - 8); _srcalpha = dc_srcalpha >> (FRACBITS - 8);
_destalpha = dc_destalpha >> (FRACBITS - 8); _destalpha = dc_destalpha >> (FRACBITS - 8);
@ -995,7 +996,7 @@ public:
LoopIterator loop(this, thread); LoopIterator loop(this, thread);
if (!loop) return; if (!loop) return;
if (_magnifying) if (_nearest_filter)
{ {
if (loop.is_64x64) if (loop.is_64x64)
{ {
@ -1040,7 +1041,7 @@ public:
LoopIterator loop(this, thread); LoopIterator loop(this, thread);
if (!loop) return; if (!loop) return;
if (_magnifying) if (_nearest_filter)
{ {
if (loop.is_64x64) if (loop.is_64x64)
{ {

View file

@ -461,15 +461,11 @@ class SampleBgra
public: public:
inline static bool span_sampler_setup(const uint32_t * RESTRICT &source, int &xbits, int &ybits, fixed_t xstep, fixed_t ystep) inline static bool span_sampler_setup(const uint32_t * RESTRICT &source, int &xbits, int &ybits, fixed_t xstep, fixed_t ystep)
{ {
if (!r_bilinear)
return false;
// Is this a magfilter or minfilter? // Is this a magfilter or minfilter?
fixed_t xmagnitude = abs(xstep) >> (32 - xbits - FRACBITS); fixed_t xmagnitude = abs(xstep) >> (32 - xbits - FRACBITS);
fixed_t ymagnitude = abs(ystep) >> (32 - ybits - FRACBITS); fixed_t ymagnitude = abs(ystep) >> (32 - ybits - FRACBITS);
fixed_t magnitude = (xmagnitude + ymagnitude) * 2 + (1 << (FRACBITS - 1)); fixed_t magnitude = (xmagnitude + ymagnitude) * 2 + (1 << (FRACBITS - 1));
if (magnitude >> FRACBITS == 0) bool magnifying = (magnitude >> FRACBITS == 0);
return false;
if (r_mipmap) if (r_mipmap)
{ {
@ -485,7 +481,8 @@ public:
level >>= 1; level >>= 1;
} }
} }
return true;
return (magnifying && r_magfilter_linear) || (!magnifying && r_minfilter_linear);
} }
FORCEINLINE static uint32_t sample_bilinear(const uint32_t *col0, const uint32_t *col1, uint32_t texturefracx, uint32_t texturefracy, int ybits, uint32_t ymax) FORCEINLINE static uint32_t sample_bilinear(const uint32_t *col0, const uint32_t *col1, uint32_t texturefracx, uint32_t texturefracy, int ybits, uint32_t ymax)

View file

@ -25,7 +25,7 @@ class VecCommand(DrawSpanRGBA) : public DrawerCommand
BYTE * RESTRICT _destorg; BYTE * RESTRICT _destorg;
fixed_t _light; fixed_t _light;
ShadeConstants _shade_constants; ShadeConstants _shade_constants;
bool _magnifying; bool _nearest_filter;
public: public:
VecCommand(DrawSpanRGBA)() VecCommand(DrawSpanRGBA)()
@ -43,7 +43,7 @@ public:
_destorg = dc_destorg; _destorg = dc_destorg;
_light = ds_light; _light = ds_light;
_shade_constants = ds_shade_constants; _shade_constants = ds_shade_constants;
_magnifying = !SampleBgra::span_sampler_setup(_source, _xbits, _ybits, _xstep, _ystep); _nearest_filter = !SampleBgra::span_sampler_setup(_source, _xbits, _ybits, _xstep, _ystep);
} }
void Execute(DrawerThread *thread) override void Execute(DrawerThread *thread) override
@ -73,7 +73,7 @@ public:
uint32_t light = LightBgra::calc_light_multiplier(_light); uint32_t light = LightBgra::calc_light_multiplier(_light);
ShadeConstants shade_constants = _shade_constants; ShadeConstants shade_constants = _shade_constants;
if (_magnifying) if (_nearest_filter)
{ {
if (_xbits == 6 && _ybits == 6) if (_xbits == 6 && _ybits == 6)
{ {

View file

@ -50,6 +50,7 @@
#include "r_plane.h" #include "r_plane.h"
#include "r_segs.h" #include "r_segs.h"
#include "r_3dfloors.h" #include "r_3dfloors.h"
#include "r_draw.h"
#include "v_palette.h" #include "v_palette.h"
#include "r_data/colormaps.h" #include "r_data/colormaps.h"
@ -58,8 +59,6 @@
CVAR(Bool, r_np2, true, 0) CVAR(Bool, r_np2, true, 0)
EXTERN_CVAR(Bool, r_bilinear)
//CVAR (Int, ty, 8, 0) //CVAR (Int, ty, 8, 0)
//CVAR (Int, tx, 8, 0) //CVAR (Int, tx, 8, 0)
@ -1104,8 +1103,7 @@ WallscanSampler::WallscanSampler(int y1, float swal, double yrepeat, fixed_t xof
bool magnifying = uv_step >> (uv_fracbits - 1) == 0; bool magnifying = uv_step >> (uv_fracbits - 1) == 0;
// Only do bilinear filtering if enabled and not a magnifying filter if (!r_swtruecolor || getcol != R_GetColumn)
if (!r_swtruecolor || !r_bilinear || magnifying || getcol != R_GetColumn)
{ {
source = getcol(texture, xoffset >> FRACBITS); source = getcol(texture, xoffset >> FRACBITS);
source2 = nullptr; source2 = nullptr;
@ -1138,13 +1136,26 @@ WallscanSampler::WallscanSampler(int y1, float swal, double yrepeat, fixed_t xof
const uint32_t *pixels = texture->GetPixelsBgra() + mipmap_offset; const uint32_t *pixels = texture->GetPixelsBgra() + mipmap_offset;
int tx0 = ((xoffset - FRACUNIT / 2) >> FRACBITS) % mip_width; bool filter_nearest = (magnifying && !r_magfilter_linear) || (!magnifying && !r_minfilter_linear);
if (tx0 < 0) if (filter_nearest)
tx0 += mip_width; {
int tx1 = (tx0 + 1) % mip_width; int tx = (xoffset >> FRACBITS) % mip_width;
source = (BYTE*)(pixels + tx0 * mip_height); if (tx < 0)
source2 = (BYTE*)(pixels + tx1 * mip_height); tx += mip_width;
texturefracx = ((xoffset + FRACUNIT / 2) >> (FRACBITS - 4)) & 15; source = (BYTE*)(pixels + tx * mip_height);
source2 = nullptr;
texturefracx = 0;
}
else
{
int tx0 = ((xoffset - FRACUNIT / 2) >> FRACBITS) % mip_width;
if (tx0 < 0)
tx0 += mip_width;
int tx1 = (tx0 + 1) % mip_width;
source = (BYTE*)(pixels + tx0 * mip_height);
source2 = (BYTE*)(pixels + tx1 * mip_height);
texturefracx = ((xoffset + FRACUNIT / 2) >> (FRACBITS - 4)) & 15;
}
} }
} }