mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-04-27 20:41:46 +00:00
New color brightness formula
Gets more accurate looking results
This commit is contained in:
parent
05ad8937b3
commit
60c5eb372b
2 changed files with 27 additions and 5 deletions
|
|
@ -948,6 +948,15 @@ spritemd2found:
|
||||||
fclose(f);
|
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)
|
static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, GLMipmap_t *grmip, INT32 skinnum, skincolors_t color)
|
||||||
{
|
{
|
||||||
UINT8 i;
|
UINT8 i;
|
||||||
|
|
@ -1028,11 +1037,11 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch,
|
||||||
{
|
{
|
||||||
UINT32 tempcolor;
|
UINT32 tempcolor;
|
||||||
UINT16 imagebright, blendbright, finalbright, colorbright;
|
UINT16 imagebright, blendbright, finalbright, colorbright;
|
||||||
imagebright = (image->s.red+image->s.green+image->s.blue)/3;
|
SETBRIGHTNESS(imagebright,image->s.red,image->s.green,image->s.blue);
|
||||||
blendbright = (blendimage->s.red+blendimage->s.green+blendimage->s.blue)/3;
|
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
|
// 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;
|
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 = (finalbright*blendcolor.s.red)/colorbright;
|
||||||
tempcolor = min(255, tempcolor);
|
tempcolor = min(255, tempcolor);
|
||||||
|
|
@ -1090,6 +1099,8 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef SETBRIGHTNESS
|
||||||
|
|
||||||
static void HWR_GetBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, INT32 skinnum, const UINT8 *colormap, skincolors_t color)
|
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
|
// 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 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
|
/** \brief Generates the rainbow colourmaps that are used when a player has the invincibility power
|
||||||
|
|
||||||
\param dest_colormap colormap to populate
|
\param dest_colormap colormap to populate
|
||||||
|
|
@ -275,7 +284,7 @@ void K_RainbowColormap(UINT8 *dest_colormap, UINT8 skincolor)
|
||||||
for (i = 0; i < 16; i++)
|
for (i = 0; i < 16; i++)
|
||||||
{
|
{
|
||||||
color = V_GetColor(colortranslations[skincolor][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
|
#endif
|
||||||
|
|
||||||
|
|
@ -288,7 +297,7 @@ void K_RainbowColormap(UINT8 *dest_colormap, UINT8 skincolor)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
color = V_GetColor(i);
|
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
|
#ifdef SALLYALTRAINBOW
|
||||||
brightness = 15-(brightness/16); // Yes, 15.
|
brightness = 15-(brightness/16); // Yes, 15.
|
||||||
dest_colormap[i] = colortranslations[skincolor][brightness];
|
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
|
/** \brief Generates a translation colormap for Kart, to replace R_GenerateTranslationColormap in r_draw.c
|
||||||
|
|
||||||
\param dest_colormap colormap to populate
|
\param dest_colormap colormap to populate
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue