local d=game:GetService("\080\108\097\121\101\114\115")local M=game:GetService("\067\111\108\108\101\099\116\105\111\110\083\101\114\118\105\099\101")local b do local d,M=pcall(function()return(UserSettings()):IsUserFeatureEnabled("\085\115\101\114\080\111\112\112\101\114\099\097\109\076\111\111\115\101\079\112\097\099\105\116\121\084\104\114\101\115\104\111\108\100")end)b=d and M end local f=game.Workspace.CurrentCamera local t=math.min local v=math.tan local w=math.rad local h=math.huge local n=Ray.new local function C(d,M)for M=#d,M+1,-1 do d[M]=nil end end local E,r,H do local function d()local d=w(f.FieldOfView)local M=f.ViewportSize local b=M.X/M.Y H=2*v(d/2)r=b*H end;(f:GetPropertyChangedSignal("\070\105\101\108\100\079\102\086\105\101\119")):Connect(d);(f:GetPropertyChangedSignal("\086\105\101\119\112\111\114\116\083\105\122\101")):Connect(d)d()E=f.NearPlaneZ;(f:GetPropertyChangedSignal("\078\101\097\114\080\108\097\110\101\090")):Connect(function()E=f.NearPlaneZ end)end local T={}do local b={}local function f()T={unpack(M:GetTagged("\073\103\110\111\114\101\067\097\109\101\114\097"))}local d=#T+1 for M,b in pairs(b)do T[d]=b d=d+1 end end local function t(d)f()end local function v(d)local function M(M)b[d]=M f()end local function t()b[d]=nil f()end d.CharacterAdded:Connect(M)d.CharacterRemoving:Connect(t)if d.Character then M(d.Character)end end local function w(d)b[d]=nil f()end;(M:GetInstanceAddedSignal("\073\103\110\111\114\101\067\097\109\101\114\097")):Connect(t);(M:GetInstanceRemovedSignal("\073\103\110\111\114\101\067\097\109\101\114\097")):Connect(t)d.PlayerAdded:Connect(v)d.PlayerRemoving:Connect(w)for d,M in next,M:GetTagged("\073\103\110\111\114\101\067\097\109\101\114\097")do t(M)end for d,M in ipairs(d:GetPlayers())do v(M)end f()end


local Players = game:GetService('Players')
local Collection = game:GetService("CollectionService")

local FFlagUserPoppercamLooseOpacityThreshold do
	local success, enabled = pcall(function()
		return UserSettings():IsUserFeatureEnabled("UserPoppercamLooseOpacityThreshold")
	end)
	FFlagUserPoppercamLooseOpacityThreshold = success and enabled
end

local camera = game.Workspace.CurrentCamera

local min = math.min
local tan = math.tan
local rad = math.rad
local inf = math.huge
local ray = Ray.new

local function eraseFromEnd(t, toSize)
	for i = #t, toSize + 1, -1 do
		t[i] = nil
	end
end

local nearPlaneZ, projX, projY do
	local function updateProjection()
		local fov = rad(camera.FieldOfView)
		local view = camera.ViewportSize
		local ar = view.X/view.Y

		projY = 2*tan(fov/2)
		projX = ar*projY
	end

	camera:GetPropertyChangedSignal('FieldOfView'):Connect(updateProjection)
	camera:GetPropertyChangedSignal('ViewportSize'):Connect(updateProjection)

	updateProjection()

	nearPlaneZ = camera.NearPlaneZ
	camera:GetPropertyChangedSignal('NearPlaneZ'):Connect(function()
		nearPlaneZ = camera.NearPlaneZ
	end)
end

local blacklist = {} do
	local charMap = {}

	local function refreshIgnoreList()
		blacklist = {unpack(Collection:GetTagged("IgnoreCamera"))}
		local n = #blacklist + 1
		for _, character in pairs(charMap) do
			blacklist[n] = character
			n = n + 1
		end
	end
	
	local function OnIgnoreCollectionUpdated(instance)
		refreshIgnoreList()
	end

	local function playerAdded(player)
		local function characterAdded(character)
			charMap[player] = character
			refreshIgnoreList()
		end
		local function characterRemoving()
			charMap[player] = nil
			refreshIgnoreList()
		end

		player.CharacterAdded:Connect(characterAdded)
		player.CharacterRemoving:Connect(characterRemoving)
		if player.Character then
			characterAdded(player.Character)
		end
	end

	local function playerRemoving(player)
		charMap[player] = nil
		refreshIgnoreList()
	end
	
	Collection:GetInstanceAddedSignal("IgnoreCamera"):Connect(OnIgnoreCollectionUpdated)
	Collection:GetInstanceRemovedSignal("IgnoreCamera"):Connect(OnIgnoreCollectionUpdated)
	Players.PlayerAdded:Connect(playerAdded)
	Players.PlayerRemoving:Connect(playerRemoving)
	
	for _, instance in next,Collection:GetTagged("IgnoreCamera") do
		OnIgnoreCollectionUpdated(instance)
	end
	for _, player in ipairs(Players:GetPlayers()) do
		playerAdded(player)
	end
	refreshIgnoreList()
end
