When i use this script only 1/(the number of workers) of this screen is rendered e.g.
local numWorkers = 2
makes it so that only 1/2 of the screen is rendered
does anyone know how to fix this?
--!native
local ScreenGui = script.Parent
if ScreenGui:IsA("Actor") then
ScreenGui = ScreenGui.Parent.Parent
end
local Canvas = ScreenGui:WaitForChild("Frame")
local RunService = game:GetService("RunService")
local pixelSize = 12
local pixels = {}
local canvasWidth, canvasHeight
local function initializePixels()
canvasWidth = math.floor(Canvas.AbsoluteSize.X / pixelSize)
canvasHeight = math.floor(Canvas.AbsoluteSize.Y / pixelSize)
for _, pixelRow in pairs(Canvas:GetChildren()) do
pixelRow:Destroy()
end
pixels = {}
for y = 0, canvasHeight - 1 do
pixels[y] = {}
for x = 0, canvasWidth - 1 do
local pixel = Instance.new("Frame")
pixel.Size = UDim2.new(0, pixelSize, 0, pixelSize)
pixel.Position = UDim2.new(0, x * pixelSize, 0, y * pixelSize)
pixel.BorderSizePixel = 0
pixel.BackgroundColor3 = Color3.new(0, 0, 0)
pixel.Parent = Canvas
pixels[y][x] = {
frame = pixel,
color = Color3.new(0, 0, 0)
}
end
end
end
local function getColor(hit)
if hit then
return hit.Instance.BrickColor.Color
else
return Color3.new(0, 0, 0)
end
end
local function raytrace(camera, x, y, aspectRatio, fov)
local screenX = (x / canvasWidth) * 2 - 1
local screenY = (y / canvasHeight) * 2 - 1
screenX = screenX * aspectRatio * math.tan(fov / 2)
screenY = screenY * math.tan(fov / 2)
local rayDirection = (camera.CFrame.LookVector + camera.CFrame.RightVector * screenX - camera.CFrame.UpVector * screenY).Unit
local ray = Ray.new(camera.CFrame.Position, rayDirection * 100)
local hit = game.Workspace:Raycast(camera.CFrame.Position, rayDirection * 100)
return getColor(hit)
end
local function updatePixels(startY, endY)
local camera = game.Workspace.CurrentCamera
local aspectRatio = canvasWidth / canvasHeight
local fov = math.rad(90)
for y = startY, endY do
for x = 0, canvasWidth - 1 do
local color = raytrace(camera, x, y, aspectRatio, fov)
if color ~= pixels[y][x].color then
pixels[y][x].color = color
task.synchronize()
pixels[y][x].frame.BackgroundColor3 = color
task.desynchronize()
end
end
end
end
initializePixels()
local actor = script:GetActor()
if actor == nil then
local workers = {}
local numWorkers = 2
for i = 1, numWorkers do
local actor = Instance.new("Actor")
script:Clone().Parent = actor
table.insert(workers, actor)
end
for _, actor in ipairs(workers) do
actor.Parent = script
end
while true do
task.wait()
for i, worker in ipairs(workers) do
local startY = (i - 1) * math.ceil(canvasHeight / numWorkers)
local endY = math.min(startY + math.ceil(canvasHeight / numWorkers) - 1, canvasHeight - 1)
print(startY, endY)
worker:SendMessage("Raycast", startY, endY)
end
end
return
end
actor:BindToMessageParallel("Raycast", function(startY, endY)
updatePixels(startY, endY)
end)
Canvas:GetPropertyChangedSignal("AbsoluteSize"):Connect(function()
initializePixels()
end)