Bypassing Forced Beam LOD

Recently I’ve heard that beams have their segments influenced by camera distance and graphics settings so I’ve came up with code that reverses those changes and gives you the same desired segments from anywhere and any quality settings.

Felt unfair that I kept this to myself after I read this thread.


So here’s the client code which achieves this, reminder you have to tag beams in the Tag Editor with the tag of ‘Beam’ so that this code can pick it up.

-- Credits to nurokoi

local RunService = game:GetService("RunService")
local CollectionService = game:GetService("CollectionService")

local function RecalculateBeamSegments()
	for _, beamObject : Beam in CollectionService:GetTagged("Beam") do
		local Attachment0 = beamObject.Attachment0
		local Attachment1 = beamObject.Attachment1
		
		if not Attachment0 or not Attachment1 then continue end
		
		local SegmentCount = beamObject:GetAttribute("DesiredSegments")
		
		if not beamObject:GetAttribute("DesiredSegments") then
			SegmentCount = beamObject.Segments
			beamObject:SetAttribute("DesiredSegments", beamObject.Segments)
		end

		local CameraLocation = workspace.CurrentCamera.CFrame
		local Distance = math.max((CameraLocation.Position - Attachment0.WorldPosition).Magnitude, (CameraLocation.Position - Attachment1.WorldPosition).Magnitude)

		local QualityFactor = math.max(0, math.min(1, UserSettings().GameSettings.SavedQualityLevel.Value / 10))
		local QualityDistanceScalar = math.clamp((1 - (Distance - 200) / 800) * QualityFactor, 0.1, 1)

		beamObject.Segments = math.ceil(SegmentCount / QualityDistanceScalar) -- math.ceil(SegmentCount / (QualityDistanceScalar * (1 + Distance / 1000)))			
	end
end

RunService:BindToRenderStep("BeamLOD", Enum.RenderPriority.Camera.Value + 1, RecalculateBeamSegments)

Here’s a video which shows me using a beam with 20 segments and demonstrating the code in action.

37 Likes