- make the sprite drawers respond to 'gl_enhanced_nightvision' and 'gl_enhanced_nv_stealth'

This commit is contained in:
Rachael Alexanderson 2018-11-26 06:21:34 -05:00
parent 52dcec7e85
commit 01f8d711b5
6 changed files with 85 additions and 9 deletions

View file

@ -973,6 +973,8 @@ namespace swrenderer
float lumi = ((float)GPalette.BaseColors[colormap[fg]].r * 30.f +
GPalette.BaseColors[colormap[fg]].g * 59.f +
GPalette.BaseColors[colormap[fg]].b * 11.f) / 25500.f;
lumi = pow(lumi, 0.5f);
float r = 255.f - lumi * 255.f;
float g = clamp(511.f - lumi * 511.f, 0.f, 255.f);
float b = 255.f - lumi * 255.f;
@ -1024,6 +1026,8 @@ namespace swrenderer
float lumi = ((float)GPalette.BaseColors[colormap[fg]].r * 30.f +
GPalette.BaseColors[colormap[fg]].g * 59.f +
GPalette.BaseColors[colormap[fg]].b * 11.f) / 25500.f;
lumi = pow(lumi, 0.5f);
float r = 255.f - lumi * 255.f;
float g = clamp(511.f - lumi * 511.f, 0.f, 255.f);
float b = 255.f - lumi * 255.f;
@ -1091,16 +1095,19 @@ namespace swrenderer
const uint8_t *source = args.TexturePixels();
uint8_t fg = args.SolidColor();
// lumi is a desaturated colour and goes between 0.0 and 1.0, this is intentional
float lumi = ((float)GPalette.BaseColors[colormap[fg]].r * 30.f +
GPalette.BaseColors[colormap[fg]].g * 59.f +
GPalette.BaseColors[colormap[fg]].b * 11.f) / 25500.f;
lumi = pow(lumi, 0.5f);
float r = 255.f - lumi * 255.f;
float g = clamp(511.f - lumi * 511.f, 0.f, 255.f);
float b = 255.f - lumi * 255.f;
int destcolor = RGB256k.RGB[(int)r>>2][(int)g>>2][(int)b>>2];
do
{
// lumi is a desaturated colour and goes between 0.0 and 1.0, this is intentional
float lumi = ((float)GPalette.BaseColors[colormap[fg]].r * 30.f +
GPalette.BaseColors[colormap[fg]].g * 59.f +
GPalette.BaseColors[colormap[fg]].b * 11.f) / 25500.f;
float r = 255.f - lumi * 255.f;
float g = clamp(511.f - lumi * 511.f, 0.f, 255.f);
float b = 255.f - lumi * 255.f;
*dest = RGB256k.RGB[(int)r>>2][(int)g>>2][(int)b>>2];
*dest = destcolor;
dest += pitch;
frac += fracstep;

View file

@ -332,6 +332,7 @@ namespace swrenderer
float lumi = ((float)fgcolor.r * 30.0f +
fgcolor.g * 59.0f +
fgcolor.b * 11.0f) / 25500.0f;
lumi = pow(lumi, 0.5);
fgcolor.r = int(255.0f - lumi * 255.0f);
fgcolor.g = int(clamp(511.0f - lumi * 511.0f, 0.0f, 255.0f));

View file

@ -390,6 +390,8 @@ namespace swrenderer
float lumi = ((float)bgra_fgcolor[i].r * 30.0f +
bgra_fgcolor[i].g * 59.0f +
bgra_fgcolor[i].b * 11.0f) / 25500.0f;
lumi = pow(lumi, 0.5f);
//lumi = _mm_cvtss_f32(_mm_sqrt_ss(_mm_set_ss(lumi)));
bgra_outcolor[i].r = int(255.0f - lumi * 255.0f);
bgra_outcolor[i].g = int(clamp(511.0f - lumi * 511.0f, 0.0f, 255.0f));
@ -398,7 +400,7 @@ namespace swrenderer
}
__m128i outcolor = _mm_packs_epi32(_mm_loadu_si128((__m128i*)&bgra_outcolor[0]), _mm_loadu_si128((__m128i*)&bgra_outcolor[1]));
_mm_packus_epi16(outcolor, _mm_setzero_si128());
outcolor = _mm_packus_epi16(outcolor, _mm_setzero_si128());
return outcolor;
}

View file

@ -43,6 +43,8 @@
#include "swrenderer/viewport/r_viewport.h"
EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor)
EXTERN_CVAR(Int, gl_enhanced_nv_stealth)
EXTERN_CVAR(Bool, gl_enhanced_nightvision)
namespace swrenderer
{
@ -62,9 +64,31 @@ namespace swrenderer
realfixedcolormap = nullptr;
fixedcolormap = nullptr;
fixedlightlev = -1;
doenhancednightvis = 0;
if (player != nullptr && camera == player->mo)
{
if (player->fixedlightlevel != -1)
{
auto torchtype = PClass::FindActor(NAME_PowerTorch);
auto litetype = PClass::FindActor(NAME_PowerLightAmp);
for (AInventory * in = player->mo->Inventory; in; in = in->Inventory)
{
// Need special handling for light amplifiers
if (in->IsKindOf(torchtype))
{
// these can become more sophisticated later, right now i really am only
// worried about the basic implementation
if (gl_enhanced_nv_stealth > 1) doenhancednightvis = 2;
}
else if (in->IsKindOf(litetype))
{
if (gl_enhanced_nightvision) doenhancednightvis = 1;
if (gl_enhanced_nv_stealth > 0) doenhancednightvis |= 2;
}
}
}
if (player->fixedcolormap >= 0 && player->fixedcolormap < (int)SpecialColormaps.Size())
{
realfixedcolormap = &SpecialColormaps[player->fixedcolormap];

View file

@ -60,6 +60,7 @@ namespace swrenderer
static CameraLight *Instance();
int FixedLightLevel() const { return fixedlightlev; }
int DoEnhancedNightVis() const { return doenhancednightvis; }
FSWColormap *FixedColormap() const { return fixedcolormap; }
FSpecialColormap *ShaderColormap() const { return realfixedcolormap; }
@ -70,6 +71,7 @@ namespace swrenderer
private:
int fixedlightlev = 0;
int doenhancednightvis = 0;
FSWColormap *fixedcolormap = nullptr;
FSpecialColormap *realfixedcolormap = nullptr;
};

View file

@ -244,6 +244,46 @@ namespace swrenderer
bool SpriteDrawerArgs::SetBlendFunc(int op, fixed_t fglevel, fixed_t bglevel, int flags)
{
CameraLight *cameraLight = CameraLight::Instance();
if (cameraLight->FixedLightLevel() > 0)
{
if (!!(cameraLight->DoEnhancedNightVis() & 1))
{
if (flags & STYLEF_ColorIsFixed)
{
colfunc = &SWPixelFormatDrawers::FillNiteVisColumn;
}
else if (TranslationMap() == nullptr)
{
colfunc = &SWPixelFormatDrawers::DrawNiteVisColumn;
}
else
{
colfunc = &SWPixelFormatDrawers::DrawTranslatedNiteVisColumn;
drawer_needs_pal_input = true;
}
return true;
}
else if (!!(cameraLight->DoEnhancedNightVis() & 2))
{
// just render things without translucency (for now) if stealth vision is enabled
if (flags & STYLEF_ColorIsFixed)
{
colfunc = &SWPixelFormatDrawers::FillColumn;
}
else if (TranslationMap() == nullptr)
{
colfunc = &SWPixelFormatDrawers::DrawColumn;
}
else
{
colfunc = &SWPixelFormatDrawers::DrawTranslatedColumn;
drawer_needs_pal_input = true;
}
return true;
}
}
// r_drawtrans is a seriously bad thing to turn off. I wonder if I should
// just remove it completely.
if (!r_drawtrans || (op == STYLEOP_Add && fglevel == FRACUNIT && bglevel == 0 && !(flags & STYLEF_InvertSource)))