Hello! I recently came up with a method to reduce the number of frames needed to draw an image pixel by pixel using UIGradients for (currently) up to 20x (18x by default in 1.1) less laggy image rendering. I’ve created this proof of concept module as well as a demo included. I would not recommend using this in a large scale game due to it’s hackiness and potential instability.
DISCLAIMER
Do NOT render inappropriate things with this POC code and DO NOT allow inappropriate things to be drawn with this POC code. It is not my fault if your game is moderated due to inappropriate images being displayed by your code and it is up to you to ensure that that doesn’t happen.
How does it work?
Note: By default in 1.1 this is reduced to 1x18 for an ~18x performance boost to get rid of artifacting (this was provided by DataBrain in a reply below)
Your image is passed into the Generate
function as a 2D array of pixels. This array even supports transparent pixels! It is then converted into a bunch of 1x20 columns (frames) which include a UIGradient in them. This UIGradient contains 20 colors (one for each individual pixel). This is currently the only limiting factor of how many vertical pixels can be drawn (ColorSequences only support a maximum of 20 values). Finally, each row is scaled and positioned to match the correct location of the input image and the frame containing the generated image is returned.
Usage
One function is included on the module, the generate function. This takes a 2D array of colors/alphas. (See usage within the included scripts for more info)
Additionally WritePixels, WritePixel, and ReadPixel are included for image manipulation (1.1)
Example & Demo (V1.1 fixes artifacting by default)
Here’s 100x100 pixels of perlin noise generated entirely by this module! Notice the artifacting. The image seams are drawn in red on the right. This weird seam issue is due to the way UIGradients are interpolated and it’s the main downside to using this method.
Current Version: 1.1
If you’d like to test this demo code and see some example image generation here’s the demo code with the module included: RenderTest.rbxl (24.5 KB)