local o=1000 local A=0 local P=game.Players.LocalPlayer local c=P.Character:WaitForChild("\072\101\097\100")local G=false local T=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")function RaycastSingular(o)if o>GRID_HEIGHT*GRID_WIDTH or G then return end local A=(GRID_WIDTH-((o-1)%GRID_WIDTH+1))-GRID_WIDTH/2 local T=(GRID_HEIGHT-(math.floor((o-1)/GRID_WIDTH)+1))-GRID_HEIGHT/2 local B=RaycastParams.new()B.FilterDescendantsInstances={P.Character}B.FilterType=Enum.RaycastFilterType.Exclude local Z=workspace.CurrentCamera.CFrame local E=(Z*CFrame.Angles(math.rad(T*RAYCAST_OFFSET),math.rad(A*RAYCAST_OFFSET),0)).lookVector local O=workspace:Raycast(Z.Position,E*1000,B)if O then local A local P=O.Instance if P and P:IsA("\066\097\115\101\080\097\114\116")then local o=math.clamp(O.Distance/FOG_MULTIPLIER,1,FOG_MAX)A=Color3.new(P.Color.r*o,P.Color.g*o,P.Color.b*o)else local o=(O.Position-c.Position).Magnitude local A=math.floor(128*(1-o/1000))if A<0 then A=0 end A=Color3.new(A,A,A)end;(script.Parent.Container:WaitForChild(tostring(o))).BackgroundColor3=A else(script.Parent.Container:WaitForChild(tostring(o))).BackgroundColor3=Color3.fromRGB(85,170,255)end o+=1 end function RaycastAndApply()local o=1 for A=math.round(GRID_HEIGHT/2),-math.round(GRID_HEIGHT/2),-1 do for T=math.round(GRID_WIDTH/2)-1,-math.round(GRID_WIDTH/2),-1 do if o>GRID_HEIGHT*GRID_WIDTH or G then return end local B=RaycastParams.new()B.FilterDescendantsInstances={P.Character}B.FilterType=Enum.RaycastFilterType.Exclude local Z=workspace.CurrentCamera.CFrame local E=(Z*CFrame.Angles(math.rad(A*RAYCAST_OFFSET),math.rad(T*RAYCAST_OFFSET),0)).lookVector local O=workspace:Raycast(Z.Position,E*1000,B)if O then local A local P=O.Instance if P and P:IsA("\066\097\115\101\080\097\114\116")then local o=math.clamp(O.Distance/FOG_MULTIPLIER,1,FOG_MAX)A=Color3.new(P.Color.r*o,P.Color.g*o,P.Color.b*o)else local o=(O.Position-c.Position).Magnitude local A=math.floor(128*(1-o/1000))if A<0 then A=0 end A=Color3.new(A,A,A)end;(script.Parent.Container:WaitForChild(tostring(o))).BackgroundColor3=A else(script.Parent.Container:WaitForChild(tostring(o))).BackgroundColor3=Color3.fromRGB(85,170,255)end if CALMDOWN_RENDER then wait(CALMDOWN_RENDER)end o+=1 end end end game.Close:Connect(function()G=true end)function notify(o,A)local P=game:GetService("\083\116\097\114\116\101\114\071\117\105")P:SetCore("\083\101\110\100\078\111\116\105\102\105\099\097\116\105\111\110",{Title=o,Text=A;Duration=5})end T.InputBegan:Connect(function(o,A)if A then return end if o.KeyCode==Enum.KeyCode.Q then FOG_MAX=math.max(FOG_MAX-1,1)notify("\070\111\103 \076\101\118\101\108","\119\097\115 \099\104\097\110\103\101\100 \116\111 "..FOG_MAX)end if o.KeyCode==Enum.KeyCode.E then FOG_MAX+=1 notify("\070\111\103 \076\101\118\101\108","\119\097\115 \099\104\097\110\103\101\100 \116\111 "..FOG_MAX)end end)if RENDER_METHOD==1 then while true do wait(CALMDOWN)RaycastAndApply()if G then break end end else while true do wait(A)for o=1,o,1 do RaycastSingular(math.random(1,GRID_HEIGHT*GRID_WIDTH))end if G then break end end end
--METHOD 2 PARAMS
local PIXELS_PER_WAIT = 1000
local WAIT_PERIOD = 0

local LocalPlayer = game.Players.LocalPlayer
local LocalHumanoidRootPart = LocalPlayer.Character:WaitForChild("Head")
local terminate = false
local uis = game:GetService("UserInputService")

function RaycastSingular(i)
	if i > GRID_HEIGHT * GRID_WIDTH or terminate then
		return
	end

	local width = (GRID_WIDTH - ((i - 1) % GRID_WIDTH + 1) - (GRID_WIDTH / 2))
	local height = (GRID_HEIGHT - (math.floor((i - 1) / GRID_WIDTH) + 1)) - (GRID_HEIGHT / 2)

	--raycast ahead keeping RAYCAST_OFFSET in mind
	local rayParam = RaycastParams.new()
	rayParam.FilterDescendantsInstances = { LocalPlayer.Character }
	rayParam.FilterType = Enum.RaycastFilterType.Exclude

	local pos1 = workspace.CurrentCamera.CFrame
	local pos2 = (pos1 * CFrame.Angles(math.rad(height * RAYCAST_OFFSET), math.rad(width * RAYCAST_OFFSET), 0)).lookVector

	local raycastResult = workspace:Raycast(pos1.Position, pos2 * 1000, rayParam)

	if raycastResult then
		local colorValue

		local hitPart = raycastResult.Instance
		if hitPart and hitPart:IsA("BasePart") then
			local fadeAway = math.clamp(raycastResult.Distance / FOG_MULTIPLIER, 1, FOG_MAX)
			colorValue = Color3.new(hitPart.Color.r * fadeAway, hitPart.Color.g * fadeAway, hitPart.Color.b * fadeAway)
		else
			--make a color of black from 128,128,128 to 0,0,0 depending on the distance of hit
			local distance = (raycastResult.Position - LocalHumanoidRootPart.Position).Magnitude
			local colorValue = math.floor(128 * (1 - distance / 1000))

			if colorValue < 0 then
				colorValue = 0
			end

			colorValue = Color3.new(colorValue, colorValue, colorValue)
		end

		script.Parent.Container:WaitForChild(tostring(i)).BackgroundColor3 = colorValue
	else
		script.Parent.Container:WaitForChild(tostring(i)).BackgroundColor3 = Color3.fromRGB(85, 170, 255)
	end

	i += 1
end

function RaycastAndApply()
	--raycast from the HumanoidRootPart forwards GRID_WIDTH * GRID_HEIGHT, offsetting by RAYCAST_OFFSET studs
	local i = 1
	for height = math.round(GRID_HEIGHT / 2), -math.round(GRID_HEIGHT / 2), -1 do
		for width = math.round(GRID_WIDTH / 2) - 1, -math.round(GRID_WIDTH / 2), -1 do
			if i > GRID_HEIGHT * GRID_WIDTH or terminate then
				return
			end
			--raycast ahead keeping RAYCAST_OFFSET in mind
			local rayParam = RaycastParams.new()
			rayParam.FilterDescendantsInstances = { LocalPlayer.Character }
			rayParam.FilterType = Enum.RaycastFilterType.Exclude

			local pos1 = workspace.CurrentCamera.CFrame
			local pos2 = (pos1 * CFrame.Angles(math.rad(height * RAYCAST_OFFSET), math.rad(width * RAYCAST_OFFSET), 0)).lookVector

			local raycastResult = workspace:Raycast(pos1.Position, pos2 * 1000, rayParam)

			if raycastResult then
				local colorValue

				local hitPart = raycastResult.Instance
				if hitPart and hitPart:IsA("BasePart") then
					local fadeAway = math.clamp(raycastResult.Distance / FOG_MULTIPLIER, 1, FOG_MAX)
					colorValue =
						Color3.new(hitPart.Color.r * fadeAway, hitPart.Color.g * fadeAway, hitPart.Color.b * fadeAway)
				else
					--make a color of black from 128,128,128 to 0,0,0 depending on the distance of hit
					local distance = (raycastResult.Position - LocalHumanoidRootPart.Position).Magnitude
					local colorValue = math.floor(128 * (1 - distance / 1000))

					if colorValue < 0 then
						colorValue = 0
					end

					colorValue = Color3.new(colorValue, colorValue, colorValue)
				end

				script.Parent.Container:WaitForChild(tostring(i)).BackgroundColor3 = colorValue
			else
				script.Parent.Container:WaitForChild(tostring(i)).BackgroundColor3 = Color3.fromRGB(85, 170, 255)
			end

			if CALMDOWN_RENDER then
				wait(CALMDOWN_RENDER)
			end

			i += 1
		end
	end
end

game.Close:Connect(function()
	terminate = true
end)

function notify(title, text)
	local CoreGui = game:GetService("StarterGui")

	CoreGui:SetCore("SendNotification", {
		Title = title,
		Text = text,
		Duration = 5,
	})
end

uis.InputBegan:Connect(function(input, processed)
	if processed then
		return
	end
	if input.KeyCode == Enum.KeyCode.Q then
		FOG_MAX = math.max(FOG_MAX - 1, 1)
		notify("Fog Level", "was changed to " .. FOG_MAX)
	end
	if input.KeyCode == Enum.KeyCode.E then
		FOG_MAX += 1
		notify("Fog Level", "was changed to " .. FOG_MAX)
	end
end)

if RENDER_METHOD == 1 then
	while true do
		wait(CALMDOWN)
		--clearAllTiles()
		RaycastAndApply()
		--wait(1)
		if terminate then
			break
		end
	end
else
	while true do
		wait(WAIT_PERIOD)
		for pixels = 1, PIXELS_PER_WAIT do
			RaycastSingular(math.random(1, GRID_HEIGHT * GRID_WIDTH))
		end
		if terminate then
			break
		end
	end
end
