Skip to content

Commit

Permalink
Implement "Less Blinding Tints" Cherry Display Option (#11)
Browse files Browse the repository at this point in the history
* Implement "Less Blinding Tints" Cherry Display option

* Update CHANGELOG and README

---------

Co-authored-by: Xemonix <[email protected]>
  • Loading branch information
Spaicrab and xemonix0 authored Nov 12, 2024
1 parent 16e0933 commit efe7696
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## New Features

- _Less Blinding Tints_ setting [thanks to @Spaicrab]

### Level table

- Press `Del` to _erase selected map stats_
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Although the new code has been written with the intention of not breaking demo c
- _Rocket Trails_ setting [p.f. [Doom Retro](https://www.doomretro.com/)] (with extended customization via the _Rocket Trails Interval_ and _Smoke Translucency_ settings)
- Just like in Doom Retro, rocket trails are disabled if a [DSDHacked](https://doomwiki.org/wiki/DSDHacked) patch replaces the rocket smoke thing definition or any of its states or sprites
- _Mouselook_ option for the _Stretch Short Skies_ setting to enable sky stretching only when mouselook is enabled
- _Less Blinding Tints_ setting

#### Intermission screen

Expand Down
7 changes: 7 additions & 0 deletions src/m_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,13 @@ default_t defaults[] = {
"Rocket smoke translucency percentage"
},

{ // Less Blinding Tints
"less_blinding_tints",
(config_t *) &less_blinding_tints, NULL,
{0}, {0,1}, number, ss_gen, wad_yes,
"Less blinding tints"
},

// [Cherry] ---------------------------------------------------------------/

//
Expand Down
4 changes: 4 additions & 0 deletions src/mn_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -3020,6 +3020,9 @@ static setup_menu_t gen_settings5[] = {
{"Smoke Translucency", S_THERMO | S_ACTION | S_PCT | S_STRICT | S_CRITICAL,
M_X_THRM8, M_THRM_SPC, {"rocket_trails_tran"},
m_null, input_null, str_empty, SmokeTrans},
MI_GAP,
{"Less Blinding Tints", S_ONOFF | S_STRICT,
M_X, M_SPC, {"less_blinding_tints"}},

MI_END
};
Expand Down Expand Up @@ -3248,6 +3251,7 @@ static void UpdatePaletteItems(void)
DisableItem(!palette_changes, gen_settings5, "no_radsuit_tint");
DisableItem(!palette_changes, gen_settings5, "damagecount_cap");
DisableItem(!palette_changes, gen_settings5, "bonuscount_cap");
DisableItem(!palette_changes, gen_settings5, "less_blinding_tints");
DisableItem(!palette_changes, gen_settings6, "a11y_invul_colormap");
}

Expand Down
10 changes: 8 additions & 2 deletions src/st_stuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,8 @@ static void ST_doPaletteStuff(void)
byte* pal;
int cnt = plyr->damagecount;

static boolean old_less_blinding_tints = false; // [Cherry]

// killough 7/14/98: beta version did not cause red berserk palette
if (!beta_emulation)

Expand Down Expand Up @@ -916,12 +918,16 @@ static void ST_doPaletteStuff(void)
else
palette = 0;

if (palette != st_palette)
if (palette != st_palette
|| old_less_blinding_tints != less_blinding_tints) // [Cherry]
{
old_less_blinding_tints = less_blinding_tints;
st_palette = palette;
// haleyjd: must cast to byte *, arith. on void pointer is
// a GNU C extension
pal = (byte *)W_CacheLumpNum(lu_palette, PU_CACHE) + palette*768;
pal = STRICTMODE(less_blinding_tints) // [Cherry] Less Blinding Tints
? (byte *)(alttintpal + palette*768)
: (byte *)W_CacheLumpNum(lu_palette, PU_CACHE) + palette*768;
I_SetPalette (pal);
}
}
Expand Down
121 changes: 120 additions & 1 deletion src/v_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "doomdef.h"
#include "doomstat.h"
#include "doomtype.h"
#include "i_gamma.h" // [Cherry] Less Blinding Tints
#include "i_system.h"
#include "i_video.h"
#include "m_argv.h"
Expand Down Expand Up @@ -150,9 +151,122 @@ byte *shadow_tranmap; // HUD/menu shadows
byte *pspr_tranmap; // Translucent flashes
byte *xhair_tranmap; // Translucent crosshair

// [Cherry]
// [Cherry] /-----------------------------------------------------------------

byte *smoke_tranmap; // Translucent rocket trails

// Less Blinding Tints ---

boolean less_blinding_tints;
byte alttintpal[14*768];

static float HueToRgb(float p, float q, float t)
{
if (t < 0.0f) t += 1.0f;
else if (t > 1.0f) t -= 1.0f;
if (t < 1.0f/6.0f) return p + (q - p) * 6.0f * t;
if (t < 1.0f/2.0f) return q;
if (t < 2.0f/3.0f) return p + (q - p) * (2.0f/3.0f - t) * 6.0f;
return p;
}

static void HslToRgb(float h, float s, float l, int *rgb)
{
if (s == 0.0f)
{
rgb[0] = rgb[1] = rgb[2] = roundf(l * 255.0f);
return;
}

const float q = l < 0.5f ? l * (1.0f + s) : l + s - l * s;
const float p = 2.0f * l - q;

const float r = HueToRgb(p, q, h + 1.0f/3.0f);
const float g = HueToRgb(p, q, h);
const float b = HueToRgb(p, q, h - 1.0f/3.0f);

rgb[0] = roundf(r * 255.0f);
rgb[1] = roundf(g * 255.0f);
rgb[2] = roundf(b * 255.0f);
}

static void RgbToHsl(float r, float g, float b, float *hsl)
{
r /= 255.0f;
g /= 255.0f;
b /= 255.0f;

const float vmax = MAX(MAX(r, g), b);
const float vmin = MIN(MIN(r, g), b);
const float d = vmax - vmin;

hsl[0] = hsl[1] = hsl[2] = (vmax + vmin) / 2.0f;

if (vmax == vmin)
{
hsl[0] = hsl[1] = 0.0f;
return;
}

hsl[1] = hsl[0] > 0.5f ? d / (2.0f - vmax - vmin) : d / (vmax + vmin);

if (vmax == r) hsl[0] = (g - b) / d + (g < b ? 6.0f : 0.0f);
if (vmax == g) hsl[0] = (b - r) / d + 2.0f;
if (vmax == b) hsl[0] = (r - g) / d + 4.0f;
hsl[0] /= 6.0f;
}

static void GenerateTintedPalette(byte *palsrc, const byte *gamma, float lightness,
int palette_start, int palette_end)
{
// Cap lightness so whites get translated too
const float capped_lightness = MIN(lightness, 0.9);

for (int palette = palette_start; palette <= palette_end; palette++)
{
byte *pal_byte = (byte *)(palsrc + 768 * palette);

const byte tinted_r = gamma[pal_byte[0]];
const byte tinted_g = gamma[pal_byte[1]];
const byte tinted_b = gamma[pal_byte[2]];

float tinted_hsl[3];
RgbToHsl(tinted_r, tinted_g, tinted_b, tinted_hsl);

// Replace the tinted color's lightness
int rgb[3];
HslToRgb(tinted_hsl[0], tinted_hsl[1], capped_lightness, rgb);

for (int i = 0; i < 3; i++)
{
*pal_byte++ = rgb[i];
}
}
}
static void InitLessBlindingTints(void)
{
const byte *const gamma = gammatable[gamma2];
for (int color = 0; color < 256; color++)
{
byte *const palsrc = alttintpal + color * 3;

const byte r = gamma[palsrc[0]];
const byte g = gamma[palsrc[1]];
const byte b = gamma[palsrc[2]];

float hsl[3];
RgbToHsl(r, g, b, hsl);

const float lightness = hsl[2];

GenerateTintedPalette(palsrc, gamma, lightness, 2, 8); // Pain tint
GenerateTintedPalette(palsrc, gamma, lightness, 10, 12); // Bonus/Pickup tint
GenerateTintedPalette(palsrc, gamma, lightness, 13, 13); // Radsuit tint
}
}

// [Cherry] -----------------------------------------------------------------/

// killough 5/2/98: tiny engine driven by table above
void V_InitColorTranslation(void)
{
Expand Down Expand Up @@ -249,6 +363,11 @@ void V_InitColorTranslation(void)

nightvision[i] = I_GetPaletteIndex(playpal, 0.0, greatest, 0.0);
}

// [Cherry] Less Blinding Tints ==========================================

memcpy(alttintpal, playpal, sizeof(alttintpal));
InitLessBlindingTints();
}

void WriteGeneratedLumpWad(const char *filename)
Expand Down
3 changes: 3 additions & 0 deletions src/v_video.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ extern byte *xhair_tranmap; // Translucent crosshair

// [Cherry]
extern byte *smoke_tranmap; // Translucent rocket trails
// Less Blinding Tints
extern boolean less_blinding_tints;
extern byte alttintpal[14*768];

// array of pointers to color translation tables
extern byte *colrngs[];
Expand Down

0 comments on commit efe7696

Please sign in to comment.