-- functions bruv


function RaycastRender()
	for x=1,renderResolution do
		for y=1,renderResolution do
			local currentScreenPos = Vector2.new(x*(viewportSize.X/renderResolution), y*(viewportSize.Y/renderResolution))
			local screenRay = cam:ScreenPointToRay(currentScreenPos.X, currentScreenPos.Y)
			local RayCast = workspace:Raycast(screenRay.Origin, screenRay.Direction*1000)
			if RayCast then
				local Part = Instance.new("Part", workspace)
				Part.Anchored = true
				Part.Size = Vector3.new(1,1,1)
				Part.Position = RayCast.Position
				game.Debris:AddItem(Part, .095)
			end
		end
	end
end

function isPositionOnScreen(position)
	
	if (position - cam.CFrame.Position).Magnitude > 3000 then
	-- Check if on screen:
	local vector, inViewport = cam:WorldToViewportPoint(position)
	local onScreen = inViewport and vector.Z > 0

	-- Raycast outward:
	local ray = cam:ViewportPointToRay(vector.X, vector.Y, 0)
	local raycastParams = RaycastParams.new()
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	--raycastParams.FilterDescendantsInstances = {game.Players.LocalPlayer.Character}
	local raycastResult = workspace:Raycast(ray.Origin, ray.Direction * 1000, raycastParams)

	-- Final check:
	local isVisible = onScreen and not raycastResult
		return isVisible
	else
		return true
	end
	
end
