From ae47d2f11d4ae9412d25c977dac0cff74425eb6b Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Tue, 12 Dec 2017 05:13:58 +0000 Subject: [PATCH] New def tokens for "tint": "shadered" or "sr", "shadeblue" or "sb", "shadegreen" or "sg" tint { pal shadered <0-255> shadegreen <0-255> shadeblue <0-255> } Make shade apply a tint based on the RGB. Default values for shade are zero (black). Patch from Fox. git-svn-id: https://svn.eduke32.com/eduke32@6557 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/build/include/build.h | 2 +- source/build/include/hightile.h | 1 + source/build/src/baselayer.cpp | 17 +++++++------- source/build/src/defs.cpp | 41 ++++++++++++++++++++++----------- source/build/src/hightile.cpp | 9 +++++--- source/build/src/polymost.cpp | 7 +++++- 6 files changed, 50 insertions(+), 27 deletions(-) diff --git a/source/build/include/build.h b/source/build/include/build.h index b2af53c12..09fddb524 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -1325,7 +1325,7 @@ extern int32_t glrendmode; #endif void hicinit(void); -void hicsetpalettetint(int32_t palnum, char r, char g, char b, polytintflags_t effect); +void hicsetpalettetint(int32_t palnum, char r, char g, char b, char sr, char sg, char sb, polytintflags_t effect); // flags bitset: 1 = don't compress int32_t hicsetsubsttex(int32_t picnum, int32_t palnum, const char *filen, float alphacut, float xscale, float yscale, float specpower, float specfactor, char flags); diff --git a/source/build/include/hightile.h b/source/build/include/hightile.h index 3f37c2817..2c0846404 100644 --- a/source/build/include/hightile.h +++ b/source/build/include/hightile.h @@ -21,6 +21,7 @@ typedef struct hicreplc_t { typedef struct { polytintflags_t f; uint8_t r, g, b; + uint8_t sr, sg, sb; } polytint_t; extern polytint_t hictinting[MAXPALOOKUPS]; diff --git a/source/build/src/baselayer.cpp b/source/build/src/baselayer.cpp index 22f608881..cf8cbcd6a 100644 --- a/source/build/src/baselayer.cpp +++ b/source/build/src/baselayer.cpp @@ -384,17 +384,18 @@ static int32_t osdfunc_setrendermode(osdfuncparm_t const * const parm) #ifdef DEBUGGINGAIDS static int32_t osdcmd_hicsetpalettetint(osdfuncparm_t const * const parm) { - int32_t pal, cols[3], eff; + int32_t parms[8]; - if (parm->numparms != 5) return OSDCMD_SHOWHELP; + if (parm->numparms < 1 || (int32_t)ARRAY_SIZE(parms) < parm->numparms) return OSDCMD_SHOWHELP; - pal = Batol(parm->parms[0]); - cols[0] = Batol(parm->parms[1]); - cols[1] = Batol(parm->parms[2]); - cols[2] = Batol(parm->parms[3]); - eff = Batol(parm->parms[4]); + size_t i; + for (i = 0; (int32_t)i < parm->numparms; ++i) + parms[i] = Batol(parm->parms[i]); + for (; i < ARRAY_SIZE(parms); ++i) + parms[i] = 0; - hicsetpalettetint(pal,cols[0],cols[1],cols[2],eff); + // order is intentional + hicsetpalettetint(parms[0],parms[1],parms[2],parms[3],parms[5],parms[6],parms[7],parms[4]); return OSDCMD_OK; } diff --git a/source/build/src/defs.cpp b/source/build/src/defs.cpp index a633fc446..d00fe9ceb 100644 --- a/source/build/src/defs.cpp +++ b/source/build/src/defs.cpp @@ -117,6 +117,7 @@ enum scripttoken_t T_SRC_ALPHA, T_ONE_MINUS_SRC_ALPHA, T_DST_ALPHA, T_ONE_MINUS_DST_ALPHA, T_DST_COLOR, T_ONE_MINUS_DST_COLOR, + T_SHADERED, T_SHADEGREEN, T_SHADEBLUE, }; static int32_t lastmodelid = -1, lastvoxid = -1, modelskin = -1, lastmodelskin = -1, seenframe = 0; @@ -495,15 +496,18 @@ static int32_t defsparser(scriptfile *script) break; case T_DEFINETINT: { - int32_t pal, r,g,b,f; + int32_t pal, r,g,b,sr,sg,sb,f; if (scriptfile_getsymbol(script,&pal)) break; if (scriptfile_getnumber(script,&r)) break; if (scriptfile_getnumber(script,&g)) break; if (scriptfile_getnumber(script,&b)) break; + if (scriptfile_getnumber(script,&sr)) break; + if (scriptfile_getnumber(script,&sg)) break; + if (scriptfile_getnumber(script,&sb)) break; if (scriptfile_getnumber(script,&f)) break; //effects #ifdef USE_OPENGL - hicsetpalettetint(pal,r,g,b,f); + hicsetpalettetint(pal,r,g,b,sr,sg,sb,f); #endif } break; @@ -2047,16 +2051,19 @@ static int32_t defsparser(scriptfile *script) case T_TINT: { char *tinttokptr = script->ltextptr; - int32_t red=255, green=255, blue=255, pal=-1, flags=0; + int32_t red=255, green=255, blue=255, shadered=0, shadegreen=0, shadeblue=0, pal=-1, flags=0; char *tintend; static const tokenlist tinttokens[] = { - { "pal", T_PAL }, - { "red", T_RED },{ "r", T_RED }, - { "green", T_GREEN },{ "g", T_GREEN }, - { "blue", T_BLUE },{ "b", T_BLUE }, - { "flags", T_FLAGS } + { "pal", T_PAL }, + { "red", T_RED },{ "r", T_RED }, + { "green", T_GREEN },{ "g", T_GREEN }, + { "blue", T_BLUE },{ "b", T_BLUE }, + { "shadered", T_SHADERED },{ "sr", T_SHADERED }, + { "shadegreen", T_SHADEGREEN },{ "sg", T_SHADEGREEN }, + { "shadeblue", T_SHADEBLUE },{ "sb", T_SHADEBLUE }, + { "flags", T_FLAGS } }; if (scriptfile_getbraces(script,&tintend)) break; @@ -2065,15 +2072,21 @@ static int32_t defsparser(scriptfile *script) switch (getatoken(script,tinttokens,ARRAY_SIZE(tinttokens))) { case T_PAL: - scriptfile_getsymbol(script,&pal); break; + scriptfile_getsymbol(script,&pal); break; case T_RED: - scriptfile_getnumber(script,&red); red = min(255,max(0,red)); break; + scriptfile_getnumber(script,&red); red = min(255,max(0,red)); break; case T_GREEN: - scriptfile_getnumber(script,&green); green = min(255,max(0,green)); break; + scriptfile_getnumber(script,&green); green = min(255,max(0,green)); break; case T_BLUE: - scriptfile_getnumber(script,&blue); blue = min(255,max(0,blue)); break; + scriptfile_getnumber(script,&blue); blue = min(255,max(0,blue)); break; + case T_SHADERED: + scriptfile_getnumber(script,&shadered); shadered = min(255,max(0,shadered)); break; + case T_SHADEGREEN: + scriptfile_getnumber(script,&shadegreen); shadegreen = min(255,max(0,shadegreen)); break; + case T_SHADEBLUE: + scriptfile_getnumber(script,&shadeblue); shadeblue = min(255,max(0,shadeblue)); break; case T_FLAGS: - scriptfile_getsymbol(script,&flags); break; + scriptfile_getsymbol(script,&flags); break; } } @@ -2085,7 +2098,7 @@ static int32_t defsparser(scriptfile *script) } #ifdef USE_OPENGL - hicsetpalettetint(pal,red,green,blue,flags); + hicsetpalettetint(pal,red,green,blue,shadered,shadegreen,shadeblue,flags); #endif } break; diff --git a/source/build/src/hightile.cpp b/source/build/src/hightile.cpp index 3979aecf2..6267451d2 100644 --- a/source/build/src/hightile.cpp +++ b/source/build/src/hightile.cpp @@ -115,12 +115,12 @@ void hicinit(void) // -// hicsetpalettetint(pal,r,g,b,effect) +// hicsetpalettetint(pal,r,g,b,sr,sg,sb,effect) // The tinting values represent a mechanism for emulating the effect of global sector // palette shifts on true-colour textures and only true-colour textures. // effect bitset: 1 = greyscale, 2 = invert // -void hicsetpalettetint(int32_t palnum, char r, char g, char b, polytintflags_t effect) +void hicsetpalettetint(int32_t palnum, char r, char g, char b, char sr, char sg, char sb, polytintflags_t effect) { if ((uint32_t)palnum >= (uint32_t)MAXPALOOKUPS) return; if (!hicinitcounter) hicinit(); @@ -129,6 +129,9 @@ void hicsetpalettetint(int32_t palnum, char r, char g, char b, polytintflags_t e tint.r = r; tint.g = g; tint.b = b; + tint.sr = sr; + tint.sg = sg; + tint.sb = sb; tint.f = effect; } @@ -285,7 +288,7 @@ int32_t hicclearsubst(int32_t picnum, int32_t palnum) #include "compat.h" -void hicsetpalettetint(int32_t palnum, char r, char g, char b, polytintflags_t effect) +void hicsetpalettetint(int32_t palnum, char r, char g, char b, char sr, char sg, char sb, polytintflags_t effect) { UNREFERENCED_PARAMETER(palnum); UNREFERENCED_PARAMETER(r); diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index cd4559bb0..c3a4853fe 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -1892,7 +1892,12 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32 pc[0] = pc[1] = pc[2] = 1.0f; else #endif - pc[0] = pc[1] = pc[2] = getshadefactor(globalshade); + { + polytint_t const & tint = hictinting[globalpal]; + pc[0] = (1.f-(tint.sr*(1.f/255.f)))*getshadefactor(globalshade)+(tint.sr*(1.f/255.f)); + pc[1] = (1.f-(tint.sg*(1.f/255.f)))*getshadefactor(globalshade)+(tint.sg*(1.f/255.f)); + pc[2] = (1.f-(tint.sb*(1.f/255.f)))*getshadefactor(globalshade)+(tint.sb*(1.f/255.f)); + } // spriteext full alpha control pc[3] = float_trans(method & DAMETH_MASKPROPS, drawpoly_blend) * (1.f - drawpoly_alpha);