Plane lighting for slopes now actually acts like it should

This commit is contained in:
RedEnchilada 2015-05-13 21:41:54 -05:00
parent 2187dac49b
commit 0cc917a0ff
5 changed files with 67 additions and 27 deletions

View File

@ -106,7 +106,7 @@ UINT8 *ds_transmap; // one of the translucency tables
#ifdef ESLOPE #ifdef ESLOPE
pslope_t *ds_slope; // Current slope being used pslope_t *ds_slope; // Current slope being used
v3float_t ds_su, ds_sv, ds_sz; // Vectors for... stuff? v3float_t ds_su, ds_sv, ds_sz; // Vectors for... stuff?
float focallengthf; float focallengthf, zeroheight;
#endif #endif
/** \brief Variable flat sizes /** \brief Variable flat sizes

View File

@ -63,7 +63,7 @@ extern UINT8 *ds_transmap;
#ifdef ESLOPE #ifdef ESLOPE
pslope_t *ds_slope; // Current slope being used pslope_t *ds_slope; // Current slope being used
v3float_t ds_su, ds_sv, ds_sz; // Vectors for... stuff? v3float_t ds_su, ds_sv, ds_sz; // Vectors for... stuff?
float focallengthf; float focallengthf, zeroheight;
#endif #endif
// Variable flat sizes // Variable flat sizes

View File

@ -527,6 +527,30 @@ void R_DrawSpan_8 (void)
} }
#ifdef ESLOPE #ifdef ESLOPE
// R_CalcTiltedLighting
// Exactly what it says on the tin. I wish I wasn't too lazy to explain things properly.
static size_t tiltlighting[MAXVIDWIDTH];
void R_CalcTiltedLighting(fixed_t start, fixed_t end)
{
// ZDoom uses a different lighting setup to us, and I couldn't figure out how to adapt their version
// of this function. Here's my own.
INT32 left = ds_x1, right = ds_x2;
fixed_t step = (end-start)/(ds_x2-ds_x1+1);
size_t i;
// I wanna do some optimizing by checking for out-of-range segments on either side to fill in all at once,
// but I'm too bad at coding to not crash the game trying to do that. I guess this is fast enough for now...
for (i = left; i <= right; i++) {
tiltlighting[i] = (start += step) >> FRACBITS;
if (tiltlighting[i] < 0)
tiltlighting[i] = 0;
else if (tiltlighting[i] >= MAXLIGHTSCALE)
tiltlighting[i] = MAXLIGHTSCALE-1;
}
}
/** \brief The R_DrawTiltedSpan_8 function /** \brief The R_DrawTiltedSpan_8 function
Draw slopes! Holy sheit! Draw slopes! Holy sheit!
*/ */
@ -544,12 +568,24 @@ void R_DrawTiltedSpan_8(void)
iz = ds_sz.z + ds_sz.y*(centery-ds_y) + ds_sz.x*(ds_x1-centerx); iz = ds_sz.z + ds_sz.y*(centery-ds_y) + ds_sz.x*(ds_x1-centerx);
// Lighting is simple. It's just linear interpolation from start to end
{
float planelightfloat = BASEVIDWIDTH*BASEVIDWIDTH/vid.width / (fabs(zeroheight - FIXED_TO_FLOAT(viewz))) / -21.0f;
float lightstart, lightend;
lightend = (iz + ds_sz.x*width) * planelightfloat;
lightstart = iz * planelightfloat;
R_CalcTiltedLighting(FLOAT_TO_FIXED(lightstart), FLOAT_TO_FIXED(lightend));
//CONS_Printf("tilted lighting %f to %f (foc %f)\n", vz, uz, focallengthf);
}
uz = ds_su.z + ds_su.y*(centery-ds_y) + ds_su.x*(ds_x1-centerx); uz = ds_su.z + ds_su.y*(centery-ds_y) + ds_su.x*(ds_x1-centerx);
vz = ds_sv.z + ds_sv.y*(centery-ds_y) + ds_sv.x*(ds_x1-centerx); vz = ds_sv.z + ds_sv.y*(centery-ds_y) + ds_sv.x*(ds_x1-centerx);
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds_y] + columnofs[ds_x1];
source = ds_source; source = ds_source;
colormap = ds_colormap; //colormap = ds_colormap;
#if 0 // The "perfect" reference version of this routine. Pretty slow. #if 0 // The "perfect" reference version of this routine. Pretty slow.
// Use it only to see how things are supposed to look. // Use it only to see how things are supposed to look.
@ -559,6 +595,9 @@ void R_DrawTiltedSpan_8(void)
double z = 1.f/iz; double z = 1.f/iz;
u = (INT64)(uz*z) + viewx; u = (INT64)(uz*z) + viewx;
v = (INT64)(vz*z) + viewy; v = (INT64)(vz*z) + viewy;
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps);
*dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]]; *dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]];
dest++; dest++;
iz += ds_sz.x; iz += ds_sz.x;
@ -596,6 +635,7 @@ void R_DrawTiltedSpan_8(void)
for (i = SPANSIZE-1; i >= 0; i--) for (i = SPANSIZE-1; i >= 0; i--)
{ {
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps);
*dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]]; *dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]];
dest++; dest++;
u += stepu; u += stepu;
@ -611,6 +651,7 @@ void R_DrawTiltedSpan_8(void)
{ {
u = (INT64)(startu); u = (INT64)(startu);
v = (INT64)(startv); v = (INT64)(startv);
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps);
*dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]]; *dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]];
} }
else else
@ -631,6 +672,7 @@ void R_DrawTiltedSpan_8(void)
for (; width != 0; width--) for (; width != 0; width--)
{ {
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps);
*dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]]; *dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]];
dest++; dest++;
u += stepu; u += stepu;

View File

@ -74,7 +74,7 @@ static INT32 spanstart[MAXVIDHEIGHT];
// //
// texture mapping // texture mapping
// //
static lighttable_t **planezlight; lighttable_t **planezlight;
static fixed_t planeheight; static fixed_t planeheight;
//added : 10-02-98: yslopetab is what yslope used to be, //added : 10-02-98: yslopetab is what yslope used to be,
@ -327,6 +327,11 @@ void R_MapPlane(INT32 y, INT32 x1, INT32 x2)
if (pindex >= MAXLIGHTZ) if (pindex >= MAXLIGHTZ)
pindex = MAXLIGHTZ - 1; pindex = MAXLIGHTZ - 1;
#ifdef ESLOPE
if (currentplane->slope)
ds_colormap = colormaps;
else
#endif
ds_colormap = planezlight[pindex]; ds_colormap = planezlight[pindex];
if (currentplane->extra_colormap) if (currentplane->extra_colormap)
@ -919,24 +924,23 @@ void R_DrawSinglePlane(visplane_t *pl)
break; break;
} }
xoffs = pl->xoffs;
yoffs = pl->yoffs;
planeheight = abs(pl->height - pl->viewz);
if (light >= LIGHTLEVELS)
light = LIGHTLEVELS-1;
if (light < 0)
light = 0;
#ifdef ESLOPE #ifdef ESLOPE
if (pl->slope) { if (pl->slope) {
// Potentially override other stuff for now cus we're mean. :< But draw a slope plane! // Potentially override other stuff for now cus we're mean. :< But draw a slope plane!
// I copied ZDoom's code and adapted it to SRB2... -Red // I copied ZDoom's code and adapted it to SRB2... -Red
static const float ifloatpow2[16] =
{
// ifloatpow2[i] = 1 / (1 << i)
64.f, 32.f, 16.f, 8.f, 4.f, 2.f, 1.f, 0.5f,
0.25f, 0.125f, 0.0625f, 0.03125f, 0.015625f, 0.0078125f,
0.00390625f, 0.001953125f
/*, 0.0009765625f, 0.00048828125f, 0.000244140625f,
1.220703125e-4f, 6.103515625e-5, 3.0517578125e-5*/
};
double lxscale, lyscale;
double xscale, yscale;
v3float_t p, m, n; v3float_t p, m, n;
angle_t ang; angle_t ang;
double zeroheight; //double zeroheight;
double vx = FIXED_TO_FLOAT(viewx); double vx = FIXED_TO_FLOAT(viewx);
double vy = FIXED_TO_FLOAT(viewy); double vy = FIXED_TO_FLOAT(viewy);
@ -986,19 +990,11 @@ void R_DrawSinglePlane(visplane_t *pl)
#undef SFMULT #undef SFMULT
spanfunc = R_DrawTiltedSpan_8; spanfunc = R_DrawTiltedSpan_8;
}
planezlight = scalelight[light];
} else
#endif // ESLOPE #endif // ESLOPE
xoffs = pl->xoffs;
yoffs = pl->yoffs;
planeheight = abs(pl->height - pl->viewz);
if (light >= LIGHTLEVELS)
light = LIGHTLEVELS-1;
if (light < 0)
light = 0;
planezlight = zlight[light]; planezlight = zlight[light];
// set the maximum value for unsigned // set the maximum value for unsigned

View File

@ -82,6 +82,8 @@ extern fixed_t cachedxstep[MAXVIDHEIGHT];
extern fixed_t cachedystep[MAXVIDHEIGHT]; extern fixed_t cachedystep[MAXVIDHEIGHT];
extern fixed_t basexscale, baseyscale; extern fixed_t basexscale, baseyscale;
extern lighttable_t **planezlight;
extern fixed_t *yslope; extern fixed_t *yslope;
extern fixed_t distscale[MAXVIDWIDTH]; extern fixed_t distscale[MAXVIDWIDTH];