From b4b391c51e4f929225308807eef8f3c4f5e5256b Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 23 Feb 2017 23:13:21 +0100 Subject: [PATCH] Fix palette light artifacts caused by dynamic lights in some rare cases --- src/swrenderer/drawers/r_draw_pal.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/swrenderer/drawers/r_draw_pal.cpp b/src/swrenderer/drawers/r_draw_pal.cpp index 31aa65dd2..3e5c33e1c 100644 --- a/src/swrenderer/drawers/r_draw_pal.cpp +++ b/src/swrenderer/drawers/r_draw_pal.cpp @@ -121,10 +121,6 @@ namespace swrenderer uint32_t lit_g = 0; uint32_t lit_b = 0; - uint32_t material_r = GPalette.BaseColors[material].r; - uint32_t material_g = GPalette.BaseColors[material].g; - uint32_t material_b = GPalette.BaseColors[material].b; - for (int i = 0; i < num_lights; i++) { uint32_t light_color_r = RPART(lights[i].color); @@ -158,6 +154,13 @@ namespace swrenderer lit_b += (light_color_b * attenuation) >> 8; } + if (lit_r == 0 && lit_g == 0 && lit_b == 0) + return fg; + + uint32_t material_r = GPalette.BaseColors[material].r; + uint32_t material_g = GPalette.BaseColors[material].g; + uint32_t material_b = GPalette.BaseColors[material].b; + lit_r = MIN(GPalette.BaseColors[fg].r + ((lit_r * material_r) >> 8), 255); lit_g = MIN(GPalette.BaseColors[fg].g + ((lit_g * material_g) >> 8), 255); lit_b = MIN(GPalette.BaseColors[fg].b + ((lit_b * material_b) >> 8), 255); @@ -1920,10 +1923,6 @@ namespace swrenderer uint32_t lit_g = 0; uint32_t lit_b = 0; - uint32_t material_r = GPalette.BaseColors[material].r; - uint32_t material_g = GPalette.BaseColors[material].g; - uint32_t material_b = GPalette.BaseColors[material].b; - for (int i = 0; i < num_lights; i++) { uint32_t light_color_r = RPART(lights[i].color); @@ -1957,6 +1956,13 @@ namespace swrenderer lit_b += (light_color_b * attenuation) >> 8; } + if (lit_r == 0 && lit_g == 0 && lit_b == 0) + return fg; + + uint32_t material_r = GPalette.BaseColors[material].r; + uint32_t material_g = GPalette.BaseColors[material].g; + uint32_t material_b = GPalette.BaseColors[material].b; + lit_r = MIN(GPalette.BaseColors[fg].r + ((lit_r * material_r) >> 8), 255); lit_g = MIN(GPalette.BaseColors[fg].g + ((lit_g * material_g) >> 8), 255); lit_b = MIN(GPalette.BaseColors[fg].b + ((lit_b * material_b) >> 8), 255);