mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2025-02-22 20:01:14 +00:00
New color brightness formula
Gets more accurate looking results
This commit is contained in:
parent
78a4cdab9f
commit
ac2f81e423
2 changed files with 27 additions and 5 deletions
|
@ -948,6 +948,15 @@ spritemd2found:
|
|||
fclose(f);
|
||||
}
|
||||
|
||||
// Define for getting accurate color brightness readings according to how the human eye sees them.
|
||||
// https://en.wikipedia.org/wiki/Relative_luminance
|
||||
// 0.2126 to red
|
||||
// 0.7152 to green
|
||||
// 0.0722 to blue
|
||||
// (See this same define in k_kart.c!)
|
||||
#define SETBRIGHTNESS(brightness,r,g,b) \
|
||||
brightness = (UINT8)(((1063*((UINT16)r)/5000) + (3576*((UINT16)g)/5000) + (361*((UINT16)b)/5000)) / 3)
|
||||
|
||||
static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, GLMipmap_t *grmip, INT32 skinnum, skincolors_t color)
|
||||
{
|
||||
UINT8 i;
|
||||
|
@ -1028,11 +1037,11 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch,
|
|||
{
|
||||
UINT32 tempcolor;
|
||||
UINT16 imagebright, blendbright, finalbright, colorbright;
|
||||
imagebright = (image->s.red+image->s.green+image->s.blue)/3;
|
||||
blendbright = (blendimage->s.red+blendimage->s.green+blendimage->s.blue)/3;
|
||||
SETBRIGHTNESS(imagebright,image->s.red,image->s.green,image->s.blue);
|
||||
SETBRIGHTNESS(blendbright,blendimage->s.red,blendimage->s.green,blendimage->s.blue);
|
||||
// slightly dumb average between the blend image color and base image colour, usually one or the other will be fully opaque anyway
|
||||
finalbright = (imagebright*(255-blendimage->s.alpha))/255 + (blendbright*blendimage->s.alpha)/255;
|
||||
colorbright = (blendcolor.s.red+blendcolor.s.green+blendcolor.s.blue)/3;
|
||||
SETBRIGHTNESS(colorbright,blendcolor.s.red,blendcolor.s.green,blendcolor.s.blue);
|
||||
|
||||
tempcolor = (finalbright*blendcolor.s.red)/colorbright;
|
||||
tempcolor = min(255, tempcolor);
|
||||
|
@ -1090,6 +1099,8 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch,
|
|||
return;
|
||||
}
|
||||
|
||||
#undef SETBRIGHTNESS
|
||||
|
||||
static void HWR_GetBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, INT32 skinnum, const UINT8 *colormap, skincolors_t color)
|
||||
{
|
||||
// mostly copied from HWR_GetMappedPatch, hence the similarities and comment
|
||||
|
|
15
src/k_kart.c
15
src/k_kart.c
|
@ -255,6 +255,15 @@ UINT8 colortranslations[MAXSKINCOLORS][16] = {
|
|||
|
||||
//#define SALLYALTRAINBOW // Sal's edited version of the below, which keeps a colors' lightness, and looks better with hue-shifted colors like Ruby & Dream. Not strictly *better*, just different...
|
||||
|
||||
// Define for getting accurate color brightness readings according to how the human eye sees them.
|
||||
// https://en.wikipedia.org/wiki/Relative_luminance
|
||||
// 0.2126 to red
|
||||
// 0.7152 to green
|
||||
// 0.0722 to blue
|
||||
// (See this same define in hw_md2.c!)
|
||||
#define SETBRIGHTNESS(brightness,r,g,b) \
|
||||
brightness = (UINT8)(((1063*((UINT16)r)/5000) + (3576*((UINT16)g)/5000) + (361*((UINT16)b)/5000)) / 3)
|
||||
|
||||
/** \brief Generates the rainbow colourmaps that are used when a player has the invincibility power
|
||||
|
||||
\param dest_colormap colormap to populate
|
||||
|
@ -275,7 +284,7 @@ void K_RainbowColormap(UINT8 *dest_colormap, UINT8 skincolor)
|
|||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
color = V_GetColor(colortranslations[skincolor][i]);
|
||||
colorbrightnesses[i] = (UINT8)(((UINT16)color.s.red + (UINT16)color.s.green + (UINT16)color.s.blue)/3);
|
||||
SETBRIGHTNESS(colorbrightnesses[i], color.s.red, color.s.green, color.s.blue);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -288,7 +297,7 @@ void K_RainbowColormap(UINT8 *dest_colormap, UINT8 skincolor)
|
|||
continue;
|
||||
}
|
||||
color = V_GetColor(i);
|
||||
brightness = (UINT8)(((UINT16)color.s.red + (UINT16)color.s.green + (UINT16)color.s.blue)/3);
|
||||
SETBRIGHTNESS(brightness, color.s.red, color.s.green, color.s.blue);
|
||||
#ifdef SALLYALTRAINBOW
|
||||
brightness = 15-(brightness/16); // Yes, 15.
|
||||
dest_colormap[i] = colortranslations[skincolor][brightness];
|
||||
|
@ -307,6 +316,8 @@ void K_RainbowColormap(UINT8 *dest_colormap, UINT8 skincolor)
|
|||
}
|
||||
}
|
||||
|
||||
#undef SETBRIGHTNESS
|
||||
|
||||
/** \brief Generates a translation colormap for Kart, to replace R_GenerateTranslationColormap in r_draw.c
|
||||
|
||||
\param dest_colormap colormap to populate
|
||||
|
|
Loading…
Reference in a new issue