diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 48a5bcb0f..f93e0579f 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -274,24 +274,32 @@ void R_MapPlane (int y, int x1) visplane_light *cur_node = ds_light_list; while (cur_node && nextlightindex < 64 * 1024) { - uint32_t red = cur_node->lightsource->GetRed(); - uint32_t green = cur_node->lightsource->GetGreen(); - uint32_t blue = cur_node->lightsource->GetBlue(); - double lightX = cur_node->lightsource->X() - ViewPos.X; double lightY = cur_node->lightsource->Y() - ViewPos.Y; double lightZ = cur_node->lightsource->Z() - ViewPos.Z; - nextlightindex++; - auto &light = dc_lights[dc_num_lights++]; - light.x = (float)(lightX * ViewSin - lightY * ViewCos); - light.y = (float)(lightX * ViewTanCos + lightY * ViewTanSin) - dc_viewpos.Y; - light.z = (float)lightZ - dc_viewpos.Z; - light.radius = 256.0f / cur_node->lightsource->GetRadius(); - light.color = (red << 16) | (green << 8) | blue; + float lx = (float)(lightX * ViewSin - lightY * ViewCos); + float ly = (float)(lightX * ViewTanCos + lightY * ViewTanSin) - dc_viewpos.Y; + float lz = (float)lightZ - dc_viewpos.Z; // Precalculate the constant part of the dot here so the drawer doesn't have to. - light.y = light.y * light.y + light.z * light.z; + float lconstant = ly * ly + lz * lz; + + // Include light only if it touches this row + float radius = cur_node->lightsource->GetRadius(); + if (radius * radius >= lconstant) + { + uint32_t red = cur_node->lightsource->GetRed(); + uint32_t green = cur_node->lightsource->GetGreen(); + uint32_t blue = cur_node->lightsource->GetBlue(); + + nextlightindex++; + auto &light = dc_lights[dc_num_lights++]; + light.x = lx; + light.y = lconstant; + light.radius = 256.0f / radius; + light.color = (red << 16) | (green << 8) | blue; + } cur_node = cur_node->next; } diff --git a/src/r_walldraw.cpp b/src/r_walldraw.cpp index f43b8f9d4..0523d8960 100644 --- a/src/r_walldraw.cpp +++ b/src/r_walldraw.cpp @@ -561,24 +561,32 @@ static void Draw1Column(int x, int y1, int y2, WallSampler &sampler, void(*draw1 { if (!(cur_node->lightsource->flags2&MF2_DORMANT)) { - uint32_t red = cur_node->lightsource->GetRed(); - uint32_t green = cur_node->lightsource->GetGreen(); - uint32_t blue = cur_node->lightsource->GetBlue(); - double lightX = cur_node->lightsource->X() - ViewPos.X; double lightY = cur_node->lightsource->Y() - ViewPos.Y; double lightZ = cur_node->lightsource->Z() - ViewPos.Z; - nextlightindex++; - auto &light = dc_lights[dc_num_lights++]; - light.x = (float)(lightX * ViewSin - lightY * ViewCos) - dc_viewpos.X; - light.y = (float)(lightX * ViewTanCos + lightY * ViewTanSin) - dc_viewpos.Y; - light.z = (float)lightZ; - light.radius = 256.0f / cur_node->lightsource->GetRadius(); - light.color = (red << 16) | (green << 8) | blue; + float lx = (float)(lightX * ViewSin - lightY * ViewCos) - dc_viewpos.X; + float ly = (float)(lightX * ViewTanCos + lightY * ViewTanSin) - dc_viewpos.Y; + float lz = (float)lightZ; // Precalculate the constant part of the dot here so the drawer doesn't have to. - light.x = light.x * light.x + light.y * light.y; + float lconstant = lx * lx + ly * ly; + + // Include light only if it touches this column + float radius = cur_node->lightsource->GetRadius(); + if (radius * radius >= lconstant) + { + uint32_t red = cur_node->lightsource->GetRed(); + uint32_t green = cur_node->lightsource->GetGreen(); + uint32_t blue = cur_node->lightsource->GetBlue(); + + nextlightindex++; + auto &light = dc_lights[dc_num_lights++]; + light.x = lconstant; + light.z = lz; + light.radius = 256.0f / cur_node->lightsource->GetRadius(); + light.color = (red << 16) | (green << 8) | blue; + } } cur_node = cur_node->nextLight;