Placing pixels issue?

So, i was coding thing that places pixels:

function screen:initPixels()
	warn("Initializing screen pixels.")
	
	for x = 1, self.resolution.x do
		task.wait()
		table.insert( self.pixels, {} )
		local yPixels = self.pixels[x]
		for y = 1, self.resolution.y do
			task.wait()
			-- position = ( x - 1 ) * self.pixel_size.x, ( y - 1 ) * self.pixel_size,y
			-- size = self.pixel_size
			--print(x, y)
			local pixel = Instance.new("Frame")
			pixel.Name = tostring(x) .. "..." .. tostring(y)
			pixel.BackgroundColor3 = Color3.new(0, 0, 0)
			pixel.Position = UDim2.fromOffset((x-1) * self.pixel_size.x, (y-1) * self.pixel_size.y)
			pixel.Size = UDim2.fromOffset(self.pixel_size.x, self.pixel_size.y)
			pixel.BorderSizePixel = 1
			pixel.Parent = self.canvas
			
			yPixels[y] = pixel
		end
	end
	
	warn("Sreen pixels initialized.")
	warn("Resolution: " .. tostring(self.resolution.x) .. "x" .. tostring(self.resolution.y) .. ".")
	warn("Pixel size: " .. tostring(math.round(self.pixel_size.x)) .. "x" .. tostring(math.round(self.pixel_size.y)) .. ".")
end

and if i do 128x64 is ok:
image

but 256x128(or 512x256 or even higher resolution) is not ok:


(it freezes at this moment)

Keep in mind you’re creating thousands–if not millions–of instances that all have to be rendered frame by frame. Unfortunately there’s no way to get around this, as it’s considered largely inefficient to do work like this.

If you’re trying to reach an end goal, I’d suggest doing it some alternative method that still gets the idea across.

it’s possible, and I already did it, now I copied the previous code, replaced the pixel with an instance frame, and that’s it. I don’t understand what is wrong

You should add a wait() or something to stop stack overflow and breaking the UI. Frames can be very laggy. I have my own script where I do this:

local RAND = 36 --higher number means lower wait times/more crashes
if math.random(1,15*RAND/resolution) == 1 then
    game["Run Service"].RenderStepped:Wait()
end

i already did it for x iterator

Creating Frames individually like this is notoriously power hungry, I’m sure once everything is created it will be all good with a general frame drop, however creating thousands of instances like this all in one go is obviously going to be a problem.

Unless you have a NASA computer, I don’t know how this is the case for you.

Sure, adding a wait will probably help out, however it would turn time consuming.

This is a real problem, I don’t know why, I copied the previous code, and generally replacing object({}) with frame instance makes it still easier, no? Yes, I even have a 512x256 render

If you can, maybe generate the pixels at set resolution, and change the color of the pixels you need after without deleting and remaking them. Add a setting to generate at the beginning. I don’t know if you are making a raytracing engine or something but Frames create Frame drops. (funny wordplay) There is another thing I don’t know if works but you could half the amount of pixels by creating a pixel with a UiGradient with 2 colors in it.

inf/s

Well that’s not very helpful.

You have indeed put a task.wait() inside the x iterator, sure, but 256 frames being created instantly…dunno about that.
Especially since task.wait() is not frame dependent.

I create pixels for further recoloring, it is obviously very stupid to recreate pixels

Yes, but anyway it ddoesn’t make anything to position

the color of the pixel is determined either by the color of the object + the overlay of light and specular with shadows, or if it does not hit the object, it is given the color of the sky

It’s not finishing because its freezing, lol.
Freezed = no frame rendered.

I’m sure if you waited a couple of minutes, like got something to eat you’d probably come back to a finished product.

Ah, edit. Just realized you put a task.wait() in the y iterator. Apologies for not reading that,

So from what I’ve gathered, it’s only crashing now when you’re trying to insert a table value instead of the frame, yes?

ALSO I SUGGEST FOR A STATIC COLOR BACKGROUND YOU HAVE ANOTHER SCREENGUI WITH A FULL BACKGROUND FRAME INSTEAD OF TRYING TO RENDER THE BACKGROUND IN EVERY PIXEL.

The best thing to do I suppose is to limit raycasts to a certain amount and decrease pixel resolution each frame. It is what many RTX engines do nowadays. You add more detail and reflections every frame or 2.

Just don’t make the pixel if it doesn’t hit anything on the first raycast.

Maybe, i suggest it just overlapping him self, like other pixels creates under another… BUT HOW THEN

I have trying around 4 days, but i don’t see error

If I may ask, how did you get the light to be so perfect with the brightness and darkness on the pixels? I just use a magnitude between the pixel and color the brightness using that.

local mag = ((workspace.Light.Position-RayResult.Position).Magnitude/Far)*500
Color = Color3.fromHSV(h,s,(v*5)/mag)

I’m sorry, but this has nothing to do with the topic.

1 Like

No, there would be no overlapping. As using table.insert(tab, value) will automatically place the value in the table +1 of the previous index.

Even so it would not cause a crash.

If inserting tables is exactly what is crashing it, it may be due to memory. Empty tables with no keys inside them take up little memory, but it’s still memory to be taken.

In this case I would revert inserting pixels into the table, and working around this problem to try and get your end goal.
Unfortunately, there’s no keen way to solve this besides decompiling Roblox Studio and changing the way it handles these things…lol.

hm, okay, i think this is solution

What about not adding to the table for things that are only for skybox, what difference would that make.