Implement directional lighting

(Sloped ceilings are reversed and not sure what to do about it)
This commit is contained in:
Sally Coolatta 2022-05-25 02:51:08 -04:00
parent b6ed17d9fc
commit ec02e75f0d
5 changed files with 56 additions and 19 deletions

View file

@ -292,6 +292,9 @@ static FUINT HWR_CalcWallLight(FUINT lightnum, seg_t *seg)
if (seg != NULL && P_ApplyLightOffset(lightnum)) if (seg != NULL && P_ApplyLightOffset(lightnum))
{ {
finallight += seg->hwLightOffset; finallight += seg->hwLightOffset;
if (finallight > 255) finallight = 255;
if (finallight < 0) finallight = 0;
} }
return (FUINT)finallight; return (FUINT)finallight;
@ -303,7 +306,10 @@ static FUINT HWR_CalcSlopeLight(FUINT lightnum, pslope_t *slope)
if (slope != NULL && P_ApplyLightOffset(lightnum)) if (slope != NULL && P_ApplyLightOffset(lightnum))
{ {
finallight += slope->lightOffset; finallight += slope->hwLightOffset;
if (finallight > 255) finallight = 255;
if (finallight < 0) finallight = 0;
} }
return (FUINT)finallight; return (FUINT)finallight;

View file

@ -413,7 +413,7 @@ static void P_ClearSingleMapHeaderInfo(INT16 i)
mapheaderinfo[num]->menuflags = 0; mapheaderinfo[num]->menuflags = 0;
mapheaderinfo[num]->mobj_scale = FRACUNIT; mapheaderinfo[num]->mobj_scale = FRACUNIT;
mapheaderinfo[num]->default_waypoint_radius = 0; mapheaderinfo[num]->default_waypoint_radius = 0;
mapheaderinfo[num]->light_contrast = 0; mapheaderinfo[num]->light_contrast = 16;
mapheaderinfo[num]->use_light_angle = false; mapheaderinfo[num]->use_light_angle = false;
mapheaderinfo[num]->light_angle = 0; mapheaderinfo[num]->light_angle = 0;
#if 1 // equivalent to "FlickyList = DEMO" #if 1 // equivalent to "FlickyList = DEMO"
@ -2326,12 +2326,24 @@ static inline float P_SegLengthFloat(seg_t *seg)
void P_UpdateSegLightOffset(seg_t *li) void P_UpdateSegLightOffset(seg_t *li)
{ {
const UINT8 contrast = maplighting.contrast; const UINT8 contrast = maplighting.contrast;
const fixed_t contrastFixed = ((fixed_t)contrast) * FRACUNIT;
fixed_t light = FRACUNIT;
fixed_t extralight = 0; fixed_t extralight = 0;
extralight = -((fixed_t)contrast*FRACUNIT) + if (maplighting.directional == true)
FixedDiv(AngleFixed(R_PointToAngle2(0, 0, {
abs(li->v1->x - li->v2->x), angle_t liAngle = R_PointToAngle2(0, 0, (li->v1->x - li->v2->x), (li->v1->y - li->v2->y)) - ANGLE_90;
abs(li->v1->y - li->v2->y))), 90*FRACUNIT) * ((fixed_t)contrast * 2);
light = FixedMul(FINECOSINE(liAngle >> ANGLETOFINESHIFT), FINECOSINE(maplighting.angle >> ANGLETOFINESHIFT))
+ FixedMul(FINESINE(liAngle >> ANGLETOFINESHIFT), FINESINE(maplighting.angle >> ANGLETOFINESHIFT));
light = (light + FRACUNIT) / 2;
}
else
{
light = FixedDiv(R_PointToAngle2(0, 0, abs(li->v1->x - li->v2->x), abs(li->v1->y - li->v2->y)), ANGLE_90);
}
extralight = -contrastFixed + FixedMul(light, contrastFixed * 2);
// Between -2 and 2 for software, -16 and 16 for hardware // Between -2 and 2 for software, -16 and 16 for hardware
li->lightOffset = FixedFloor((extralight / 8) + (FRACUNIT / 2)) / FRACUNIT; li->lightOffset = FixedFloor((extralight / 8) + (FRACUNIT / 2)) / FRACUNIT;

View file

@ -34,32 +34,49 @@ static void P_SetupAnchoredSlopes (void);
// Calculate light // Calculate light
void P_UpdateSlopeLightOffset(pslope_t *slope) void P_UpdateSlopeLightOffset(pslope_t *slope)
{ {
const boolean ceiling = (slope->normal.z < 0);
const UINT8 contrast = maplighting.contrast; const UINT8 contrast = maplighting.contrast;
fixed_t contrastFixed = (contrast * FRACUNIT); fixed_t contrastFixed = ((fixed_t)contrast) * FRACUNIT;
fixed_t zMul = FRACUNIT; fixed_t zMul = FRACUNIT;
angle_t slopeDir = ANGLE_MAX; fixed_t light = FRACUNIT;
fixed_t extralight = 0; fixed_t extralight = 0;
if (slope->normal.z == 0) if (slope->normal.z == 0)
{ {
slope->lightOffset = 0; slope->lightOffset = slope->hwLightOffset = 0;
return; return;
} }
slopeDir = R_PointToAngle2(0, 0, abs(slope->normal.y), abs(slope->normal.x)); if (maplighting.directional == true)
if (ceiling == true)
{ {
slopeDir ^= ANGLE_180; fixed_t dX = slope->d.x;
fixed_t dY = slope->d.y;
if (slope->zdelta < 0)
{
dX = -dX;
dY = -dY;
}
light = FixedMul(dX, FINECOSINE(maplighting.angle >> ANGLETOFINESHIFT))
+ FixedMul(dY, FINESINE(maplighting.angle >> ANGLETOFINESHIFT));
light = (light + FRACUNIT) / 2;
}
else
{
light = FixedDiv(R_PointToAngle2(0, 0, abs(slope->d.x), abs(slope->d.y)), ANGLE_90);
} }
zMul = min(FRACUNIT, abs(slope->zdelta)*3/2); // *3/2, to make 60 degree slopes match walls. zMul = min(FRACUNIT, abs(slope->zdelta)*3/2); // *3/2, to make 60 degree slopes match walls.
contrastFixed = FixedMul(contrastFixed, zMul); contrastFixed = FixedMul(contrastFixed, zMul);
extralight = -contrastFixed + FixedMul(FixedDiv(AngleFixed(slopeDir), 90*FRACUNIT), (contrastFixed * 2));
// -16 and 16 for both software & hardware extralight = -contrastFixed + FixedMul(light, contrastFixed * 2);
slope->lightOffset = FixedFloor(extralight + (FRACUNIT / 2)) / FRACUNIT;
// Between -2 and 2 for software, -16 and 16 for hardware
slope->lightOffset = FixedFloor((extralight / 8) + (FRACUNIT / 2)) / FRACUNIT;
#ifdef HWRENDER
slope->hwLightOffset = FixedFloor(extralight + (FRACUNIT / 2)) / FRACUNIT;
#endif
} }
// Calculate line normal // Calculate line normal

View file

@ -253,7 +253,10 @@ typedef struct pslope_s
fixed_t highz; fixed_t highz;
// Light offsets (see seg_t) // Light offsets (see seg_t)
INT16 lightOffset; SINT8 lightOffset;
#ifdef HWRENDER
INT16 hwLightOffset;
#endif
} pslope_t; } pslope_t;
typedef enum typedef enum

View file

@ -388,8 +388,7 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel,
if (slope != NULL && P_ApplyLightOffset(lightlevel)) if (slope != NULL && P_ApplyLightOffset(lightlevel))
{ {
// for software: crunchitize the light level offset, otherwise it's too bright. lightlevel += slope->lightOffset * 8;
lightlevel += (slope->lightOffset / 8) * 8;
} }
// This appears to fix the Nimbus Ruins sky bug. // This appears to fix the Nimbus Ruins sky bug.