From b70f02fdf263632b7e9549044b6da58fe74476ba Mon Sep 17 00:00:00 2001 From: Bigfoot71 Date: Wed, 12 Mar 2025 18:32:36 +0100 Subject: [PATCH] apply perspective correction to colors --- src/external/rlsw.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/external/rlsw.h b/src/external/rlsw.h index 6b7a7376a..d8155636c 100644 --- a/src/external/rlsw.h +++ b/src/external/rlsw.h @@ -930,6 +930,12 @@ void sw_project_and_clip_triangle(sw_vertex_t polygon[SW_MAX_CLIPPED_POLYGON_VER v->texcoord[0] *= v->homogeneous[3]; v->texcoord[1] *= v->homogeneous[3]; + // Division of colors (perspective correct) + v->color[0] *= v->homogeneous[3]; + v->color[1] *= v->homogeneous[3]; + v->color[2] *= v->homogeneous[3]; + v->color[3] *= v->homogeneous[3]; + // Transform to screen space v->screen[0] = RLSW.vpPos[0] + (v->homogeneous[0] + 1.0f) * 0.5f * RLSW.vpDim[0]; v->screen[1] = RLSW.vpPos[1] + (v->homogeneous[1] + 1.0f) * 0.5f * RLSW.vpDim[1]; @@ -1012,7 +1018,7 @@ void FUNC_NAME(const sw_texture_t* tex, const sw_vertex_t* start, /* Interpolate the color and modulate by the texture color */ \ for (int i = 0; i < 4; i++) { \ float finalColor = texColor[i]; \ - finalColor *= start->color[i] + t * dcol[i]; \ + finalColor *= (start->color[i] + t * dcol[i]) * w; \ dst[i] = (uint8_t)(sw_saturate(finalColor) * 255.0f); \ } \ } \ @@ -1020,7 +1026,7 @@ void FUNC_NAME(const sw_texture_t* tex, const sw_vertex_t* start, { \ /* Interpolate the color */ \ for (int i = 0; i < 4; i++) { \ - float finalColor = start->color[i] + t * dcol[i]; \ + float finalColor = (start->color[i] + t * dcol[i]) * w; \ dst[i] = (uint8_t)(sw_saturate(finalColor) * 255.0f); \ } \ } \