- made 'nocoloredspritelighting' a global option and also implemented it in the software renderer.

This commit is contained in:
Christoph Oelckers 2017-03-16 00:56:03 +01:00
parent 91da8aecdb
commit 3aa7687d91
17 changed files with 73 additions and 59 deletions

View file

@ -142,6 +142,11 @@ struct PalEntry
return other;
}
}
void Decolorize() // this for 'nocoloredspritelighting' and not the same as desaturation. The normal formula results in a value that's too dark.
{
int v = (r + g + b);
r = g = b = ((255*3) + v + v) / 9;
}
bool isBlack() const
{
return (d & 0xffffff) == 0;

View file

@ -240,6 +240,7 @@ enum ELevelFlags : unsigned int
LEVEL3_REMOVEITEMS = 0x00000002, // kills all INVBAR items on map change.
LEVEL3_ATTENUATE = 0x00000004, // attenuate lights?
LEVEL3_NOLIGHTFADE = 0x00000008, // no light fading to black.
LEVEL3_NOCOLOREDSPRITELIGHTING = 0x00000010, // draw sprites only with color-less light
};

View file

@ -1357,6 +1357,7 @@ MapFlagHandlers[] =
{ "spawnwithweaponraised", MITYPE_SETFLAG2, LEVEL2_PRERAISEWEAPON, 0 },
{ "forcefakecontrast", MITYPE_SETFLAG3, LEVEL3_FORCEFAKECONTRAST, 0 },
{ "nolightfade", MITYPE_SETFLAG3, LEVEL3_NOLIGHTFADE, 0 },
{ "nocoloredspritelighting", MITYPE_SETFLAG3, LEVEL3_NOCOLOREDSPRITELIGHTING, 0 },
{ "nobotnodes", MITYPE_IGNORE, 0, 0 }, // Skulltag option: nobotnodes
{ "compat_shorttex", MITYPE_COMPATFLAG, COMPATF_SHORTTEX, 0 },
{ "compat_stairs", MITYPE_COMPATFLAG, COMPATF_STAIRINDEX, 0 },
@ -1431,7 +1432,16 @@ void FMapInfoParser::ParseMapDefinition(level_info_t &info)
break;
case MITYPE_SETFLAG:
if (!CheckAssign())
{
info.flags |= handler->data1;
}
else
{
sc.MustGetNumber();
if (sc.Number) info.flags |= handler->data1;
else info.flags &= ~handler->data1;
}
info.flags |= handler->data2;
break;
@ -1445,7 +1455,16 @@ void FMapInfoParser::ParseMapDefinition(level_info_t &info)
break;
case MITYPE_SETFLAG2:
if (!CheckAssign())
{
info.flags2 |= handler->data1;
}
else
{
sc.MustGetNumber();
if (sc.Number) info.flags2 |= handler->data1;
else info.flags2 &= ~handler->data1;
}
info.flags2 |= handler->data2;
break;
@ -1459,7 +1478,16 @@ void FMapInfoParser::ParseMapDefinition(level_info_t &info)
break;
case MITYPE_SETFLAG3:
if (!CheckAssign())
{
info.flags3 |= handler->data1;
}
else
{
sc.MustGetNumber();
if (sc.Number) info.flags3 |= handler->data1;
else info.flags3 &= ~handler->data1;
}
info.flags3 |= handler->data2;
break;

View file

@ -79,11 +79,6 @@ CUSTOM_CVAR(Bool, gl_notexturefill, false, 0)
}
CUSTOM_CVAR(Bool, gl_nocoloredspritelighting, false, 0)
{
glset.nocoloredspritelighting = self;
}
void gl_CreateSections();
//-----------------------------------------------------------------------------
@ -191,7 +186,6 @@ struct FGLROptions : public FOptionalMapinfoData
identifier = "gl_renderer";
brightfog = false;
lightmode = -1;
nocoloredspritelighting = -1;
notexturefill = -1;
skyrotatevector = FVector3(0,0,1);
skyrotatevector2 = FVector3(0,0,1);
@ -202,7 +196,6 @@ struct FGLROptions : public FOptionalMapinfoData
FGLROptions *newopt = new FGLROptions;
newopt->identifier = identifier;
newopt->lightmode = lightmode;
newopt->nocoloredspritelighting = nocoloredspritelighting;
newopt->notexturefill = notexturefill;
newopt->skyrotatevector = skyrotatevector;
newopt->skyrotatevector2 = skyrotatevector2;
@ -212,7 +205,6 @@ struct FGLROptions : public FOptionalMapinfoData
int lightmode;
int brightfog;
int8_t lightadditivesurfaces;
int8_t nocoloredspritelighting;
int8_t notexturefill;
FVector3 skyrotatevector;
FVector3 skyrotatevector2;
@ -234,20 +226,6 @@ DEFINE_MAP_OPTION(lightmode, false)
opt->lightmode = uint8_t(parse.sc.Number);
}
DEFINE_MAP_OPTION(nocoloredspritelighting, false)
{
FGLROptions *opt = info->GetOptData<FGLROptions>("gl_renderer");
if (parse.CheckAssign())
{
parse.sc.MustGetNumber();
opt->nocoloredspritelighting = !!parse.sc.Number;
}
else
{
opt->nocoloredspritelighting = true;
}
}
DEFINE_MAP_OPTION(notexturefill, false)
{
FGLROptions *opt = info->GetOptData<FGLROptions>("gl_renderer");
@ -317,8 +295,6 @@ static void ResetOpts()
{
if (!IsLightmodeValid()) glset.lightmode = gl_lightmode;
else glset.lightmode = glset.map_lightmode;
if (glset.map_nocoloredspritelighting == -1) glset.nocoloredspritelighting = gl_nocoloredspritelighting;
else glset.nocoloredspritelighting = !!glset.map_nocoloredspritelighting;
if (glset.map_notexturefill == -1) glset.notexturefill = gl_notexturefill;
else glset.notexturefill = !!glset.map_notexturefill;
if (glset.map_brightfog == -1) glset.brightfog = gl_brightfog;
@ -336,7 +312,6 @@ void InitGLRMapinfoData()
glset.map_lightmode = opt->lightmode;
glset.map_lightadditivesurfaces = opt->lightadditivesurfaces;
glset.map_brightfog = opt->brightfog;
glset.map_nocoloredspritelighting = opt->nocoloredspritelighting;
glset.map_notexturefill = opt->notexturefill;
glset.skyrotatevector = opt->skyrotatevector;
glset.skyrotatevector2 = opt->skyrotatevector2;
@ -346,7 +321,6 @@ void InitGLRMapinfoData()
glset.map_lightmode = -1;
glset.map_lightadditivesurfaces = -1;
glset.map_brightfog = -1;
glset.map_nocoloredspritelighting = -1;
glset.map_notexturefill = -1;
glset.skyrotatevector = FVector3(0, 0, 1);
glset.skyrotatevector2 = FVector3(0, 0, 1);

View file

@ -9,13 +9,11 @@
struct GLRenderSettings
{
int8_t lightmode;
bool nocoloredspritelighting;
bool notexturefill;
bool brightfog;
bool lightadditivesurfaces;
int8_t map_lightmode;
int8_t map_nocoloredspritelighting;
int8_t map_notexturefill;
int8_t map_brightfog;
int8_t map_lightadditivesurfaces;

View file

@ -29,6 +29,7 @@
#include "gl/system/gl_system.h"
#include "a_sharedglobal.h"
#include "r_utility.h"
#include "g_levellocals.h"
#include "gl/system/gl_cvars.h"
#include "gl/data/gl_data.h"
@ -161,7 +162,7 @@ void GLWall::DrawDecal(DBaseDecal *decal)
FColormap p = Colormap;
if (glset.nocoloredspritelighting)
if (level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING)
{
p.Decolorize();
}
@ -346,7 +347,7 @@ void GLWall::DrawDecal(DBaseDecal *decal)
thiscm.FadeColor = Colormap.FadeColor;
thiscm.CopyFrom3DLight(&(*lightlist)[k]);
mDrawer->SetColor(thisll, rel, thiscm, a);
if (glset.nocoloredspritelighting) thiscm.Decolorize();
if (level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING) thiscm.Decolorize();
mDrawer->SetFog(thisll, rel, &thiscm, RenderStyle == STYLE_Add);
gl_RenderState.SetSplitPlanes((*lightlist)[k].plane, lowplane);

View file

@ -401,7 +401,7 @@ void GLSprite::Draw(int pass)
FColormap thiscm;
thiscm.CopyFog(Colormap);
thiscm.CopyFrom3DLight(&(*lightlist)[i]);
if (glset.nocoloredspritelighting)
if (level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING)
{
thiscm.Decolorize();
}
@ -527,7 +527,7 @@ void GLSprite::SplitSprite(sector_t * frontsector, bool translucent)
copySprite.lightlevel = gl_ClampLight(*lightlist[i].p_lightlevel);
copySprite.Colormap.CopyLight(lightlist[i].extra_colormap);
if (glset.nocoloredspritelighting)
if (level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING)
{
copySprite.Colormap.Decolorize();
}
@ -940,7 +940,7 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal)
Colormap.LightColor.b = (3 * Colormap.LightColor.b + 0xff) / 4;
}
}
else if (glset.nocoloredspritelighting)
else if (level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING)
{
Colormap.Decolorize();
}
@ -1118,7 +1118,7 @@ void GLSprite::ProcessParticle (particle_t *particle, sector_t *sector)//, int s
break;
}
}
if (glset.nocoloredspritelighting)
if (level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING)
{
Colormap.Decolorize(); // ZDoom never applies colored light to particles.
}

View file

@ -251,7 +251,7 @@ void GLSceneDrawer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep)
lightlevel = gl_ClampLight(fakesec->lightlevel);
// calculate colormap for weapon sprites
if (viewsector->e->XFloor.ffloors.Size() && !glset.nocoloredspritelighting)
if (viewsector->e->XFloor.ffloors.Size() && !(level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING))
{
TArray<lightlist_t> & lightlist = viewsector->e->XFloor.lightlist;
for(i=0;i<lightlist.Size();i++)
@ -278,7 +278,7 @@ void GLSceneDrawer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep)
else
{
cm=fakesec->Colormap;
if (glset.nocoloredspritelighting) cm.ClearColor();
if (level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING) cm.ClearColor();
}
lightlevel = gl_CalcLightLevel(lightlevel, getExtraLight(), true);

View file

@ -215,7 +215,7 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa
bool noaccel = false;
FDynamicColormap *basecolormap = GetColorTable(viewpoint.sector->Colormap, viewpoint.sector->SpecialColors[sector_t::sprites]);
FDynamicColormap *basecolormap = GetColorTable(viewpoint.sector->Colormap, viewpoint.sector->SpecialColors[sector_t::sprites], true);
FDynamicColormap *colormap_to_use = basecolormap;
int ColormapNum = 0;

View file

@ -162,7 +162,7 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, const Vec4f &clipPla
args.stenciltestvalue = stencilValue;
args.stencilwritevalue = stencilValue;
args.SetTexture(tex, thing->Translation);
args.SetColormap(GetColorTable(sub->sector->Colormap, sub->sector->SpecialColors[sector_t::sprites]));
args.SetColormap(GetColorTable(sub->sector->Colormap, sub->sector->SpecialColors[sector_t::sprites], true));
args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w);
TriBlendMode blendmode;

View file

@ -123,7 +123,7 @@ void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, const Vec4f &cli
args.stenciltestvalue = stencilValue;
args.stencilwritevalue = stencilValue;
args.SetTexture(tex);
args.SetColormap(GetColorTable(sub->sector->Colormap, sub->sector->SpecialColors[sector_t::sprites]));
args.SetColormap(GetColorTable(sub->sector->Colormap, sub->sector->SpecialColors[sector_t::sprites], true));
args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w);
args.subsectorTest = true;
args.writeSubsector = false;

View file

@ -64,10 +64,9 @@ struct FColormap
void CopyFrom3DLight(lightlist_t *light);
void Decolorize() // this for 'nocoloredspritelighting' and not the same as desaturation. The normal formula results in a value that's too dark.
void Decolorize()
{
int v = (LightColor.r + LightColor.g + LightColor.b) / 3;
LightColor.r = LightColor.g = LightColor.b = (255 + v + v) / 3;
LightColor.Decolorize();
}
bool operator == (const FColormap &other)

View file

@ -1,6 +1,7 @@
#pragma once
#include "g_levellocals.h"
struct FSWColormap
{
@ -46,9 +47,16 @@ void SetDefaultColormap (const char *name);
#endif
// MSVC needs the forceinline here.
FORCEINLINE FDynamicColormap *GetColorTable(const FColormap &cm, PalEntry SpecialColor = 0xffffff)
FORCEINLINE FDynamicColormap *GetColorTable(const FColormap &cm, PalEntry SpecialColor = 0xffffff, bool forsprites = false)
{
auto c = SpecialColor.Modulate(cm.LightColor);
PalEntry c;
if (!forsprites || !(level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING)) c = SpecialColor.Modulate(cm.LightColor);
else
{
c = cm.LightColor;
c.Decolorize();
c = SpecialColor.Modulate(c);
}
auto p = &NormalLight;
if (c == p->Color &&
cm.FadeColor == p->Fade &&

View file

@ -702,7 +702,7 @@ namespace swrenderer
ceilingplane = backupcp;
}
basecolormap = GetColorTable(frontsector->Colormap, frontsector->SpecialColors[sector_t::sprites]);
basecolormap = GetColorTable(frontsector->Colormap, frontsector->SpecialColors[sector_t::sprites], true);
floorlightlevel = fll;
ceilinglightlevel = cll;
@ -886,7 +886,7 @@ namespace swrenderer
{
int lightlevel = thing->Sector->GetTexture(sector_t::ceiling) == skyflatnum ? thing->Sector->GetCeilingLight() : thing->Sector->GetFloorLight();
thingShade = LightVisibility::LightLevelToShade(lightlevel + LightVisibility::ActualExtraLight(foggy, Thread->Viewport.get()), foggy);
thingColormap = GetColorTable(thing->Sector->Colormap, thing->Sector->SpecialColors[sector_t::sprites]);
thingColormap = GetColorTable(thing->Sector->Colormap, thing->Sector->SpecialColors[sector_t::sprites], true);
}
if ((sprite.renderflags & RF_SPRITETYPEMASK) == RF_WALLSPRITE)

View file

@ -148,7 +148,7 @@ namespace swrenderer
botplane = &heightsec->ceilingplane;
toppic = sector->GetTexture(sector_t::ceiling);
botpic = heightsec->GetTexture(sector_t::ceiling);
map = GetColorTable(heightsec->Colormap, heightsec->SpecialColors[sector_t::sprites]);
map = GetColorTable(heightsec->Colormap, heightsec->SpecialColors[sector_t::sprites], true);
}
else if (fakeside == WaterFakeSide::BelowFloor)
{
@ -156,7 +156,7 @@ namespace swrenderer
botplane = &sector->floorplane;
toppic = heightsec->GetTexture(sector_t::floor);
botpic = sector->GetTexture(sector_t::floor);
map = GetColorTable(heightsec->Colormap, heightsec->SpecialColors[sector_t::sprites]);
map = GetColorTable(heightsec->Colormap, heightsec->SpecialColors[sector_t::sprites], true);
}
else
{
@ -164,7 +164,7 @@ namespace swrenderer
botplane = &heightsec->floorplane;
toppic = heightsec->GetTexture(sector_t::ceiling);
botpic = heightsec->GetTexture(sector_t::floor);
map = GetColorTable(sector->Colormap, sector->SpecialColors[sector_t::sprites]);
map = GetColorTable(sector->Colormap, sector->SpecialColors[sector_t::sprites], true);
}
}
else
@ -173,7 +173,7 @@ namespace swrenderer
botplane = &sector->floorplane;
toppic = sector->GetTexture(sector_t::ceiling);
botpic = sector->GetTexture(sector_t::floor);
map = GetColorTable(sector->Colormap, sector->SpecialColors[sector_t::sprites]);
map = GetColorTable(sector->Colormap, sector->SpecialColors[sector_t::sprites], true);
}
if (botpic != skyflatnum && particle->Pos.Z < botplane->ZatPoint(particle->Pos))

View file

@ -103,9 +103,9 @@ namespace swrenderer
break;
sec = rover->model;
if (rover->flags & FF_FADEWALLS)
basecolormap = GetColorTable(sec->Colormap, sec->SpecialColors[sector_t::sprites]);
basecolormap = GetColorTable(sec->Colormap, sec->SpecialColors[sector_t::sprites], true);
else
basecolormap = GetColorTable(Thread->Viewport->viewpoint.sector->e->XFloor.lightlist[i].extra_colormap, sec->SpecialColors[sector_t::sprites]);
basecolormap = GetColorTable(Thread->Viewport->viewpoint.sector->e->XFloor.lightlist[i].extra_colormap, sec->SpecialColors[sector_t::sprites], true);
}
break;
}
@ -113,7 +113,7 @@ namespace swrenderer
if (!sec)
{
sec = Thread->Viewport->viewpoint.sector;
basecolormap = GetColorTable(sec->Colormap, sec->SpecialColors[sector_t::sprites]);
basecolormap = GetColorTable(sec->Colormap, sec->SpecialColors[sector_t::sprites], true);
}
floorlight = ceilinglight = sec->lightlevel;
}
@ -123,7 +123,7 @@ namespace swrenderer
sec = Thread->OpaquePass->FakeFlat(Thread->Viewport->viewpoint.sector, &tempsec, &floorlight, &ceilinglight, nullptr, 0, 0, 0, 0);
// [RH] set basecolormap
basecolormap = GetColorTable(sec->Colormap, sec->SpecialColors[sector_t::sprites]);
basecolormap = GetColorTable(sec->Colormap, sec->SpecialColors[sector_t::sprites], true);
}
// [RH] set foggy flag

View file

@ -113,11 +113,11 @@ namespace swrenderer
sec = rover->model;
if (rover->flags & FF_FADEWALLS)
{
mybasecolormap = GetColorTable(sec->Colormap, spr->sector->SpecialColors[sector_t::sprites]);
mybasecolormap = GetColorTable(sec->Colormap, spr->sector->SpecialColors[sector_t::sprites], true);
}
else
{
mybasecolormap = GetColorTable(spr->sector->e->XFloor.lightlist[i].extra_colormap, spr->sector->SpecialColors[sector_t::sprites]);
mybasecolormap = GetColorTable(spr->sector->e->XFloor.lightlist[i].extra_colormap, spr->sector->SpecialColors[sector_t::sprites], true);
}
}
break;