diff --git a/src/crispy.c b/src/crispy.c index 10b21443b..e2544d498 100644 --- a/src/crispy.c +++ b/src/crispy.c @@ -29,6 +29,7 @@ static crispy_t crispy_s = { .smoothscaling = 1, .soundfix = 1, #ifdef CRISPY_TRUECOLOR + .smoothlight = 1, .truecolor = 1, #endif .vsync = 1, diff --git a/src/doom/m_crispy.c b/src/doom/m_crispy.c index c9e67036c..3fcced9a0 100644 --- a/src/doom/m_crispy.c +++ b/src/doom/m_crispy.c @@ -516,6 +516,10 @@ static void M_CrispyToggleSmoothLightingHook (void) { crispy->smoothlight = !crispy->smoothlight; +#ifdef CRISPY_TRUECOLOR + // [crispy] re-calculate amount of colormaps and light tables + R_InitColormaps(); +#endif // [crispy] re-calculate the zlight[][] array R_InitLightTables(); // [crispy] re-calculate the scalelight[][] array diff --git a/src/doom/m_menu.c b/src/doom/m_menu.c index aa048a6c6..8af456c72 100644 --- a/src/doom/m_menu.c +++ b/src/doom/m_menu.c @@ -2789,7 +2789,6 @@ boolean M_Responder (event_t* ev) I_SetPalette (W_CacheLumpName (DEH_String("PLAYPAL"),PU_CACHE)); #else { - extern void R_InitColormaps (void); I_SetPalette (0); R_InitColormaps(); inhelpscreens = true; diff --git a/src/doom/p_setup.c b/src/doom/p_setup.c index 568817ff4..9fabc6420 100644 --- a/src/doom/p_setup.c +++ b/src/doom/p_setup.c @@ -323,13 +323,13 @@ void P_SegLengths (boolean contrast_only) li->fakecontrast = -LIGHTBRIGHT; else if (abs(finesine[li->r_angle >> ANGLETOFINESHIFT]) < rightangle) - li->fakecontrast = -(LIGHTBRIGHT >> 1); + li->fakecontrast = -LIGHTBRIGHT / 2; else if (!dx) li->fakecontrast = LIGHTBRIGHT; else if (abs(finecosine[li->r_angle >> ANGLETOFINESHIFT]) < rightangle) - li->fakecontrast = LIGHTBRIGHT >> 1; + li->fakecontrast = LIGHTBRIGHT / 2; else li->fakecontrast = 0; } diff --git a/src/doom/r_data.c b/src/doom/r_data.c index aebbd3354..9b2c18a5a 100644 --- a/src/doom/r_data.c +++ b/src/doom/r_data.c @@ -1189,6 +1189,7 @@ void R_InitColormaps (void) // 256 byte align tables. lump = W_GetNumForName(DEH_String("COLORMAP")); colormaps = W_CacheLumpNum(lump, PU_STATIC); + NUMCOLORMAPS = 32; // [crispy] smooth diminishing lighting #else int c, i, j = 0; byte r, g, b; @@ -1196,10 +1197,19 @@ void R_InitColormaps (void) byte *const playpal = W_CacheLumpName("PLAYPAL", PU_STATIC); byte *const colormap = W_CacheLumpName("COLORMAP", PU_STATIC); - if (!colormaps) + // [crispy] Smoothest diminishing lighting. + // Compiled in but not enabled TrueColor mode + // can't use more than original 32 colormaps. + if (crispy->truecolor && crispy->smoothlight) { - colormaps = (lighttable_t*) Z_Malloc((NUMCOLORMAPS + 1) * 256 * sizeof(lighttable_t), PU_STATIC, 0); + NUMCOLORMAPS = 256; } + else + { + NUMCOLORMAPS = 32; + } + + colormaps = I_Realloc(colormaps, (NUMCOLORMAPS + 1) * 256 * sizeof(lighttable_t)); if (crispy->truecolor) { diff --git a/src/doom/r_main.c b/src/doom/r_main.c index 71d68dd81..47776bab7 100644 --- a/src/doom/r_main.c +++ b/src/doom/r_main.c @@ -111,6 +111,7 @@ lighttable_t*** zlight = NULL; int extralight; // [crispy] parameterized for smooth diminishing lighting +int NUMCOLORMAPS; int LIGHTLEVELS; int LIGHTSEGSHIFT; int LIGHTBRIGHT; @@ -699,23 +700,40 @@ void R_InitLightTables (void) // [crispy] smooth diminishing lighting if (crispy->smoothlight) { - LIGHTLEVELS = 32; - LIGHTSEGSHIFT = 3; - LIGHTBRIGHT = 2; - MAXLIGHTSCALE = 48; - LIGHTSCALESHIFT = 12; - MAXLIGHTZ = 1024; - LIGHTZSHIFT = 17; +#ifdef CRISPY_TRUECOLOR + if (crispy->truecolor) + { + // [crispy] if in TrueColor mode, use smoothest diminished lighting + LIGHTLEVELS = 16 << 4; + LIGHTSEGSHIFT = 4 - 4; + LIGHTBRIGHT = 1 << 4; + MAXLIGHTSCALE = 48 << 3; + LIGHTSCALESHIFT = 12 - 3; + MAXLIGHTZ = 128 << 6; + LIGHTZSHIFT = 20 - 6; + } + else +#endif + { + // [crispy] else, use paletted approach + LIGHTLEVELS = 16 << 1; + LIGHTSEGSHIFT = 4 - 1; + LIGHTBRIGHT = 1 << 1; + MAXLIGHTSCALE = 48 << 0; + LIGHTSCALESHIFT = 12 - 0; + MAXLIGHTZ = 128 << 3; + LIGHTZSHIFT = 20 - 3; + } } else { - LIGHTLEVELS = 16; - LIGHTSEGSHIFT = 4; - LIGHTBRIGHT = 1; - MAXLIGHTSCALE = 48; - LIGHTSCALESHIFT = 12; - MAXLIGHTZ = 128; - LIGHTZSHIFT = 20; + LIGHTLEVELS = 16; + LIGHTSEGSHIFT = 4; + LIGHTBRIGHT = 1; + MAXLIGHTSCALE = 48; + LIGHTSCALESHIFT = 12; + MAXLIGHTZ = 128; + LIGHTZSHIFT = 20; } scalelight = malloc(LIGHTLEVELS * sizeof(*scalelight)); @@ -1092,7 +1110,7 @@ void R_SetupFrame (player_t* player) { fixedcolormap = colormaps - + player->fixedcolormap*256; + + player->fixedcolormap*(NUMCOLORMAPS / 32)*256; // [crispy] smooth diminishing lighting walllights = scalelightfixed; diff --git a/src/doom/r_main.h b/src/doom/r_main.h index e3fc7961b..619a0dadc 100644 --- a/src/doom/r_main.h +++ b/src/doom/r_main.h @@ -80,7 +80,8 @@ extern lighttable_t* fixedcolormap; // Number of diminishing brightness levels. // There a 0-31, i.e. 32 LUT in the COLORMAP lump. -#define NUMCOLORMAPS 32 +// [crispy] parameterized for smooth diminishing lighting +extern int NUMCOLORMAPS; // Blocky/low detail mode. //B remove this? @@ -200,6 +201,7 @@ void R_Init (void); // Called by M_Responder. void R_SetViewSize (int blocks, int detail); +void R_InitColormaps(void); void R_ExecuteSetViewSize(void); diff --git a/src/heretic/d_main.c b/src/heretic/d_main.c index 1b05c621c..c2c5ac316 100644 --- a/src/heretic/d_main.c +++ b/src/heretic/d_main.c @@ -882,6 +882,7 @@ void D_BindVariables(void) M_BindIntVariable("crispy_mouselook", &crispy->mouselook); M_BindIntVariable("crispy_playercoords", &crispy->playercoords); M_BindIntVariable("crispy_secretmessage", &crispy->secretmessage); + M_BindIntVariable("crispy_smoothlight", &crispy->smoothlight); M_BindIntVariable("crispy_soundmono", &crispy->soundmono); #ifdef CRISPY_TRUECOLOR M_BindIntVariable("crispy_truecolor", &crispy->truecolor); diff --git a/src/heretic/mn_menu.c b/src/heretic/mn_menu.c index b7587fb29..0ae7d94ae 100644 --- a/src/heretic/mn_menu.c +++ b/src/heretic/mn_menu.c @@ -131,6 +131,7 @@ static boolean CrispyHires(int option); static boolean CrispyToggleWidescreen(int option); static boolean CrispySmoothing(int option); static boolean CrispyBrightmaps(int option); +static boolean CrispySmoothLighting(int option); static boolean CrispySoundMono(int option); static boolean CrispySndChannels(int option); static boolean CrispyAutomapStats(int option); @@ -169,6 +170,8 @@ void MN_LoadSlotText(void); extern void I_ReInitGraphics(int reinit); extern void AM_LevelInit(boolean reinit); extern void AM_initVariables(void); +extern void P_SegLengths (boolean contrast_only); +extern void R_InitLightTables (void); // Public Data @@ -368,6 +371,7 @@ static MenuItem_t Crispness1Items[] = { {ITT_EMPTY, NULL, NULL, 0, MENU_NONE}, {ITT_EMPTY, NULL, NULL, 0, MENU_NONE}, {ITT_LRFUNC2, "APPLY BRIGHTMAPS TO:", CrispyBrightmaps, 0, MENU_NONE}, + {ITT_LRFUNC2, "SMOOTH DIMINISHING LIGHTING:", CrispySmoothLighting, 0, MENU_NONE}, {ITT_EMPTY, NULL, NULL, 0, MENU_NONE}, {ITT_EMPTY, NULL, NULL, 0, MENU_NONE}, {ITT_LRFUNC2, "MONO SFX:", CrispySoundMono, 0, MENU_NONE}, @@ -379,7 +383,7 @@ static MenuItem_t Crispness1Items[] = { static Menu_t Crispness1Menu = { 68, 35, DrawCrispness, - 15, Crispness1Items, + 16, Crispness1Items, 0, MENU_OPTIONS }; @@ -1704,6 +1708,27 @@ static boolean CrispyBrightmaps(int option) return true; } +static void CrispySmoothLightingHook (void) +{ + crispy->smoothlight = !crispy->smoothlight; +#ifdef CRISPY_TRUECOLOR + // [crispy] re-calculate amount of colormaps and light tables + R_InitColormaps(); +#endif + // [crispy] re-calculate the zlight[][] array + R_InitLightTables(); + // [crispy] re-calculate the scalelight[][] array + R_ExecuteSetViewSize(); + // [crispy] re-calculate fake contrast + P_SegLengths(true); +} + +static boolean CrispySmoothLighting(int option) +{ + crispy->post_rendering_hook = CrispySmoothLightingHook; + return true; +} + static boolean CrispySoundMono(int option) { crispy->soundmono = !crispy->soundmono; @@ -2982,13 +3007,16 @@ static void DrawCrispness1(void) // Brightmaps DrawCrispnessMultiItem(crispy->brightmaps, 213, 115, multiitem_brightmaps, false); - DrawCrispnessSubheader("AUDIBLE", 135); + // Smooth Diminishing Lighting + DrawCrispnessItem(crispy->smoothlight, 257, 125); + + DrawCrispnessSubheader("AUDIBLE", 145); // Mono SFX - DrawCrispnessItem(crispy->soundmono, 137, 145); + DrawCrispnessItem(crispy->soundmono, 137, 155); // Sound Channels - DrawCrispnessMultiItem(snd_Channels >> 4, 181, 155, multiitem_sndchannels, false); + DrawCrispnessMultiItem(snd_Channels >> 4, 181, 165, multiitem_sndchannels, false); } static void DrawCrispness2(void) diff --git a/src/heretic/p_setup.c b/src/heretic/p_setup.c index 28a03458d..d8736fda8 100644 --- a/src/heretic/p_setup.c +++ b/src/heretic/p_setup.c @@ -174,9 +174,10 @@ static angle_t anglediff(angle_t a, angle_t b) return b - a; } -static void P_SegLengths(void) +void P_SegLengths(boolean contrast_only) { int i; + const int rightangle = abs(finesine[(ANG60/2) >> ANGLETOFINESHIFT]); for (i = 0; i < numsegs; i++) { @@ -186,6 +187,8 @@ static void P_SegLengths(void) dx = li->v2->r_x - li->v1->r_x; dy = li->v2->r_y - li->v1->r_y; + if (!contrast_only) + { li->length = (uint32_t)(sqrt((double)dx * dx + (double)dy * dy) / 2); // [crispy] re-calculate angle used for rendering @@ -198,6 +201,22 @@ static void P_SegLengths(void) { li->r_angle = li->angle; } + } + + // [crispy] smoother fake contrast + if (!dy) + li->fakecontrast = -LIGHTBRIGHT; + else + if (abs(finesine[li->r_angle >> ANGLETOFINESHIFT]) < rightangle) + li->fakecontrast = -LIGHTBRIGHT / 2; + else + if (!dx) + li->fakecontrast = LIGHTBRIGHT; + else + if (abs(finecosine[li->r_angle >> ANGLETOFINESHIFT]) < rightangle) + li->fakecontrast = LIGHTBRIGHT / 2; + else + li->fakecontrast = 0; } } @@ -839,7 +858,7 @@ void P_SetupLevel(int episode, int map, int playermask, skill_t skill) P_RemoveSlimeTrails(); // [crispy] fix long wall wobble - P_SegLengths(); + P_SegLengths(false); bodyqueslot = 0; deathmatch_p = deathmatchstarts; diff --git a/src/heretic/r_data.c b/src/heretic/r_data.c index d628122d0..578137a7e 100644 --- a/src/heretic/r_data.c +++ b/src/heretic/r_data.c @@ -708,6 +708,7 @@ void R_InitColormaps(void) length = W_LumpLength(lump); colormaps = Z_Malloc(length, PU_STATIC, 0); W_ReadLump(lump, colormaps); + NUMCOLORMAPS = 32; // [crispy] smooth diminishing lighting #else int c, i, j = 0; byte r, g, b; @@ -715,10 +716,19 @@ void R_InitColormaps(void) byte *const playpal = W_CacheLumpName("PLAYPAL", PU_STATIC); byte *const colormap = W_CacheLumpName("COLORMAP", PU_STATIC); - if (!colormaps) + // [crispy] Smoothest diminishing lighting. + // Compiled in but not enabled TrueColor mode + // can't use more than original 32 colormaps. + if (crispy->truecolor && crispy->smoothlight) { - colormaps = (lighttable_t*) Z_Malloc((NUMCOLORMAPS + 1) * 256 * sizeof(lighttable_t), PU_STATIC, 0); + NUMCOLORMAPS = 256; } + else + { + NUMCOLORMAPS = 32; + } + + colormaps = I_Realloc(colormaps, (NUMCOLORMAPS + 1) * 256 * sizeof(lighttable_t)); if (crispy->truecolor) { @@ -756,9 +766,9 @@ void R_InitColormaps(void) // [crispy] Invulnerability (c == COLORMAPS), generated from COLORMAP lump for (i = 0; i < 256; i++) { - r = gamma2table[crispy->gamma][playpal[3 * colormap[c * 256 + i] + 0]] & ~3; - g = gamma2table[crispy->gamma][playpal[3 * colormap[c * 256 + i] + 1]] & ~3; - b = gamma2table[crispy->gamma][playpal[3 * colormap[c * 256 + i] + 2]] & ~3; + r = gamma2table[crispy->gamma][playpal[3 * colormap[INVERSECOLORMAP * 256 + i] + 0]] & ~3; + g = gamma2table[crispy->gamma][playpal[3 * colormap[INVERSECOLORMAP * 256 + i] + 1]] & ~3; + b = gamma2table[crispy->gamma][playpal[3 * colormap[INVERSECOLORMAP * 256 + i] + 2]] & ~3; colormaps[j++] = 0xff000000 | (r << 16) | (g << 8) | b; } diff --git a/src/heretic/r_local.h b/src/heretic/r_local.h index 39907f608..251fc0645 100644 --- a/src/heretic/r_local.h +++ b/src/heretic/r_local.h @@ -41,13 +41,16 @@ // // lighting constants // -#define LIGHTLEVELS 16 -#define LIGHTSEGSHIFT 4 -#define MAXLIGHTSCALE 48 -#define LIGHTSCALESHIFT 12 -#define MAXLIGHTZ 128 -#define LIGHTZSHIFT 20 -#define NUMCOLORMAPS 32 // number of diminishing +// [crispy] parameterized for smooth diminishing lighting +extern int LIGHTLEVELS; +extern int LIGHTSEGSHIFT; +extern int LIGHTBRIGHT; +extern int MAXLIGHTSCALE; +extern int LIGHTSCALESHIFT; +extern int MAXLIGHTZ; +extern int LIGHTZSHIFT; +// [crispy] parameterized for smooth diminishing lighting +extern int NUMCOLORMAPS; // number of diminishing #define INVERSECOLORMAP 32 #define LOOKDIRMIN 110 // [crispy] -110, actually @@ -171,6 +174,7 @@ typedef struct uint32_t length; // [crispy] fix long wall wobble angle_t r_angle; // [crispy] recalculated angle used for rendering + int fakecontrast; } seg_t; typedef struct @@ -342,9 +346,9 @@ extern fixed_t projection; extern int validcount; extern int sscount, linecount, loopcount; -extern lighttable_t *scalelight[LIGHTLEVELS][MAXLIGHTSCALE]; -extern lighttable_t *scalelightfixed[MAXLIGHTSCALE]; -extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; +extern lighttable_t ***scalelight; +extern lighttable_t **scalelightfixed; +extern lighttable_t ***zlight; extern int extralight; extern lighttable_t *fixedcolormap; diff --git a/src/heretic/r_main.c b/src/heretic/r_main.c index a1dceb770..4846eefb2 100644 --- a/src/heretic/r_main.c +++ b/src/heretic/r_main.c @@ -61,12 +61,23 @@ int viewangletox[FINEANGLES / 2]; // that maps back to x ranges from clipangle to -clipangle angle_t xtoviewangle[MAXWIDTH + 1]; -lighttable_t *scalelight[LIGHTLEVELS][MAXLIGHTSCALE]; -lighttable_t *scalelightfixed[MAXLIGHTSCALE]; -lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; +// [crispy] parameterized for smooth diminishing lighting +lighttable_t ***scalelight = NULL; +lighttable_t **scalelightfixed = NULL; +lighttable_t ***zlight = NULL; int extralight; // bumped light from gun blasts +// [crispy] parameterized for smooth diminishing lighting +int NUMCOLORMAPS; +int LIGHTLEVELS; +int LIGHTSEGSHIFT; +int LIGHTBRIGHT; +int MAXLIGHTSCALE; +int LIGHTSCALESHIFT; +int MAXLIGHTZ; +int LIGHTZSHIFT; + void (*colfunc) (void); void (*basecolfunc) (void); void (*tlcolfunc) (void); @@ -552,12 +563,80 @@ void R_InitLightTables(void) int i, j, level, startmap; int scale; + if (scalelight) + { + for (i = 0; i < LIGHTLEVELS; i++) + { + free(scalelight[i]); + } + free(scalelight); + } + + if (scalelightfixed) + { + free(scalelightfixed); + } + + if (zlight) + { + for (i = 0; i < LIGHTLEVELS; i++) + { + free(zlight[i]); + } + free(zlight); + } + + // [crispy] smooth diminishing lighting + if (crispy->smoothlight) + { +#ifdef CRISPY_TRUECOLOR + if (crispy->truecolor) + { + // [crispy] if in TrueColor mode, use smoothest diminished lighting + LIGHTLEVELS = 16 << 4; + LIGHTSEGSHIFT = 4 - 4; + LIGHTBRIGHT = 1 << 4; + MAXLIGHTSCALE = 48 << 3; + LIGHTSCALESHIFT = 12 - 3; + MAXLIGHTZ = 128 << 6; + LIGHTZSHIFT = 20 - 6; + } + else +#endif + { + // [crispy] else, use paletted approach + LIGHTLEVELS = 16 << 1; + LIGHTSEGSHIFT = 4 - 1; + LIGHTBRIGHT = 1 << 1; + MAXLIGHTSCALE = 48 << 0; + LIGHTSCALESHIFT = 12 - 0; + MAXLIGHTZ = 128 << 3; + LIGHTZSHIFT = 20 - 3; + } + } + else + { + LIGHTLEVELS = 16; + LIGHTSEGSHIFT = 4; + LIGHTBRIGHT = 1; + MAXLIGHTSCALE = 48; + LIGHTSCALESHIFT = 12; + MAXLIGHTZ = 128; + LIGHTZSHIFT = 20; + } + + scalelight = malloc(LIGHTLEVELS * sizeof(*scalelight)); + scalelightfixed = malloc(MAXLIGHTSCALE * sizeof(*scalelightfixed)); + zlight = malloc(LIGHTLEVELS * sizeof(*zlight)); + // // Calculate the light levels to use for each level / distance combination // for (i = 0; i < LIGHTLEVELS; i++) { - startmap = ((LIGHTLEVELS - 1 - i) * 2) * NUMCOLORMAPS / LIGHTLEVELS; + startmap = ((LIGHTLEVELS - LIGHTBRIGHT - i) * 2) * NUMCOLORMAPS / LIGHTLEVELS; + scalelight[i] = malloc(MAXLIGHTSCALE * sizeof(**scalelight)); + zlight[i] = malloc(MAXLIGHTZ * sizeof(**zlight)); for (j = 0; j < MAXLIGHTZ; j++) { scale = @@ -712,7 +791,7 @@ void R_ExecuteSetViewSize(void) // for (i = 0; i < LIGHTLEVELS; i++) { - startmap = ((LIGHTLEVELS - 1 - i) * 2) * NUMCOLORMAPS / LIGHTLEVELS; + startmap = ((LIGHTLEVELS - LIGHTBRIGHT - i) * 2) * NUMCOLORMAPS / LIGHTLEVELS; for (j = 0; j < MAXLIGHTSCALE; j++) { level = @@ -904,6 +983,7 @@ void R_SetupFrame(player_t * player) if (player->fixedcolormap) { fixedcolormap = colormaps + player->fixedcolormap + * (NUMCOLORMAPS / 32) // [crispy] smooth diminishing lighting * 256 /* * sizeof(lighttable_t)*/; walllights = scalelightfixed; for (i = 0; i < MAXLIGHTSCALE; i++) diff --git a/src/heretic/r_plane.c b/src/heretic/r_plane.c index daf00e62a..c29b90e78 100644 --- a/src/heretic/r_plane.c +++ b/src/heretic/r_plane.c @@ -644,7 +644,7 @@ void R_DrawPlanes(void) } ds_brightmap = R_BrightmapForFlatNum(lumpnum-firstflat); planeheight = abs(pl->height - viewz); - light = (pl->lightlevel >> LIGHTSEGSHIFT) + extralight; + light = (pl->lightlevel >> LIGHTSEGSHIFT) + (extralight * LIGHTBRIGHT); // [crispy] smooth diminishing lighting if (light >= LIGHTLEVELS) light = LIGHTLEVELS - 1; if (light < 0) diff --git a/src/heretic/r_segs.c b/src/heretic/r_segs.c index be2ff5f98..8c2a7a8d6 100644 --- a/src/heretic/r_segs.c +++ b/src/heretic/r_segs.c @@ -187,11 +187,15 @@ void R_RenderMaskedSegRange(drawseg_t * ds, int x1, int x2) backsector = curline->backsector; texnum = texturetranslation[curline->sidedef->midtexture]; - lightnum = (frontsector->lightlevel >> LIGHTSEGSHIFT) + extralight; + lightnum = (frontsector->lightlevel >> LIGHTSEGSHIFT) + (extralight * LIGHTBRIGHT); // [crispy] smooth diminishing lighting + // [crispy] smoother fake contrast + lightnum += curline->fakecontrast; +/* if (curline->v1->y == curline->v2->y) lightnum--; else if (curline->v1->x == curline->v2->x) lightnum++; +*/ if (lightnum < 0) walllights = scalelight[0]; else if (lightnum >= LIGHTLEVELS) @@ -744,11 +748,15 @@ void R_StoreWallRange(int start, int stop) if (!fixedcolormap) { lightnum = - (frontsector->lightlevel >> LIGHTSEGSHIFT) + extralight; + (frontsector->lightlevel >> LIGHTSEGSHIFT) + (extralight * LIGHTBRIGHT); // [crispy] smooth diminishing lighting + // [crispy] smoother fake contrast + lightnum += curline->fakecontrast; + /* if (curline->v1->y == curline->v2->y) lightnum--; else if (curline->v1->x == curline->v2->x) lightnum++; + */ if (lightnum < 0) walllights = scalelight[0]; else if (lightnum >= LIGHTLEVELS) diff --git a/src/heretic/r_things.c b/src/heretic/r_things.c index 98d6b99c0..1b0e4ca6f 100644 --- a/src/heretic/r_things.c +++ b/src/heretic/r_things.c @@ -695,7 +695,7 @@ void R_AddSprites(sector_t * sec) sec->validcount = validcount; - lightnum = (sec->lightlevel >> LIGHTSEGSHIFT) + extralight; + lightnum = (sec->lightlevel >> LIGHTSEGSHIFT) + (extralight * LIGHTBRIGHT); // [crispy] smooth diminishing lighting if (lightnum < 0) spritelights = scalelight[0]; else if (lightnum >= LIGHTLEVELS) @@ -904,7 +904,7 @@ void R_DrawPlayerSprites(void) // lightnum = (viewplayer->mo->subsector->sector->lightlevel >> LIGHTSEGSHIFT) + - extralight; + (extralight * LIGHTBRIGHT); // [crispy] smooth diminishing lighting if (lightnum < 0) spritelights = scalelight[0]; else if (lightnum >= LIGHTLEVELS) diff --git a/src/hexen/h2_main.c b/src/hexen/h2_main.c index 72b608e32..7f27a052b 100644 --- a/src/hexen/h2_main.c +++ b/src/hexen/h2_main.c @@ -212,6 +212,7 @@ void D_BindVariables(void) #ifdef CRISPY_TRUECOLOR M_BindIntVariable("crispy_truecolor", &crispy->truecolor); #endif + M_BindIntVariable("crispy_smoothlight", &crispy->smoothlight); M_BindIntVariable("crispy_smoothscaling", &crispy->smoothscaling); M_BindIntVariable("crispy_vsync", &crispy->vsync); M_BindIntVariable("crispy_widescreen", &crispy->widescreen); diff --git a/src/hexen/mn_menu.c b/src/hexen/mn_menu.c index 926383b0c..492f39292 100644 --- a/src/hexen/mn_menu.c +++ b/src/hexen/mn_menu.c @@ -107,6 +107,7 @@ typedef struct } multiitem_t; // EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- +extern void R_InitLightTables(void); // [crispy] extern void I_ReInitGraphics(int reinit); // [crispy] extern void R_ExecuteSetViewSize(void); // [crispy] extern void AM_LevelInit(boolean reinit); // [crispy] @@ -136,6 +137,7 @@ static void CrispyUncapped(int option); static void CrispyFpsLimit(int option); static void CrispyVsync(int option); static void CrispyBrightmaps(int option); +static void CrispySmoothLighting(int option); static void CrispySoundMono(int option); static void CrispySndChannels(int option); static void CrispyPlayerCoords(int options); @@ -368,6 +370,7 @@ static MenuItem_t Crispness1Items[] = { {ITT_EMPTY, NULL, NULL, 0, MENU_NONE}, {ITT_EMPTY, NULL, NULL, 0, MENU_NONE}, {ITT_LRFUNC2, "BRIGHTMAPS:", CrispyBrightmaps, 0, MENU_NONE}, + {ITT_LRFUNC2, "SMOOTH DIMINISHING LIGHTING:", CrispySmoothLighting, 0, MENU_NONE}, {ITT_EMPTY, NULL, NULL, 0, MENU_NONE}, {ITT_EMPTY, NULL, NULL, 0, MENU_NONE}, {ITT_LRFUNC2, "MONO SFX:", CrispySoundMono, 0, MENU_NONE}, @@ -379,7 +382,7 @@ static MenuItem_t Crispness1Items[] = { static Menu_t Crispness1Menu = { 68, 35, DrawCrispnessMenu, - 15, Crispness1Items, + 16, Crispness1Items, 0, MENU_OPTIONS }; @@ -1729,6 +1732,24 @@ static void CrispyBrightmaps(int option) ChangeSettingEnum(&crispy->brightmaps, option, NUM_BRIGHTMAPS); } +static void CrispySmoothLightingHook (void) +{ + crispy->smoothlight = !crispy->smoothlight; +#ifdef CRISPY_TRUECOLOR + // [crispy] re-calculate amount of colormaps and light tables + R_InitTrueColormaps(LevelUseFullBright ? "COLORMAP" : "FOGMAP"); +#endif + // [crispy] re-calculate the zlight[][] array + R_InitLightTables(); + // [crispy] re-calculate the scalelight[][] array + R_ExecuteSetViewSize(); +} + +static void CrispySmoothLighting(int option) +{ + crispy->post_rendering_hook = CrispySmoothLightingHook; +} + static void CrispySoundMono(int option) { crispy->soundmono = !crispy->soundmono; @@ -2972,13 +2993,16 @@ static void DrawCrispness1(void) // Brightmaps DrawCrispnessMultiItem(crispy->brightmaps, 150, 115, multiitem_brightmaps, false); - DrawCrispnessSubheader("AUDIBLE", 135); + // Smooth Diminishing Lighting + DrawCrispnessItem(crispy->smoothlight, 257, 125); + + DrawCrispnessSubheader("AUDIBLE", 145); // Mono SFX - DrawCrispnessItem(crispy->soundmono, 137, 145); + DrawCrispnessItem(crispy->soundmono, 137, 155); // Sound Channels - DrawCrispnessMultiItem(snd_Channels >> 4, 181, 155, multiitem_sndchannels, false); + DrawCrispnessMultiItem(snd_Channels >> 4, 181, 165, multiitem_sndchannels, false); } static void DrawCrispness2(void) diff --git a/src/hexen/r_data.c b/src/hexen/r_data.c index e9eeed098..29d22415a 100644 --- a/src/hexen/r_data.c +++ b/src/hexen/r_data.c @@ -675,6 +675,7 @@ void R_InitColormaps(void) length = W_LumpLength(lump); colormaps = Z_Malloc(length, PU_STATIC, 0); W_ReadLump(lump, colormaps); + NUMCOLORMAPS = 32; // [crispy] smooth diminishing lighting } #else @@ -688,10 +689,19 @@ void R_InitTrueColormaps(char *current_colormap) byte *const playpal = W_CacheLumpName("PLAYPAL", PU_STATIC); byte *const colormap = W_CacheLumpName(current_colormap, PU_STATIC); - if (!colormaps) + // [crispy] Smoothest diminishing lighting. + // Compiled in but not enabled TrueColor mode + // can't use more than original 32 colormaps. + if (crispy->truecolor && crispy->smoothlight) { - colormaps = (lighttable_t*) Z_Malloc((NUMCOLORMAPS + 1) * 256 * sizeof(lighttable_t), PU_STATIC, 0); + NUMCOLORMAPS = 256; } + else + { + NUMCOLORMAPS = 32; + } + + colormaps = I_Realloc(colormaps, (NUMCOLORMAPS + 1) * 256 * sizeof(lighttable_t)); if (crispy->truecolor) { diff --git a/src/hexen/r_local.h b/src/hexen/r_local.h index 70bcb5f3e..4df1652bf 100644 --- a/src/hexen/r_local.h +++ b/src/hexen/r_local.h @@ -38,13 +38,16 @@ // // lighting constants // -#define LIGHTLEVELS 16 -#define LIGHTSEGSHIFT 4 -#define MAXLIGHTSCALE 48 -#define LIGHTSCALESHIFT 12 -#define MAXLIGHTZ 128 -#define LIGHTZSHIFT 20 -#define NUMCOLORMAPS 32 // number of diminishing +// [crispy] parameterized for smooth diminishing lighting +extern int LIGHTLEVELS; +extern int LIGHTSEGSHIFT; +extern int LIGHTBRIGHT; +extern int MAXLIGHTSCALE; +extern int LIGHTSCALESHIFT; +extern int MAXLIGHTZ; +extern int LIGHTZSHIFT; +// [crispy] parameterized for smooth diminishing lighting +extern int NUMCOLORMAPS; // number of diminishing #define INVERSECOLORMAP 32 #define LOOKDIRMIN 110 // [crispy] -110, actually @@ -390,9 +393,9 @@ extern fixed_t projection; extern int validcount; extern int sscount, linecount, loopcount; -extern lighttable_t *scalelight[LIGHTLEVELS][MAXLIGHTSCALE]; -extern lighttable_t *scalelightfixed[MAXLIGHTSCALE]; -extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; +extern lighttable_t ***scalelight; +extern lighttable_t **scalelightfixed; +extern lighttable_t ***zlight; extern int extralight; extern lighttable_t *fixedcolormap; diff --git a/src/hexen/r_main.c b/src/hexen/r_main.c index f9b16396d..579d70c8f 100644 --- a/src/hexen/r_main.c +++ b/src/hexen/r_main.c @@ -59,12 +59,23 @@ int viewangletox[FINEANGLES / 2]; // that maps back to x ranges from clipangle to -clipangle angle_t xtoviewangle[MAXWIDTH + 1]; -lighttable_t *scalelight[LIGHTLEVELS][MAXLIGHTSCALE]; -lighttable_t *scalelightfixed[MAXLIGHTSCALE]; -lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; +// [crispy] parameterized for smooth diminishing lighting +lighttable_t ***scalelight = NULL; +lighttable_t **scalelightfixed = NULL; +lighttable_t ***zlight = NULL; int extralight; // bumped light from gun blasts +// [crispy] parameterized for smooth diminishing lighting +int NUMCOLORMAPS; +int LIGHTLEVELS; +int LIGHTSEGSHIFT; +int LIGHTBRIGHT; +int MAXLIGHTSCALE; +int LIGHTSCALESHIFT; +int MAXLIGHTZ; +int LIGHTZSHIFT; + void (*colfunc) (void); void (*basecolfunc) (void); void (*tlcolfunc) (void); @@ -555,12 +566,80 @@ void R_InitLightTables(void) int i, j, level, startmap; int scale; + if (scalelight) + { + for (i = 0; i < LIGHTLEVELS; i++) + { + free(scalelight[i]); + } + free(scalelight); + } + + if (scalelightfixed) + { + free(scalelightfixed); + } + + if (zlight) + { + for (i = 0; i < LIGHTLEVELS; i++) + { + free(zlight[i]); + } + free(zlight); + } + + // [crispy] smooth diminishing lighting + if (crispy->smoothlight) + { +#ifdef CRISPY_TRUECOLOR + if (crispy->truecolor) + { + // [crispy] if in TrueColor mode, use smoothest diminished lighting + LIGHTLEVELS = 16 << 4; + LIGHTSEGSHIFT = 4 - 4; + LIGHTBRIGHT = 1 << 4; + MAXLIGHTSCALE = 48 << 3; + LIGHTSCALESHIFT = 12 - 3; + MAXLIGHTZ = 128 << 6; + LIGHTZSHIFT = 20 - 6; + } + else +#endif + { + // [crispy] else, use paletted approach + LIGHTLEVELS = 16 << 1; + LIGHTSEGSHIFT = 4 - 1; + LIGHTBRIGHT = 1 << 1; + MAXLIGHTSCALE = 48 << 0; + LIGHTSCALESHIFT = 12 - 0; + MAXLIGHTZ = 128 << 3; + LIGHTZSHIFT = 20 - 3; + } + } + else + { + LIGHTLEVELS = 16; + LIGHTSEGSHIFT = 4; + LIGHTBRIGHT = 1; + MAXLIGHTSCALE = 48; + LIGHTSCALESHIFT = 12; + MAXLIGHTZ = 128; + LIGHTZSHIFT = 20; + } + + scalelight = malloc(LIGHTLEVELS * sizeof(*scalelight)); + scalelightfixed = malloc(MAXLIGHTSCALE * sizeof(*scalelightfixed)); + zlight = malloc(LIGHTLEVELS * sizeof(*zlight)); + // // Calculate the light levels to use for each level / distance combination // for (i = 0; i < LIGHTLEVELS; i++) { - startmap = ((LIGHTLEVELS - 1 - i) * 2) * NUMCOLORMAPS / LIGHTLEVELS; + startmap = ((LIGHTLEVELS - LIGHTBRIGHT - i) * 2) * NUMCOLORMAPS / LIGHTLEVELS; + scalelight[i] = malloc(MAXLIGHTSCALE * sizeof(**scalelight)); + zlight[i] = malloc(MAXLIGHTZ * sizeof(**zlight)); for (j = 0; j < MAXLIGHTZ; j++) { scale = @@ -713,7 +792,7 @@ void R_ExecuteSetViewSize(void) // for (i = 0; i < LIGHTLEVELS; i++) { - startmap = ((LIGHTLEVELS - 1 - i) * 2) * NUMCOLORMAPS / LIGHTLEVELS; + startmap = ((LIGHTLEVELS - LIGHTBRIGHT - i) * 2) * NUMCOLORMAPS / LIGHTLEVELS; for (j = 0; j < MAXLIGHTSCALE; j++) { level = @@ -907,6 +986,7 @@ void R_SetupFrame(player_t * player) if (player->fixedcolormap) { fixedcolormap = colormaps + player->fixedcolormap + * (NUMCOLORMAPS / 32) // [crispy] smooth diminishing lighting // [crispy] sizeof(lighttable_t) not needed in paletted render // and breaks Torch's fixed colormap indexes in true color render * 256 /* * sizeof(lighttable_t)*/; diff --git a/src/hexen/r_plane.c b/src/hexen/r_plane.c index 75ad70606..491dfafd0 100644 --- a/src/hexen/r_plane.c +++ b/src/hexen/r_plane.c @@ -724,7 +724,7 @@ void R_DrawPlanes(void) break; } planeheight = abs(pl->height - viewz); - light = (pl->lightlevel >> LIGHTSEGSHIFT) + extralight; + light = (pl->lightlevel >> LIGHTSEGSHIFT) + (extralight * LIGHTBRIGHT); // [crispy] smooth diminishing lighting if (light >= LIGHTLEVELS) { light = LIGHTLEVELS - 1; diff --git a/src/hexen/r_segs.c b/src/hexen/r_segs.c index 97696461b..d65539bfc 100644 --- a/src/hexen/r_segs.c +++ b/src/hexen/r_segs.c @@ -179,7 +179,7 @@ void R_RenderMaskedSegRange(drawseg_t * ds, int x1, int x2) backsector = curline->backsector; texnum = texturetranslation[curline->sidedef->midtexture]; - lightnum = (frontsector->lightlevel >> LIGHTSEGSHIFT) + extralight; + lightnum = (frontsector->lightlevel >> LIGHTSEGSHIFT) + (extralight * LIGHTBRIGHT); // [crispy] smooth diminishing lighting //if (curline->v1->y == curline->v2->y) // lightnum--; //else if (curline->v1->x == curline->v2->x) @@ -727,7 +727,7 @@ void R_StoreWallRange(int start, int stop) if (!fixedcolormap) { lightnum = - (frontsector->lightlevel >> LIGHTSEGSHIFT) + extralight; + (frontsector->lightlevel >> LIGHTSEGSHIFT) + (extralight * LIGHTBRIGHT); // [crispy] smooth diminishing lighting; //if (curline->v1->y == curline->v2->y) // lightnum--; //else if (curline->v1->x == curline->v2->x) diff --git a/src/hexen/r_things.c b/src/hexen/r_things.c index f85e4f15c..01962d3e2 100644 --- a/src/hexen/r_things.c +++ b/src/hexen/r_things.c @@ -703,7 +703,7 @@ void R_AddSprites(sector_t * sec) sec->validcount = validcount; - lightnum = (sec->lightlevel >> LIGHTSEGSHIFT) + extralight; + lightnum = (sec->lightlevel >> LIGHTSEGSHIFT) + (extralight * LIGHTBRIGHT); // [crispy] smooth diminishing lighting if (lightnum < 0) spritelights = scalelight[0]; else if (lightnum >= LIGHTLEVELS) @@ -925,7 +925,7 @@ void R_DrawPlayerSprites(void) // lightnum = (viewplayer->mo->subsector->sector->lightlevel >> LIGHTSEGSHIFT) + - extralight; + (extralight * LIGHTBRIGHT); // [crispy] smooth diminishing lighting if (lightnum < 0) spritelights = scalelight[0]; else if (lightnum >= LIGHTLEVELS) diff --git a/src/strife/m_crispy.c b/src/strife/m_crispy.c index 36604eeb2..2f7bb7a00 100644 --- a/src/strife/m_crispy.c +++ b/src/strife/m_crispy.c @@ -262,6 +262,10 @@ static void M_CrispyToggleSmoothLightingHook (void) { crispy->smoothlight = !crispy->smoothlight; +#ifdef CRISPY_TRUECOLOR + // [crispy] re-calculate amount of colormaps and light tables + R_InitColormaps(); +#endif // [crispy] re-calculate the zlight[][] array R_InitLightTables(); // [crispy] re-calculate the scalelight[][] array diff --git a/src/strife/p_setup.c b/src/strife/p_setup.c index 6aaacd208..160c39bd9 100644 --- a/src/strife/p_setup.c +++ b/src/strife/p_setup.c @@ -264,13 +264,13 @@ void P_SegLengths (boolean contrast_only) li->fakecontrast = -LIGHTBRIGHT; else if (abs(finesine[li->r_angle >> ANGLETOFINESHIFT]) < rightangle) - li->fakecontrast = -(LIGHTBRIGHT >> 1); + li->fakecontrast = -LIGHTBRIGHT / 2; else if (!dx) li->fakecontrast = LIGHTBRIGHT; else if (abs(finecosine[li->r_angle >> ANGLETOFINESHIFT]) < rightangle) - li->fakecontrast = LIGHTBRIGHT >> 1; + li->fakecontrast = LIGHTBRIGHT / 2; else li->fakecontrast = 0; } diff --git a/src/strife/r_data.c b/src/strife/r_data.c index fe286b7fa..73723cde3 100644 --- a/src/strife/r_data.c +++ b/src/strife/r_data.c @@ -697,6 +697,7 @@ void R_InitColormaps (void) // Load in the light tables, 256 byte align tables. lump = W_GetNumForName(DEH_String("COLORMAP")); colormaps = W_CacheLumpNum(lump, PU_STATIC); + NUMCOLORMAPS = 32; // [crispy] smooth diminishing lighting #else int c, i, j = 0; byte r, g, b; @@ -704,10 +705,19 @@ void R_InitColormaps (void) byte *const playpal = W_CacheLumpName("PLAYPAL", PU_STATIC); byte *const colormap = W_CacheLumpName("COLORMAP", PU_STATIC); - if (!colormaps) + // [crispy] Smoothest diminishing lighting. + // Compiled in but not enabled TrueColor mode + // can't use more than original 32 colormaps. + if (crispy->truecolor && crispy->smoothlight) { - colormaps = (lighttable_t*) Z_Malloc((NUMCOLORMAPS + 1) * 256 * sizeof(lighttable_t), PU_STATIC, 0); + NUMCOLORMAPS = 256; } + else + { + NUMCOLORMAPS = 32; + } + + colormaps = I_Realloc(colormaps, (NUMCOLORMAPS + 1) * 256 * sizeof(lighttable_t)); if (crispy->truecolor) { diff --git a/src/strife/r_main.c b/src/strife/r_main.c index da1d90cd2..73e5bea1b 100644 --- a/src/strife/r_main.c +++ b/src/strife/r_main.c @@ -110,6 +110,7 @@ lighttable_t*** zlight = NULL; int extralight; // [crispy] parameterized for smooth diminishing lighting +int NUMCOLORMAPS; int LIGHTLEVELS; int LIGHTSEGSHIFT; int LIGHTBRIGHT; @@ -718,13 +719,30 @@ void R_InitLightTables (void) // [crispy] smooth diminishing lighting if (crispy->smoothlight) { - LIGHTLEVELS = 32; - LIGHTSEGSHIFT = 3; - LIGHTBRIGHT = 2; - MAXLIGHTSCALE = 48; - LIGHTSCALESHIFT = 12; - MAXLIGHTZ = 1024; - LIGHTZSHIFT = 17; +#ifdef CRISPY_TRUECOLOR + if (crispy->truecolor) + { + // [crispy] if in TrueColor mode, use smoothest diminished lighting + LIGHTLEVELS = 16 << 4; + LIGHTSEGSHIFT = 4 - 4; + LIGHTBRIGHT = 1 << 4; + MAXLIGHTSCALE = 48 << 3; + LIGHTSCALESHIFT = 12 - 3; + MAXLIGHTZ = 128 << 6; + LIGHTZSHIFT = 20 - 6; + } + else +#endif + { + // [crispy] else, use paletted approach + LIGHTLEVELS = 16 << 1; + LIGHTSEGSHIFT = 4 - 1; + LIGHTBRIGHT = 1 << 1; + MAXLIGHTSCALE = 48 << 0; + LIGHTSCALESHIFT = 12 - 0; + MAXLIGHTZ = 128 << 3; + LIGHTZSHIFT = 20 - 3; + } } else { @@ -1094,7 +1112,7 @@ void R_SetupFrame (player_t* player) colormaps // [crispy] sizeof(lighttable_t) not needed in paletted render // and breaks Sigil weapon effects in true color render - + player->fixedcolormap*256/**sizeof(lighttable_t)*/; + + player->fixedcolormap*(NUMCOLORMAPS / 32)*256/**sizeof(lighttable_t)*/; // [crispy] smooth diminishing lighting walllights = scalelightfixed; diff --git a/src/strife/r_main.h b/src/strife/r_main.h index e9af60594..03d0b93ba 100644 --- a/src/strife/r_main.h +++ b/src/strife/r_main.h @@ -78,7 +78,8 @@ extern lighttable_t* fixedcolormap; // Number of diminishing brightness levels. // There a 0-31, i.e. 32 LUT in the COLORMAP lump. -#define NUMCOLORMAPS 32 +// [crispy] parameterized for smooth diminishing lighting +extern int NUMCOLORMAPS; // Blocky/low detail mode. //B remove this?