Custom render script

Hello fellow devs! Im trying to make a custom renderer but Im not really good with raycasts nor Vector3’s…

local camera = game.Workspace.CurrentCamera
local renderGui = game.StarterGui.ScreenGui
local renderDistance = 1000

function renderScene()
	local viewportSize = renderGui.AbsoluteSize
	local pixelWidth = viewportSize.X
	local pixelHeight = viewportSize.Y

	for x = 0, pixelWidth - 1 do
		task.wait()
		for y = 0, pixelHeight - 1 do
			task.wait()
			print("a")
			local screenPoint = Vector2.new(x, y)
			local rayDirection = (camera:ScreenPointToRay(screenPoint.X, screenPoint.Y).Direction).Unit

			local result = workspace:Raycast(camera.CFrame.Position, rayDirection * renderDistance, RaycastParams.new())

			if result then
				local hitPart = result.Instance
				local material = hitPart.Material
				local color = hitPart.BrickColor.Color

				local pixel = Instance.new("Frame")
				pixel.Size = UDim2.new(0, 1, 0, 1)
				pixel.Position = UDim2.new(0, x, 0, y)
				pixel.BackgroundColor3 = color
				pixel.Parent = renderGui
			end
		end
	end
end

local Type = "render"
if Type == "render" then
	renderScene()
else
	renderGui:ClearAllChildren()
end

Here is the code I currently have but it is really laggy and I could not get it to work