Merge branch 'fake-contrast-2-electric-boogaloo' into 'master'

Fake contrast 2: Electric Boogaloo

See merge request KartKrew/Kart!267
This commit is contained in:
Sryder 2020-05-21 19:08:30 -04:00
commit 7132eeab48
7 changed files with 72 additions and 64 deletions

View file

@ -223,40 +223,27 @@ UINT8 HWR_FogBlockAlpha(INT32 light, extracolormap_t *colormap) // Let's see if
return surfcolor.s.alpha;
}
static FUINT HWR_CalcWallLight(FUINT lightnum, fixed_t v1x, fixed_t v1y, fixed_t v2x, fixed_t v2y)
// Lightnum = current light
// line = the seg to get the light offset from
static FUINT HWR_CalcWallLight(seg_t *line, FUINT lightnum)
{
INT16 finallight = lightnum;
if (cv_grfakecontrast.value != 0)
fixed_t extralight = 0;
if (cv_grfakecontrast.value == 1) // Smooth setting
extralight += line->hwLightOffset;
else
extralight += line->lightOffset * 8;
if (extralight != 0)
{
const UINT8 contrast = 8;
fixed_t extralight = 0;
finallight += extralight;
if (cv_grfakecontrast.value == 2) // Smooth setting
{
extralight = (-(contrast<<FRACBITS) +
FixedDiv(AngleFixed(R_PointToAngle2(0, 0,
abs(v1x - v2x),
abs(v1y - v2y))), 90<<FRACBITS)
* (contrast * 2)) >> FRACBITS;
}
else
{
if (v1y == v2y)
extralight = -contrast;
else if (v1x == v2x)
extralight = contrast;
}
if (extralight != 0)
{
finallight += extralight;
if (finallight < 0)
finallight = 0;
if (finallight > 255)
finallight = 255;
}
if (finallight < 0)
finallight = 0;
if (finallight > 255)
finallight = 255;
}
return (FUINT)finallight;
@ -618,7 +605,7 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa
INT32 solid, i;
lightlist_t * list = sector->lightlist;
const UINT8 alpha = Surf->PolyColor.s.alpha;
FUINT lightnum = HWR_CalcWallLight(sector->lightlevel, v1x, v1y, v2x, v2y);
FUINT lightnum = HWR_CalcWallLight(gr_curline, sector->lightlevel);
extracolormap_t *colormap = NULL;
realtop = top = wallVerts[3].y;
@ -647,12 +634,12 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa
{
if (pfloor && (pfloor->flags & FF_FOG))
{
lightnum = HWR_CalcWallLight(pfloor->master->frontsector->lightlevel, v1x, v1y, v2x, v2y);
lightnum = HWR_CalcWallLight(gr_curline, pfloor->master->frontsector->lightlevel);
colormap = pfloor->master->frontsector->extra_colormap;
}
else
{
lightnum = HWR_CalcWallLight(*list[i].lightlevel, v1x, v1y, v2x, v2y);
lightnum = HWR_CalcWallLight(gr_curline, *list[i].lightlevel);
colormap = list[i].extra_colormap;
}
}
@ -933,7 +920,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom
cliphigh = (float)(texturehpeg + (gr_curline->flength*FRACUNIT));
}
lightnum = HWR_CalcWallLight(gr_frontsector->lightlevel, vs.x, vs.y, ve.x, ve.y);
lightnum = HWR_CalcWallLight(gr_curline, gr_frontsector->lightlevel);
colormap = gr_frontsector->extra_colormap;
if (gr_frontsector)
@ -1759,7 +1746,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom
blendmode = PF_Fog|PF_NoTexture;
lightnum = HWR_CalcWallLight(rover->master->frontsector->lightlevel, vs.x, vs.y, ve.x, ve.y);
lightnum = HWR_CalcWallLight(gr_curline, rover->master->frontsector->lightlevel);
colormap = rover->master->frontsector->extra_colormap;
Surf.PolyColor.s.alpha = HWR_FogBlockAlpha(rover->master->frontsector->lightlevel, rover->master->frontsector->extra_colormap);
@ -1871,7 +1858,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom
blendmode = PF_Fog|PF_NoTexture;
lightnum = HWR_CalcWallLight(rover->master->frontsector->lightlevel, vs.x, vs.y, ve.x, ve.y);
lightnum = HWR_CalcWallLight(gr_curline, rover->master->frontsector->lightlevel);
colormap = rover->master->frontsector->extra_colormap;
Surf.PolyColor.s.alpha = HWR_FogBlockAlpha(rover->master->frontsector->lightlevel, rover->master->frontsector->extra_colormap);
@ -3596,10 +3583,10 @@ static int CompareVisSprites(const void *p1, const void *p2)
gr_vissprite_t* spr2 = *(gr_vissprite_t*const*)p2;
int idiff;
float fdiff;
// make transparent sprites last
// "boolean to int"
int transparency1 = (spr1->mobj->flags2 & MF2_SHADOW) || (spr1->mobj->frame & FF_TRANSMASK);
int transparency2 = (spr2->mobj->flags2 & MF2_SHADOW) || (spr2->mobj->frame & FF_TRANSMASK);
idiff = transparency1 - transparency2;

View file

@ -1407,7 +1407,10 @@ static boolean Polyobj_rotate(polyobj_t *po, angle_t delta, UINT8 turnthings)
{
// update seg angles (used only by renderer)
for (i = 0; i < po->segCount; ++i)
{
po->segs[i]->angle += delta;
P_UpdateSegLightOffset(po->segs[i]);
}
// update polyobject's angle
po->angle += delta;

View file

@ -446,6 +446,27 @@ static inline float P_SegLengthFloat(seg_t *seg)
}
#endif
/** Updates the light offset
*
* \param li Seg to update the light offsets of
*/
void P_UpdateSegLightOffset(seg_t *li)
{
const UINT8 contrast = 16;
fixed_t extralight = 0;
extralight = -((fixed_t)contrast*FRACUNIT) +
FixedDiv(AngleFixed(R_PointToAngle2(0, 0,
abs(li->v1->x - li->v2->x),
abs(li->v1->y - li->v2->y))), 90*FRACUNIT) * ((fixed_t)contrast * 2);
// Between -2 and 2 for software, -16 and 16 for hardware
li->lightOffset = FixedFloor((extralight / 8) + (FRACUNIT / 2)) / FRACUNIT;
#ifdef HWRENDER
li->hwLightOffset = FixedFloor(extralight + (FRACUNIT / 2)) / FRACUNIT;
#endif
}
/** Loads the SEGS resource from a level.
*
* \param lump Lump number of the SEGS resource.
@ -492,6 +513,8 @@ static void P_LoadRawSegs(UINT8 *data, size_t i)
li->numlights = 0;
li->rlights = NULL;
P_UpdateSegLightOffset(li);
}
}
@ -1091,7 +1114,7 @@ static void P_LoadThings(void)
|| mt->type == 1705 || mt->type == 1713 || mt->type == 1800)
{
sector_t *mtsector = R_PointInSubsector(mt->x << FRACBITS, mt->y << FRACBITS)->sector;
mt->mobj = NULL;
// Z for objects

View file

@ -66,6 +66,7 @@ boolean P_DelWadFile(void);
#endif
boolean P_RunSOC(const char *socfilename);
void P_WriteThings(lumpnum_t lump);
void P_UpdateSegLightOffset(seg_t *li);
size_t P_PrecacheLevelFlats(void);
void P_AllocMapHeader(INT16 i);

View file

@ -565,6 +565,12 @@ typedef struct seg_s
polyobj_t *polyseg;
boolean dontrenderme;
#endif
// Fake contrast calculated on level load
SINT8 lightOffset;
#ifdef HWRENDER
INT16 hwLightOffset;
#endif
} seg_t;
//

View file

@ -412,10 +412,8 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2)
if (rlight->extra_colormap && rlight->extra_colormap->fog)
;
else if (curline->v1->y == curline->v2->y)
lightnum--;
else if (curline->v1->x == curline->v2->x)
lightnum++;
else
lightnum += curline->lightOffset;
rlight->lightnum = lightnum;
}
@ -435,10 +433,8 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2)
if (colfunc == R_DrawFogColumn_8
|| (frontsector->extra_colormap && frontsector->extra_colormap->fog))
;
else if (curline->v1->y == curline->v2->y)
lightnum--;
else if (curline->v1->x == curline->v2->x)
lightnum++;
else
lightnum += curline->lightOffset;
if (lightnum < 0)
walllights = scalelight[0];
@ -932,10 +928,8 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor)
if (pfloor->flags & FF_FOG || rlight->flags & FF_FOG || (rlight->extra_colormap && rlight->extra_colormap->fog))
;
else if (curline->v1->y == curline->v2->y)
rlight->lightnum--;
else if (curline->v1->x == curline->v2->x)
rlight->lightnum++;
else
rlight->lightnum += curline->lightOffset;
p++;
}
@ -955,11 +949,10 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor)
lightnum = R_FakeFlat(frontsector, &tempsec, &templight, &templight, false)
->lightlevel >> LIGHTSEGSHIFT;
if (pfloor->flags & FF_FOG || (frontsector->extra_colormap && frontsector->extra_colormap->fog));
else if (curline->v1->y == curline->v2->y)
lightnum--;
else if (curline->v1->x == curline->v2->x)
lightnum++;
if (pfloor->flags & FF_FOG || (frontsector->extra_colormap && frontsector->extra_colormap->fog))
;
else
lightnum += curline->lightOffset;
if (lightnum < 0)
walllights = scalelight[0];
@ -1492,10 +1485,8 @@ static void R_RenderSegLoop (void)
if (dc_lightlist[i].extra_colormap)
;
else if (curline->v1->y == curline->v2->y)
lightnum--;
else if (curline->v1->x == curline->v2->x)
lightnum++;
else
lightnum += curline->lightOffset;
if (lightnum < 0)
xwalllights = scalelight[0];
@ -2639,10 +2630,7 @@ void R_StoreWallRange(INT32 start, INT32 stop)
// OPTIMIZE: get rid of LIGHTSEGSHIFT globally
lightnum = (frontsector->lightlevel >> LIGHTSEGSHIFT);
if (curline->v1->y == curline->v2->y)
lightnum--;
else if (curline->v1->x == curline->v2->x)
lightnum++;
lightnum += curline->lightOffset;
if (lightnum < 0)
walllights = scalelight[0];

View file

@ -84,7 +84,7 @@ static void CV_Gammaxxx_ONChange(void);
// - You can change them in software,
// but they won't do anything.
static CV_PossibleValue_t grgamma_cons_t[] = {{1, "MIN"}, {255, "MAX"}, {0, NULL}};
static CV_PossibleValue_t grfakecontrast_cons_t[] = {{0, "Off"}, {1, "Standard"}, {2, "Smooth"}, {0, NULL}};
static CV_PossibleValue_t grfakecontrast_cons_t[] = {{0, "Standard"}, {1, "Smooth"}, {0, NULL}};
consvar_t cv_grshaders = {"gr_shaders", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
consvar_t cv_grfovchange = {"gr_fovchange", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};