diff --git a/src/swrenderer/drawers/r_draw_pal.cpp b/src/swrenderer/drawers/r_draw_pal.cpp index 84b9745dd4..c0625e3fc3 100644 --- a/src/swrenderer/drawers/r_draw_pal.cpp +++ b/src/swrenderer/drawers/r_draw_pal.cpp @@ -112,9 +112,9 @@ namespace swrenderer uint8_t PalWall1Command::AddLights(const TriLight *lights, int num_lights, float viewpos_z, uint8_t fg, uint8_t material) { - uint32_t lit_r = GPalette.BaseColors[fg].r; - uint32_t lit_g = GPalette.BaseColors[fg].g; - uint32_t lit_b = GPalette.BaseColors[fg].b; + uint32_t lit_r = 0; + 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; @@ -144,14 +144,14 @@ namespace swrenderer float point_attenuation = lights[i].y * rcp_dist * distance_attenuation; uint32_t attenuation = (uint32_t)(lights[i].y == 0.0f ? simple_attenuation : point_attenuation); - lit_r += (light_color_r * material_r * attenuation) >> 16; - lit_g += (light_color_g * material_g * attenuation) >> 16; - lit_b += (light_color_b * material_b * attenuation) >> 16; + lit_r += (light_color_r * attenuation) >> 8; + lit_g += (light_color_g * attenuation) >> 8; + lit_b += (light_color_b * attenuation) >> 8; } - lit_r = MIN(lit_r, 255); - lit_g = MIN(lit_g, 255); - lit_b = MIN(lit_b, 255); + 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); return RGB256k.All[((lit_r >> 2) << 12) | ((lit_g >> 2) << 6) | (lit_b >> 2)]; } @@ -1722,9 +1722,9 @@ namespace swrenderer uint8_t PalSpanCommand::AddLights(const TriLight *lights, int num_lights, float viewpos_x, uint8_t fg, uint8_t material) { - uint32_t lit_r = GPalette.BaseColors[fg].r; - uint32_t lit_g = GPalette.BaseColors[fg].g; - uint32_t lit_b = GPalette.BaseColors[fg].b; + uint32_t lit_r = 0; + 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; @@ -1754,14 +1754,14 @@ namespace swrenderer float point_attenuation = lights[i].z * rcp_dist * distance_attenuation; uint32_t attenuation = (uint32_t)(lights[i].z == 0.0f ? simple_attenuation : point_attenuation); - lit_r += (light_color_r * material_r * attenuation) >> 16; - lit_g += (light_color_g * material_g * attenuation) >> 16; - lit_b += (light_color_b * material_b * attenuation) >> 16; + lit_r += (light_color_r * attenuation) >> 8; + lit_g += (light_color_g * attenuation) >> 8; + lit_b += (light_color_b * attenuation) >> 8; } - lit_r = MIN(lit_r, 255); - lit_g = MIN(lit_g, 255); - lit_b = MIN(lit_b, 255); + 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); return RGB256k.All[((lit_r >> 2) << 12) | ((lit_g >> 2) << 6) | (lit_b >> 2)]; } diff --git a/tools/drawergen/fixedfunction/drawspancodegen.cpp b/tools/drawergen/fixedfunction/drawspancodegen.cpp index 0fdadaa84f..f5a3b46c7b 100644 --- a/tools/drawergen/fixedfunction/drawspancodegen.cpp +++ b/tools/drawergen/fixedfunction/drawspancodegen.cpp @@ -237,7 +237,7 @@ SSAVec4i DrawSpanCodegen::Shade(SSAVec4i fg, bool isSimpleShade) else c = shade_bgra_advanced(fg, light, shade_constants); - stack_lit_color.store(c); + stack_lit_color.store(SSAVec4i(0)); stack_light_index.store(SSAInt(0)); SSAForBlock block; @@ -269,14 +269,14 @@ SSAVec4i DrawSpanCodegen::Shade(SSAVec4i fg, bool isSimpleShade) SSAFloat point_attenuation = light_z * rcp_dist * distance_attenuation; SSAInt attenuation = SSAInt((light_z == SSAFloat(0.0f)).select(simple_attenuation, point_attenuation), true); - SSAVec4i contribution = (light_color * fg * attenuation) >> 16; + SSAVec4i contribution = (light_color * attenuation) >> 8; stack_lit_color.store(lit_color + contribution); stack_light_index.store(light_index + 1); } block.end_block(); - return stack_lit_color.load(); + return c + ((stack_lit_color.load() * fg) >> 8); } SSAVec4i DrawSpanCodegen::Blend(SSAVec4i fg, SSAVec4i bg, DrawSpanVariant variant) diff --git a/tools/drawergen/fixedfunction/drawwallcodegen.cpp b/tools/drawergen/fixedfunction/drawwallcodegen.cpp index 9207fb63a7..df89432392 100644 --- a/tools/drawergen/fixedfunction/drawwallcodegen.cpp +++ b/tools/drawergen/fixedfunction/drawwallcodegen.cpp @@ -169,7 +169,7 @@ SSAVec4i DrawWallCodegen::Shade(SSAVec4i fg, bool isSimpleShade) else c = shade_bgra_advanced(fg, light, shade_constants); - stack_lit_color.store(c); + stack_lit_color.store(SSAVec4i(0)); stack_light_index.store(SSAInt(0)); SSAForBlock block; @@ -201,14 +201,14 @@ SSAVec4i DrawWallCodegen::Shade(SSAVec4i fg, bool isSimpleShade) SSAFloat point_attenuation = light_y * rcp_dist * distance_attenuation; SSAInt attenuation = SSAInt((light_y == SSAFloat(0.0f)).select(simple_attenuation, point_attenuation), true); - SSAVec4i contribution = (light_color * fg * attenuation) >> 16; + SSAVec4i contribution = (light_color * attenuation) >> 8; stack_lit_color.store(lit_color + contribution); stack_light_index.store(light_index + 1); } block.end_block(); - return stack_lit_color.load(); + return c + ((stack_lit_color.load() * fg) >> 8); } SSAVec4i DrawWallCodegen::Blend(SSAVec4i fg, SSAVec4i bg, DrawWallVariant variant)