Some of you may have seen my other post on making a 3D renderer from scratch, and the experienced devs seemed politely suggestive that I stick to the native fillTriangle functions. Here I reveal my hand…
I’d like to make a game that actively uses more than 16 colors by changing palettes on the fly.
This initial demonstration is just a small performance test and proof of concept that shows palettes can be swapped pretty quickly on the fly to allow for an arbitrary number of colors to be displayed in a single project.
My eventual goal…
- Take a dynamically generated image with as many as 16,777,216 unique colors - the standard limitation for colors represented by rgb hex values, which Makecode uses for its palette colors
- Plot the color of each pixel in a 3-dimensional plot by its r, g, and b values
- Use some algorithm like median cut or octrees to intelligently pick 15 colors (+ transparent, which can be used to mimic black) to represent that frame.
- Employ a technique like Floyd-Steinberg dithering to shade the image appropriately with those 16 colors.
If this is done every frame, the color palette will adapt to whichever 15 colors + black will best represent the image on any given frame. This is similar to the technique used to generate old .gifs
The images I will be processing are renderings from my 3d engine. Rather than drawing directly to the screen, I plan on drawing to a color buffer that holds information for the actual colors I’d like at each pixel, were Makecode Arcade not limited to 16 colors. The colors will be based on lightning and rotation of the triangles in my scene, and to start, I’d like to attach hex color values to the vertices on my 3d models rather than assigning a palette index to the faces like many other 3D implementations in Arcade have done up to this point.
This will absolutely not be performant, especially on hardware. I’m curious to see how many fps (frames-per-sometimes) my laptop will be able to eventually manage. If you wanted it to be even remotely performant, you’re probably better off manually setting or calculating the color palette on boot up and just using a dithering algorithm, though I doubt even that will be feasible for realtime.
Thank you for reading, and wish me luck! I will update as I make progress. First step will be coding the dithering algorithm with a static color palette, though I need to make progress on my 3D engine before I can appropriately test it.