How to quickly get the color of any pixel?

Hello. I saw a video a while ago called “What is bloom, and how is it simulated?”. Here it is:

The first thing I wanted to do was try to get the color of each pixel on the screen each frame in order to draw / create the bloom effect. How do I get the color of any pixel on the screen in a localscript efficiently? I’ve made a script a long time ago that would perform 1 raycast per pixel and use the color3 property of the object that the raycast hit. The problem with this is that it’s slow… like really, really slow. So I wouldn’t be able to do this in a game any time and expect it to be fun, and playable even on fast devices. So, I’ve been thinking about performing these raycasts every x amount of pixels, and then use linear / cubic interpolation for the pixels in between those pixels, so that way I don’t need to perform raycasts for every pixel on the screen, but I’m wondering if anybody knows if there is anything else that I could do to make it even faster than how fast my ideas could make it. I’ll probably also precompute as many things as I can, which will hopefully increase the speed of it as well.

So, the main question of my topic is how do I get the color of any pixel on the screen in a script efficiently?

2 Likes

tbh, the raycast method is probably your best bet. There’s really not much support for accessing pixels.

I think there is a bloom object available that you can put in lighting btw

1 Like

I am aware, but I want to try to make what is in the video. I understand that it may not be necessary to create my own bloom, but I guess you could call this a “scripting challenge”. The main reason I want to make this though, is because I wish roblox simulated bloom the same way that the video explained.

1 Like

If I understand you correctly, you’re wanting to read the pixel data on the user’s screen. If so, this is not possible with current ROBLOX API. There is no way to read the individual pixels on a user’s screen without some hacky method such as using a GUI object for every pixel, since ROBLOX doesn’t support custom shaders.

A reason for this is ROBLOX’s presence on many platforms - shader architecture is not as unified as it needs to be (at least on ROBLOX) to make supporting shaders an easy task.

Any workaround UI implementation is not going to be performant without intense optimization, and even then it won’t be able to use screen data very well at all. Like @PoppyandNeivaarecute has stated, your best bet is to use the built-in Bloom, even if it’s not exactly to your liking.

1 Like

I believe there’s some sort of capture api(not sure if you can read the pixels), and there’s also a technique boatbomber made for his ui blur module that approximates the color of pixels

2 Likes

Yes, it is possible using CaptureService:CaptureAsync(callback), in tandem with AssetService:CreateEditableImageAsync(assetid), to read pixel data. The problem is, there is a limit to how often you can take a capture. It’s about 2 per second for me (the images load instantly). I’m positive that because of EditableImage’s 1024x1024 resolution cap, you can’t read the exact data of a pixel, but can only approximate it.

also EditableImage is still in studio beta, so it can’t be used in experiences

3 Likes