mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-01-10 00:34:32 +00:00
Add/sub fog
Makes it consistent with the subtractive lighting I was working on... the big benefit is that no saturation is lost when blending to white or black. Has a few maps this looks worse on, though.
This commit is contained in:
parent
c7783945ca
commit
c95684198d
1 changed files with 36 additions and 17 deletions
53
src/r_data.c
53
src/r_data.c
|
|
@ -623,13 +623,13 @@ extracolormap_t *R_ColormapForName(char *name)
|
|||
// custom colormaps at runtime. NOTE: For GL mode, we only need to color
|
||||
// data and not the colormap data.
|
||||
//
|
||||
static double deltas[256][3], map[256][3];
|
||||
static double brightChange[256], map[256][3];
|
||||
|
||||
static int RoundUp(double number);
|
||||
|
||||
lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap)
|
||||
{
|
||||
double cmaskr, cmaskg, cmaskb, cdestr, cdestg, cdestb;
|
||||
double cmaskr, cmaskg, cmaskb, cdestr, cdestg, cdestb, cdestbright;
|
||||
double maskamt = 0, othermask = 0;
|
||||
|
||||
UINT8 cr = R_GetRgbaR(extra_colormap->rgba),
|
||||
|
|
@ -668,6 +668,7 @@ lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap)
|
|||
cdestr = cfr;
|
||||
cdestg = cfg;
|
||||
cdestb = cfb;
|
||||
cdestbright = sqrt((cfr*cfr) + (cfg*cfg) + (cfb*cfb));
|
||||
|
||||
// fade alpha unused in software
|
||||
// maskamt = (double)(cfa/24.0l);
|
||||
|
|
@ -682,7 +683,7 @@ lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap)
|
|||
// This code creates the colormap array used by software renderer
|
||||
/////////////////////
|
||||
{
|
||||
double r, g, b, cbrightness;
|
||||
double r, g, b, cbrightness, cbest;
|
||||
int p;
|
||||
lighttable_t *colormap_p;
|
||||
|
||||
|
|
@ -701,17 +702,28 @@ lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap)
|
|||
map[i][0] = (cbrightness * cmaskr) + (r * othermask);
|
||||
if (map[i][0] > 255.0l)
|
||||
map[i][0] = 255.0l;
|
||||
deltas[i][0] = (map[i][0] - cdestr) / (double)fadedist;
|
||||
|
||||
map[i][1] = (cbrightness * cmaskg) + (g * othermask);
|
||||
if (map[i][1] > 255.0l)
|
||||
map[i][1] = 255.0l;
|
||||
deltas[i][1] = (map[i][1] - cdestg) / (double)fadedist;
|
||||
|
||||
map[i][2] = (cbrightness * cmaskb) + (b * othermask);
|
||||
if (map[i][2] > 255.0l)
|
||||
map[i][2] = 255.0l;
|
||||
deltas[i][2] = (map[i][2] - cdestb) / (double)fadedist;
|
||||
|
||||
// Get the "best" color.
|
||||
// Our brightest color's value, if we're fading to a darker color,
|
||||
// or our (inverted) darkest color's value, if we're fading to a brighter color.
|
||||
if (cbrightness < cdestbright)
|
||||
{
|
||||
cbest = 255.0l - min(r, min(g, b));
|
||||
}
|
||||
else
|
||||
{
|
||||
cbest = max(r, max(g, b));
|
||||
}
|
||||
|
||||
brightChange[i] = abs(cbest - cdestbright) / (double)fadedist;
|
||||
}
|
||||
|
||||
// Now allocate memory for the actual colormap array itself!
|
||||
|
|
@ -732,22 +744,29 @@ lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap)
|
|||
|
||||
if ((UINT32)p < fadestart)
|
||||
continue;
|
||||
#define ABS2(x) ((x) < 0 ? -(x) : (x))
|
||||
if (ABS2(map[i][0] - cdestr) > ABS2(deltas[i][0]))
|
||||
map[i][0] -= deltas[i][0];
|
||||
else
|
||||
|
||||
// Add/subtract towards the destination color.
|
||||
if (abs(map[i][0] - cdestr) <= brightChange[i])
|
||||
map[i][0] = cdestr;
|
||||
|
||||
if (ABS2(map[i][1] - cdestg) > ABS2(deltas[i][1]))
|
||||
map[i][1] -= deltas[i][1];
|
||||
else if (map[i][0] > cdestr)
|
||||
map[i][0] -= brightChange[i];
|
||||
else
|
||||
map[i][0] += brightChange[i];
|
||||
|
||||
|
||||
if (abs(map[i][1] - cdestg) <= brightChange[i])
|
||||
map[i][1] = cdestg;
|
||||
|
||||
if (ABS2(map[i][2] - cdestb) > ABS2(deltas[i][1]))
|
||||
map[i][2] -= deltas[i][2];
|
||||
else if (map[i][1] > cdestg)
|
||||
map[i][1] -= brightChange[i];
|
||||
else
|
||||
map[i][1] += brightChange[i];
|
||||
|
||||
if (abs(map[i][2] - cdestb) <= brightChange[i])
|
||||
map[i][2] = cdestb;
|
||||
#undef ABS2
|
||||
else if (map[i][2] > cdestb)
|
||||
map[i][2] -= brightChange[i];
|
||||
else
|
||||
map[i][2] += brightChange[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue