Fix palette light artifacts caused by dynamic lights in some rare cases

This commit is contained in:
Magnus Norddahl 2017-02-23 23:13:21 +01:00
parent 4d161fbd42
commit b4b391c51e

View file

@ -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<uint32_t>(GPalette.BaseColors[fg].r + ((lit_r * material_r) >> 8), 255);
lit_g = MIN<uint32_t>(GPalette.BaseColors[fg].g + ((lit_g * material_g) >> 8), 255);
lit_b = MIN<uint32_t>(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<uint32_t>(GPalette.BaseColors[fg].r + ((lit_r * material_r) >> 8), 255);
lit_g = MIN<uint32_t>(GPalette.BaseColors[fg].g + ((lit_g * material_g) >> 8), 255);
lit_b = MIN<uint32_t>(GPalette.BaseColors[fg].b + ((lit_b * material_b) >> 8), 255);