better slope light

This commit is contained in:
Alug committed 2024-08-17 16:09:43 +02:00
1 parent bab96b73e0
commit 87176cfd0b
4 files changed
+62 -26

No files matched your search

+5 -22
View File
@@ -607,35 +607,18 @@ static FUINT HWR_CalcWallLight(FUINT lightnum, seg_t *seg)
return (FUINT)finallight;
}
static FUINT HWR_CalcSlopeLight(FUINT lightnum, angle_t dir, fixed_t delta)
static FUINT HWR_CalcSlopeLight(FUINT lightnum, pslope_t *slope)
{
INT16 finallight = lightnum;
if (cv_grfakecontrast.value != 0 && cv_grslopecontrast.value != 0)
if (slope != NULL && cv_grfakecontrast.value != 0 && cv_grslopecontrast.value != 0)
{
const UINT8 contrast = 8;
fixed_t extralight = 0;
if (cv_grfakecontrast.value == 2) // Smooth setting
{
fixed_t dirmul = abs(FixedDiv(AngleFixed(dir) - (180<<FRACBITS), 180<<FRACBITS));
extralight = -(contrast<<FRACBITS) + (dirmul * (contrast * 2));
extralight = FixedMul(extralight, delta*4) >> FRACBITS;
}
extralight += slope->hwLightOffset;
else
{
dir = ((dir + ANGLE_45) / ANGLE_90) * ANGLE_90;
if (dir == ANGLE_180)
extralight = -contrast;
else if (dir == 0)
extralight = contrast;
if (delta >= FRACUNIT/2)
extralight *= 2;
}
extralight += slope->lightOffset * 8;
if (extralight != 0)
{
@@ -826,7 +809,7 @@ void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isc
SETUP3DVERT(v3d, pv->x, pv->y);
if (slope)
lightlevel = HWR_CalcSlopeLight(lightlevel, R_PointToAngle2(0, 0, slope->normal.x, slope->normal.y), abs(slope->zdelta));
lightlevel = HWR_CalcSlopeLight(lightlevel, slope);
HWR_Lighting(&Surf, lightlevel, planecolormap);
+46 -4
View File
@@ -27,11 +27,47 @@
static pslope_t *slopelist = NULL;
static UINT16 slopecount = 0;
// Calculate light
static void P_UpdateSlopeLightOffset(pslope_t *slope)
{
const boolean ceiling = (slope->normal.z < 0);
const UINT8 contrast = 8;
fixed_t contrastFixed = ((fixed_t)contrast) * FRACUNIT;
fixed_t zMul = FRACUNIT;
angle_t slopeDir = ANGLE_MAX;
fixed_t extralight = 0;
if (slope->normal.z == 0)
{
slope->lightOffset = slope->hwLightOffset = 0;
return;
}
slopeDir = R_PointToAngle2(0, 0, abs(slope->normal.y), abs(slope->normal.x));
if (ceiling == true)
{
slopeDir ^= ANGLE_180;
}
zMul = min(FRACUNIT, abs(slope->zdelta)*3/2); // *3/2, to make 60 degree slopes match walls.
contrastFixed = FixedMul(contrastFixed, zMul);
extralight = -contrastFixed + FixedMul(FixedDiv(AngleFixed(slopeDir), 90*FRACUNIT), (contrastFixed * 2));
// Between -2 and 2 for software, -8 and 8 for hardware
slope->lightOffset = FixedFloor((extralight / 8) + (FRACUNIT / 2)) / FRACUNIT;
#ifdef HWRENDER
slope->hwLightOffset = FixedFloor(extralight + (FRACUNIT / 2)) / FRACUNIT;
#endif
}
// Calculate line normal
void P_CalculateSlopeNormal(pslope_t *slope) {
slope->normal.z = FINECOSINE(slope->zangle>>ANGLETOFINESHIFT);
slope->normal.x = -FixedMul(FINESINE(slope->zangle>>ANGLETOFINESHIFT), -slope->d.x);
slope->normal.y = -FixedMul(FINESINE(slope->zangle>>ANGLETOFINESHIFT), -slope->d.y);
P_UpdateSlopeLightOffset(slope);
}
// With a vertex slope that has its vertices set, configure relevant slope info
@@ -89,14 +125,19 @@ static void P_ReconfigureVertexSlope(pslope_t *slope)
slope->real_xydirection = R_PointToAngle2(0, 0, slope->d.x, slope->d.y)+ANGLE_180;
slope->real_zangle = InvAngle(R_PointToAngle2(0, 0, FRACUNIT, slope->zdelta));
if (slope->normal.x == 0 && slope->normal.y == 0) { // Set some defaults for a non-sloped "slope"
if (slope->normal.x == 0 && slope->normal.y == 0) // Set some defaults for a non-sloped "slope"
{
slope->zangle = slope->xydirection = 0;
slope->zdelta = slope->d.x = slope->d.y = 0;
} else {
}
else
{
slope->extent = extent;
slope->xydirection = slope->real_xydirection;
slope->zangle = slope->real_zangle;
}
P_UpdateSlopeLightOffset(slope);
}
// Recalculate dynamic slopes
@@ -369,7 +410,8 @@ void P_SpawnSlope_Line(int linenum)
P_CalculateSlopeNormal(fslope);
}
if(frontceil)
if (frontceil)
{
fixed_t highest, lowest;
size_t l;
@@ -934,4 +976,4 @@ void P_ButteredSlope(mobj_t *mo)
P_Thrust(mo, mo->standingslope->xydirection, thrust);
}
// EOF
// EOF
+6
View File
@@ -257,6 +257,12 @@ typedef struct pslope_s
mapthing_t **vertices; // List should be three long for slopes made by vertex things, or one long for slopes using one vertex thing to anchor
struct pslope_s *next; // Make a linked list of dynamic slopes, for easy reference later
// Light offsets (see seg_t)
SINT8 lightOffset;
#ifdef HWRENDER
INT16 hwLightOffset;
#endif
} pslope_t;
typedef enum
+5
View File
@@ -419,6 +419,11 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel,
}
}
if (slope != NULL)
{
lightlevel += (slope->lightOffset / 8);
}
// This appears to fix the Nimbus Ruins sky bug.
if (picnum == skyflatnum && pfloor)
{