diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index f5839520..129daa00 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -231,6 +231,7 @@ struct FSurfaceInfo { FUINT PolyFlags; RGBA_t PolyColor; + RGBA_t TintColor; RGBA_t FadeColor; FLightInfo LightInfo; // jimita 14032019 }; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index a3969ad1..18cf3bb8 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -141,79 +141,87 @@ static INT32 drawcount = 0; void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, UINT32 mixcolor, UINT32 fadecolor) { - RGBA_t mix_color, fog_color, final_color; - INT32 mix; - float fog_alpha; - - mix_color.rgba = mixcolor; - fog_color.rgba = fadecolor; - - mix = mix_color.s.alpha*10/5; - if (mix > 25) mix = 25; - mix *= 255; - mix /= 25; - - // Modulate the colors by alpha. - mix_color.s.red = (UINT8)(CALCLIGHT(mix,mix_color.s.red)); - mix_color.s.green = (UINT8)(CALCLIGHT(mix,mix_color.s.green)); - mix_color.s.blue = (UINT8)(CALCLIGHT(mix,mix_color.s.blue)); - - // Set the surface colors and further modulate the colors by light. - final_color.s.red = (UINT8)(CALCLIGHT((0xFF-mix),0xFF)+CALCLIGHT(mix_color.s.red,0xFF)); - final_color.s.green = (UINT8)(CALCLIGHT((0xFF-mix),0xFF)+CALCLIGHT(mix_color.s.green,0xFF)); - final_color.s.blue = (UINT8)(CALCLIGHT((0xFF-mix),0xFF)+CALCLIGHT(mix_color.s.blue,0xFF)); - final_color.s.alpha = 0xFF; - - // Fog. - fog_alpha = (0xFF - fog_color.s.alpha) / 255.0f; - - // Set the surface colors and further modulate the colors by light. - fog_color.s.red = (UINT8)(((float)fog_color.s.red) * fog_alpha); - fog_color.s.green = (UINT8)(((float)fog_color.s.green) * fog_alpha); - fog_color.s.blue = (UINT8)(((float)fog_color.s.blue) * fog_alpha); - - if (cv_grfog.value) + if (!cv_grshaders.value || (cv_grshaders.value && !cv_grfog.value)) { - // be careful, this may get negative for high lightlevel values. - float fog = (fog_alpha - (light_level/255.0f))*3/2; - if (fog < 0) - fog = 0; + RGBA_t mix_color, fog_color, final_color; + INT32 mix; + float fog_alpha; - float red = ((fog_color.s.red/255.0f) * fog) + ((final_color.s.red/255.0f) * (1.0f - fog)); - float green = ((fog_color.s.green/255.0f) * fog) + ((final_color.s.green/255.0f) * (1.0f - fog)); - float blue = ((fog_color.s.blue/255.0f) * fog) + ((final_color.s.blue/255.0f) * (1.0f - fog)); - final_color.s.red = (UINT8)(red*255.0f); - final_color.s.green = (UINT8)(green*255.0f); - final_color.s.blue = (UINT8)(blue*255.0f); + mix_color.rgba = mixcolor; + fog_color.rgba = fadecolor; + + mix = mix_color.s.alpha*10/5; + if (mix > 25) mix = 25; + mix *= 255; + mix /= 25; + + // Modulate the colors by alpha. + mix_color.s.red = (UINT8)(CALCLIGHT(mix,mix_color.s.red)); + mix_color.s.green = (UINT8)(CALCLIGHT(mix,mix_color.s.green)); + mix_color.s.blue = (UINT8)(CALCLIGHT(mix,mix_color.s.blue)); + + // Set the surface colors and further modulate the colors by light. + final_color.s.red = (UINT8)(CALCLIGHT((0xFF-mix),0xFF)+CALCLIGHT(mix_color.s.red,0xFF)); + final_color.s.green = (UINT8)(CALCLIGHT((0xFF-mix),0xFF)+CALCLIGHT(mix_color.s.green,0xFF)); + final_color.s.blue = (UINT8)(CALCLIGHT((0xFF-mix),0xFF)+CALCLIGHT(mix_color.s.blue,0xFF)); + final_color.s.alpha = 0xFF; + + // Fog. + fog_alpha = (0xFF - fog_color.s.alpha) / 255.0f; + + // Set the surface colors and further modulate the colors by light. + fog_color.s.red = (UINT8)(((float)fog_color.s.red) * fog_alpha); + fog_color.s.green = (UINT8)(((float)fog_color.s.green) * fog_alpha); + fog_color.s.blue = (UINT8)(((float)fog_color.s.blue) * fog_alpha); + + if (cv_grfog.value) + { + // be careful, this may get negative for high lightlevel values. + float fog = (fog_alpha - (light_level/255.0f))*3/2; + if (fog < 0) + fog = 0; + + float red = ((fog_color.s.red/255.0f) * fog) + ((final_color.s.red/255.0f) * (1.0f - fog)); + float green = ((fog_color.s.green/255.0f) * fog) + ((final_color.s.green/255.0f) * (1.0f - fog)); + float blue = ((fog_color.s.blue/255.0f) * fog) + ((final_color.s.blue/255.0f) * (1.0f - fog)); + final_color.s.red = (UINT8)(red*255.0f); + final_color.s.green = (UINT8)(green*255.0f); + final_color.s.blue = (UINT8)(blue*255.0f); + } + + Surface->PolyColor.rgba = final_color.rgba; + Surface->FadeColor.rgba = fog_color.rgba; + Surface->LightInfo.light_level = light_level; + } + else + { + Surface->PolyColor.rgba = 0xFFFFFFFF; + Surface->TintColor.rgba = mixcolor; + Surface->FadeColor.rgba = fadecolor; + Surface->LightInfo.light_level = light_level; } - - Surface->PolyColor.rgba = final_color.rgba; - Surface->FadeColor.rgba = fog_color.rgba; - Surface->LightInfo.light_level = light_level; } void HWR_NoColormapLighting(FSurfaceInfo *Surface, INT32 light_level, UINT32 mixcolor, UINT32 fadecolor) { - RGBA_t mix_color, fog_color, final_color; - INT32 mix, fogmix, lightmix; - float fog_alpha; - - // You see the problem is that darker light isn't actually as dark as it SHOULD be. - lightmix = 255 - ((255 - light_level)*10/7); - - // Don't go out of bounds - if (lightmix < 0) - lightmix = 0; - else if (lightmix > 255) - lightmix = 255; - - mix_color.rgba = mixcolor; - fog_color.rgba = fadecolor; - - // if shaders are off, or shaders are on, but fog is off: - // modulate colors by light here if (!cv_grshaders.value || (cv_grshaders.value && !cv_grfog.value)) { + RGBA_t mix_color, fog_color, final_color; + INT32 mix, fogmix, lightmix; + float fog_alpha; + + // You see the problem is that darker light isn't actually as dark as it SHOULD be. + lightmix = 255 - ((255 - light_level)*10/7); + + // Don't go out of bounds + if (lightmix < 0) + lightmix = 0; + else if (lightmix > 255) + lightmix = 255; + + mix_color.rgba = mixcolor; + fog_color.rgba = fadecolor; + mix = (mix_color.s.alpha*255)/25; fogmix = (fog_color.s.alpha*255)/25; @@ -237,24 +245,27 @@ void HWR_NoColormapLighting(FSurfaceInfo *Surface, INT32 light_level, UINT32 mix final_color.s.green = final_color.s.green+((UINT8)(CALCLIGHT((0xFF-fogmix),(0xFF-lightmix))+CALCLIGHT(fog_color.s.green,(0xFF-lightmix)))); final_color.s.blue = final_color.s.blue+((UINT8)(CALCLIGHT((0xFF-fogmix),(0xFF-lightmix))+CALCLIGHT(fog_color.s.blue,(0xFF-lightmix)))); final_color.s.alpha = 0xFF; + + // Fog. + fog_color.rgba = fadecolor; + fog_alpha = (0xFF - fog_color.s.alpha*10/7) / 255.0f; + + // Set the surface colors and further modulate the colors by light. + fog_color.s.red = (UINT8)(((float)fog_color.s.red) * fog_alpha); + fog_color.s.green = (UINT8)(((float)fog_color.s.green) * fog_alpha); + fog_color.s.blue = (UINT8)(((float)fog_color.s.blue) * fog_alpha); + + Surface->PolyColor.rgba = final_color.rgba; + Surface->FadeColor.rgba = fog_color.rgba; + Surface->LightInfo.light_level = lightmix; } - // if shaders are on: - // modulate colors by light on the shader else - final_color.rgba = 0xFFFFFFFF; - - // Fog. - fog_color.rgba = fadecolor; - fog_alpha = (0xFF - fog_color.s.alpha*10/7) / 255.0f; - - // Set the surface colors and further modulate the colors by light. - fog_color.s.red = (UINT8)(((float)fog_color.s.red) * fog_alpha); - fog_color.s.green = (UINT8)(((float)fog_color.s.green) * fog_alpha); - fog_color.s.blue = (UINT8)(((float)fog_color.s.blue) * fog_alpha); - - Surface->PolyColor.rgba = final_color.rgba; - Surface->FadeColor.rgba = fog_color.rgba; - Surface->LightInfo.light_level = lightmix; + { + Surface->PolyColor.rgba = 0xFFFFFFFF; + Surface->TintColor.rgba = mixcolor; + Surface->FadeColor.rgba = fadecolor; + Surface->LightInfo.light_level = light_level; + } } UINT8 HWR_FogBlockAlpha(INT32 light, UINT32 color) // Let's see if this can work diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 659388d2..8d6ee3c7 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -552,7 +552,8 @@ static boolean gl_batching = false;// are we currently collecting batches? typedef enum { // lighting - gluniform_mix_color, + gluniform_poly_color, + gluniform_tint_color, gluniform_fade_color, gluniform_lighting, @@ -582,37 +583,80 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; // GLSL Software fragment shader // -#define GLSL_INTERNAL_FOG_FUNCTION \ - "float fog(const float dist, const float density, const float globaldensity) {\n" \ - "const float LOG2 = -1.442695;\n" \ - "float d = density * dist;\n" \ - "return 1.0 - clamp(exp2(d * sqrt(d) * globaldensity * LOG2), 0.0, 1.0);\n" \ +// (new shader stuff taken from srb2 shader branch) +// this is missing support for fade_start and fade_end + +#define GLSL_DOOM_COLORMAP \ + "float R_DoomColormap(float light, float z)\n" \ + "{\n" \ + "float lightnum = clamp(light / 17.0, 0.0, 15.0);\n" \ + "float lightz = clamp(z / 16.0, 0.0, 127.0);\n" \ + "float startmap = (15.0 - lightnum) * 4.0;\n" \ + "float scale = 160.0 / (lightz + 1.0);\n" \ + "return startmap - scale * 0.5;\n" \ "}\n" -// https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_gpu_shader_fp64.txt -#define GLSL_INTERNAL_FOG_MIX \ - "float fog_distance = gl_FragCoord.z / gl_FragCoord.w;\n" \ - "float fog_attenuation = floor(fog(fog_distance, 0.0001 * ((256.0-lighting)/24.0), fog_density)*10.0)/10.0;\n" \ - "vec4 fog_color = vec4(fade_color[0], fade_color[1], fade_color[2], 1.0);\n" \ - "vec4 mixed_color = texel * mix_color;\n" \ - "vec4 fog_mix = mix(mixed_color, fog_color, fog_attenuation);\n" \ - "vec4 final_color = mix(fog_mix, fog_color, ((256.0-lighting)/256.0));\n" \ - "final_color[3] = mixed_color[3];\n" +#define GLSL_DOOM_LIGHT_EQUATION \ + "float R_DoomLightingEquation(float light)\n" \ + "{\n" \ + "float z = gl_FragCoord.z / gl_FragCoord.w;\n" \ + "float colormap = floor(R_DoomColormap(light, z)) + 0.5;\n" \ + "return clamp(colormap, 0.0, 31.0) / 32.0;\n" \ + "}\n" + +#define GLSL_SOFTWARE_TINT_EQUATION \ + "if (tint_color.a > 0.0) {\n" \ + "float color_bright = sqrt((base_color.r * base_color.r) + (base_color.g * base_color.g) + (base_color.b * base_color.b));\n" \ + "float strength = sqrt(9.0 * tint_color.a);\n" \ + "final_color.r = clamp((color_bright * (tint_color.r * strength)) + (base_color.r * (1.0 - strength)), 0.0, 1.0);\n" \ + "final_color.g = clamp((color_bright * (tint_color.g * strength)) + (base_color.g * (1.0 - strength)), 0.0, 1.0);\n" \ + "final_color.b = clamp((color_bright * (tint_color.b * strength)) + (base_color.b * (1.0 - strength)), 0.0, 1.0);\n" \ + "}\n" + +#define GLSL_SOFTWARE_FADE_EQUATION \ + "float darkness = R_DoomLightingEquation(lighting);\n" \ + "final_color = mix(final_color, fade_color, darkness);\n" #define GLSL_SOFTWARE_FRAGMENT_SHADER \ "uniform sampler2D tex;\n" \ - "uniform vec4 mix_color;\n" \ + "uniform vec4 poly_color;\n" \ + "uniform vec4 tint_color;\n" \ "uniform vec4 fade_color;\n" \ "uniform float lighting;\n" \ - "uniform int fog_mode;\n" \ - "uniform float fog_density;\n" \ - GLSL_INTERNAL_FOG_FUNCTION \ + GLSL_DOOM_COLORMAP \ + GLSL_DOOM_LIGHT_EQUATION \ "void main(void) {\n" \ "vec4 texel = texture2D(tex, gl_TexCoord[0].st);\n" \ - GLSL_INTERNAL_FOG_MIX \ + "vec4 base_color = texel * poly_color;\n" \ + "vec4 final_color = base_color;\n" \ + GLSL_SOFTWARE_TINT_EQUATION \ + GLSL_SOFTWARE_FADE_EQUATION \ + "final_color.a = texel.a * poly_color.a;\n" \ "gl_FragColor = final_color;\n" \ "}\0" + +// +// Fog block shader (Taken from srb2 shader branch) +// +// Alpha of the planes themselves are still slightly off -- see HWR_FogBlockAlpha +// + +#define GLSL_FOG_FRAGMENT_SHADER \ + "uniform vec4 tint_color;\n" \ + "uniform vec4 fade_color;\n" \ + "uniform float lighting;\n" \ + GLSL_DOOM_COLORMAP \ + GLSL_DOOM_LIGHT_EQUATION \ + "void main(void) {\n" \ + "vec4 base_color = gl_Color;\n" \ + "vec4 final_color = base_color;\n" \ + GLSL_SOFTWARE_TINT_EQUATION \ + GLSL_SOFTWARE_FADE_EQUATION \ + "gl_FragColor = final_color;\n" \ + "}\0" + + // // GLSL generic fragment shader // @@ -644,9 +688,7 @@ static const char *fragment_shaders[] = { GLSL_SOFTWARE_FRAGMENT_SHADER, // Fog fragment shader - "void main(void) {\n" - "gl_FragColor = gl_Color;\n" - "}\0", + GLSL_FOG_FRAGMENT_SHADER, // Sky fragment shader "uniform sampler2D tex;\n" @@ -840,7 +882,8 @@ EXPORT void HWRAPI(LoadShaders) (void) #define GETUNI(uniform) pglGetUniformLocation(shader->program, uniform); // lighting - shader->uniforms[gluniform_mix_color] = GETUNI("mix_color"); + shader->uniforms[gluniform_poly_color] = GETUNI("poly_color"); + shader->uniforms[gluniform_tint_color] = GETUNI("tint_color"); shader->uniforms[gluniform_fade_color] = GETUNI("fade_color"); shader->uniforms[gluniform_lighting] = GETUNI("lighting"); @@ -1626,7 +1669,7 @@ EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo) } } -static void load_shaders(FSurfaceInfo *Surface, GLRGBAFloat *mix, GLRGBAFloat *fade) +static void load_shaders(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAFloat *tint, GLRGBAFloat *fade) { #ifdef GL_SHADERS if (gl_shadersenabled) @@ -1685,7 +1728,9 @@ static void load_shaders(FSurfaceInfo *Surface, GLRGBAFloat *mix, GLRGBAFloat *f function (uniform, a, b, c, d); // polygon - UNIFORM_4(shader->uniforms[gluniform_mix_color], mix->red, mix->green, mix->blue, mix->alpha, pglUniform4f); + UNIFORM_4(shader->uniforms[gluniform_poly_color], poly->red, poly->green, poly->blue, poly->alpha, pglUniform4f); + UNIFORM_4(shader->uniforms[gluniform_tint_color], tint->red, tint->green, tint->blue, tint->alpha, pglUniform4f); + // 13062019 // Check for fog @@ -1794,6 +1839,8 @@ static int comparePolygons(const void *p1, const void *p2) diff64 = poly1->surf.PolyColor.rgba - poly2->surf.PolyColor.rgba; if (diff64 < 0) return -1; else if (diff64 > 0) return 1; + diff64 = poly1->surf.TintColor.rgba - poly2->surf.TintColor.rgba; + if (diff64 < 0) return -1; else if (diff64 > 0) return 1; diff64 = poly1->surf.FadeColor.rgba - poly2->surf.FadeColor.rgba; if (diff64 < 0) return -1; else if (diff64 > 0) return 1; @@ -1840,6 +1887,7 @@ EXPORT void HWRAPI(RenderBatches) (int *sNumPolys, int *sNumVerts, int *sNumCall FSurfaceInfo currentSurfaceInfo; GLRGBAFloat firstPoly = {0,0,0,0}; // may be misleading but this means first PolyColor + GLRGBAFloat firstTint = {0,0,0,0}; GLRGBAFloat firstFade = {0,0,0,0}; boolean needRebind = false; @@ -1901,6 +1949,11 @@ EXPORT void HWRAPI(RenderBatches) (int *sNumPolys, int *sNumVerts, int *sNumCall firstPoly.alpha = byte2float[currentSurfaceInfo.PolyColor.s.alpha]; pglColor4ubv((GLubyte*)¤tSurfaceInfo.PolyColor.s); } + // Tint color + firstTint.red = byte2float[currentSurfaceInfo.TintColor.s.red]; + firstTint.green = byte2float[currentSurfaceInfo.TintColor.s.green]; + firstTint.blue = byte2float[currentSurfaceInfo.TintColor.s.blue]; + firstTint.alpha = byte2float[currentSurfaceInfo.TintColor.s.alpha]; // Fade color firstFade.red = byte2float[currentSurfaceInfo.FadeColor.s.red]; firstFade.green = byte2float[currentSurfaceInfo.FadeColor.s.green]; @@ -1908,7 +1961,7 @@ EXPORT void HWRAPI(RenderBatches) (int *sNumPolys, int *sNumVerts, int *sNumCall firstFade.alpha = byte2float[currentSurfaceInfo.FadeColor.s.alpha]; if (gl_allowshaders) - load_shaders(¤tSurfaceInfo, &firstPoly, &firstFade); + load_shaders(¤tSurfaceInfo, &firstPoly, &firstTint, &firstFade); if (currentPolyFlags & PF_NoTexture) currentTexture = 0; @@ -2022,6 +2075,7 @@ EXPORT void HWRAPI(RenderBatches) (int *sNumPolys, int *sNumVerts, int *sNumCall if (gl_allowshaders) { if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba || + currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba || currentSurfaceInfo.FadeColor.rgba != nextSurfaceInfo.FadeColor.rgba || currentSurfaceInfo.LightInfo.light_level != nextSurfaceInfo.LightInfo.light_level) { @@ -2070,6 +2124,7 @@ EXPORT void HWRAPI(RenderBatches) (int *sNumPolys, int *sNumVerts, int *sNumCall if (changeShader) { GLRGBAFloat poly = {0,0,0,0}; + GLRGBAFloat tint = {0,0,0,0}; GLRGBAFloat fade = {0,0,0,0}; gl_currentshaderprogram = nextShader; gl_shaderprogramchanged = true; @@ -2081,13 +2136,18 @@ EXPORT void HWRAPI(RenderBatches) (int *sNumPolys, int *sNumVerts, int *sNumCall poly.blue = byte2float[nextSurfaceInfo.PolyColor.s.blue]; poly.alpha = byte2float[nextSurfaceInfo.PolyColor.s.alpha]; } + // Tint color + tint.red = byte2float[nextSurfaceInfo.TintColor.s.red]; + tint.green = byte2float[nextSurfaceInfo.TintColor.s.green]; + tint.blue = byte2float[nextSurfaceInfo.TintColor.s.blue]; + tint.alpha = byte2float[nextSurfaceInfo.TintColor.s.alpha]; // Fade color fade.red = byte2float[nextSurfaceInfo.FadeColor.s.red]; fade.green = byte2float[nextSurfaceInfo.FadeColor.s.green]; fade.blue = byte2float[nextSurfaceInfo.FadeColor.s.blue]; fade.alpha = byte2float[nextSurfaceInfo.FadeColor.s.alpha]; - load_shaders(&nextSurfaceInfo, &poly, &fade); + load_shaders(&nextSurfaceInfo, &poly, &tint, &fade); currentShader = nextShader; changeShader = false; @@ -2114,6 +2174,7 @@ EXPORT void HWRAPI(RenderBatches) (int *sNumPolys, int *sNumVerts, int *sNumCall if (changeSurfaceInfo) { GLRGBAFloat poly = {0,0,0,0}; + GLRGBAFloat tint = {0,0,0,0}; GLRGBAFloat fade = {0,0,0,0}; gl_shaderprogramchanged = false; if (nextPolyFlags & PF_Modulated) @@ -2127,13 +2188,18 @@ EXPORT void HWRAPI(RenderBatches) (int *sNumPolys, int *sNumVerts, int *sNumCall } if (gl_allowshaders) { + // Tint color + tint.red = byte2float[nextSurfaceInfo.TintColor.s.red]; + tint.green = byte2float[nextSurfaceInfo.TintColor.s.green]; + tint.blue = byte2float[nextSurfaceInfo.TintColor.s.blue]; + tint.alpha = byte2float[nextSurfaceInfo.TintColor.s.alpha]; // Fade color fade.red = byte2float[nextSurfaceInfo.FadeColor.s.red]; fade.green = byte2float[nextSurfaceInfo.FadeColor.s.green]; fade.blue = byte2float[nextSurfaceInfo.FadeColor.s.blue]; fade.alpha = byte2float[nextSurfaceInfo.FadeColor.s.alpha]; - load_shaders(&nextSurfaceInfo, &poly, &fade); + load_shaders(&nextSurfaceInfo, &poly, &tint, &fade); } currentSurfaceInfo = nextSurfaceInfo; changeSurfaceInfo = false; @@ -2199,7 +2265,8 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUI } else { - static GLRGBAFloat mix = {0,0,0,0}; + static GLRGBAFloat poly = {0,0,0,0}; + static GLRGBAFloat tint = {0,0,0,0}; static GLRGBAFloat fade = {0,0,0,0}; SetBlend(PolyFlags); //TODO: inline (#pragma..) @@ -2210,14 +2277,20 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUI // If Modulated, mix the surface colour to the texture if (CurrentPolyFlags & PF_Modulated) { - // Mix color - mix.red = byte2float[pSurf->PolyColor.s.red]; - mix.green = byte2float[pSurf->PolyColor.s.green]; - mix.blue = byte2float[pSurf->PolyColor.s.blue]; - mix.alpha = byte2float[pSurf->PolyColor.s.alpha]; + // Poly color + poly.red = byte2float[pSurf->PolyColor.s.red]; + poly.green = byte2float[pSurf->PolyColor.s.green]; + poly.blue = byte2float[pSurf->PolyColor.s.blue]; + poly.alpha = byte2float[pSurf->PolyColor.s.alpha]; pglColor4ubv((GLubyte*)&pSurf->PolyColor.s); } + + // Tint color + tint.red = byte2float[pSurf->TintColor.s.red]; + tint.green = byte2float[pSurf->TintColor.s.green]; + tint.blue = byte2float[pSurf->TintColor.s.blue]; + tint.alpha = byte2float[pSurf->TintColor.s.alpha]; // Fade color fade.red = byte2float[pSurf->FadeColor.s.red]; @@ -2226,7 +2299,7 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUI fade.alpha = byte2float[pSurf->FadeColor.s.alpha]; } - load_shaders(pSurf, &mix, &fade); + load_shaders(pSurf, &poly, &tint, &fade); pglVertexPointer(3, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].x); pglTexCoordPointer(2, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].s); @@ -2526,7 +2599,8 @@ EXPORT void HWRAPI(CreateModelVBOs) (model_t *model) static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 tics, INT32 nextFrameIndex, FTransform *pos, float scale, UINT8 flipped, FSurfaceInfo *Surface) { - static GLRGBAFloat mix = {0,0,0,0}; + static GLRGBAFloat poly = {0,0,0,0}; + static GLRGBAFloat tint = {0,0,0,0}; static GLRGBAFloat fade = {0,0,0,0}; float pol = 0.0f; @@ -2555,24 +2629,29 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 pol = 0.0f; } - mix.red = byte2float[Surface->PolyColor.s.red]; - mix.green = byte2float[Surface->PolyColor.s.green]; - mix.blue = byte2float[Surface->PolyColor.s.blue]; - mix.alpha = byte2float[Surface->PolyColor.s.alpha]; + poly.red = byte2float[Surface->PolyColor.s.red]; + poly.green = byte2float[Surface->PolyColor.s.green]; + poly.blue = byte2float[Surface->PolyColor.s.blue]; + poly.alpha = byte2float[Surface->PolyColor.s.alpha]; - if (mix.alpha < 1) + if (poly.alpha < 1) SetBlend(PF_Translucent|PF_Modulated); else SetBlend(PF_Masked|PF_Modulated|PF_Occlude); pglColor4ubv((GLubyte*)&Surface->PolyColor.s); + tint.red = byte2float[Surface->TintColor.s.red]; + tint.green = byte2float[Surface->TintColor.s.green]; + tint.blue = byte2float[Surface->TintColor.s.blue]; + tint.alpha = byte2float[Surface->TintColor.s.alpha]; + fade.red = byte2float[Surface->FadeColor.s.red]; fade.green = byte2float[Surface->FadeColor.s.green]; fade.blue = byte2float[Surface->FadeColor.s.blue]; fade.alpha = byte2float[Surface->FadeColor.s.alpha]; - load_shaders(Surface, &mix, &fade); + load_shaders(Surface, &poly, &tint, &fade); pglEnable(GL_CULL_FACE); pglEnable(GL_NORMALIZE);