diff --git a/src/hwrenderer/scene/hw_bsp.cpp b/src/hwrenderer/scene/hw_bsp.cpp index 4393424c1..8f561c289 100644 --- a/src/hwrenderer/scene/hw_bsp.cpp +++ b/src/hwrenderer/scene/hw_bsp.cpp @@ -75,6 +75,21 @@ void HWDrawInfo::UnclipSubsector(subsector_t *sub) // //========================================================================== +EXTERN_CVAR(Float, r_line_distance_cull) + +inline bool IsDistanceCulled(seg_t *line) +{ + double dist3 = r_line_distance_cull * r_line_distance_cull; + if (dist3 <= 0.0) + return false; + + double dist1 = (line->v1->fPos() - r_viewpoint.Pos).LengthSquared(); + double dist2 = (line->v2->fPos() - r_viewpoint.Pos).LengthSquared(); + if ((dist1 > dist3) && (dist2 > dist3)) + return true; + return false; +} + void HWDrawInfo::AddLine (seg_t *seg, bool portalclip) { #ifdef _DEBUG @@ -123,6 +138,8 @@ void HWDrawInfo::AddLine (seg_t *seg, bool portalclip) uint8_t ispoly = uint8_t(seg->sidedef->Flags & WALLF_POLYOBJ); + if (IsDistanceCulled(seg)) { clipper.SafeAddClipRange(startAngle, endAngle); return; } + if (!seg->backsector) { clipper.SafeAddClipRange(startAngle, endAngle);