Halo causing serious FPS drop to lower-end PCs. Fixes? Alternatives?

Hi,

Here’s my clientside code;


hook.Add( "PreDrawHalos", "AddHalos", function()
if not IsValid(LocalPlayer()) then return end
local pos = LocalPlayer():GetPos()

for k, v in pairs(ents.FindByClass("LootItem")) do
    if ( pos:Distance(v:GetPos()) <= 300 ) then
        halo.Add( {v}, Color( 0, 0, 255 ), 1, 1, 1 )
    end
end
end)

In pseudocode; when the local player (clientside) is within 300 units of a lootable item, it has a halo.Add with the lowest settings applied to it.

I personally have a fairly powerful rig and am not affected by the issue. However, one of my player has noted a drop of as much as 20FPS when within range of ONE halo. (From 60 to 40 FPS, potentially more around more items).

Am I doing something wrong? If not, what alternatives to cool glow/highlighted items do I have?

Thank you for your time!

I worked on this for a while and think this is a better solution. I don’t notice much of a FPS drop, but I tried to optimize it the best I could.

[lua]
if SERVER then
AddCSLuaFile()
else
local ViewDistance = 300
hook.Add(“PreDrawHalos”, “EntityHaloOutline”, function()
local ply = LocalPlayer()
if !IsValid(ply) then return end
if !ply.HaloEnts then
ply.HaloEnts = {}
end

	local Ents = ents.FindByClass("LootItem")
	for i = 1, #Ents do
		local v = Ents*
		local pPos = ply:GetPos()
		local vPos = v:GetPos()
		local px,py,pz = pPos.x, pPos.y, pPos.z
		local vx,vy,vz = vPos.x, vPos.y, vPos.z
		local xDiff,yDiff,zDiff = ((px-vx)^2),((py-vy)^2),((pz-vz)^2)
		local totalDist = ((xDiff+yDiff+zDiff)^(0.5))
		if (totalDist &lt;= ViewDistance) then
			ply.HaloEnts[#ply.HaloEnts+1] = v
		end
	end
	
	if #ply.HaloEnts == 0 then return end
	
	halo.Add(ply.HaloEnts, Color(255, 0, 0), 2, 2, 2, false, false)
	ply.HaloEnts = {}
end)

end
[/lua]

You could use stencils.