Danny Spencer took his trusty previous Recreation Boy Shade and turned it right into a canvas for real-time 3D shading, remodeling the straightforward handheld into an incredibly convincing three dimensional setting. Because the teapot spins, its curves seize the sunshine from a supply you management with the D-pad, inflicting shadows to change seamlessly in response to every nudge.
Pixels mild up one after the other with a Lambertian shader, which tells you precisely how instantly mild hits a floor, and Spencer solved the issue of multiplying non-integer numbers by baking floor info into regular maps and storing them in tiny three-byte chunks within the ROM. Every pixel selects a standard vector from these maps, doses it with mild path, and outputs a shade starting from lifeless black to full-on white. The teapot’s spout glints within the mild or falls into shade, with every body a complete new creation from uncooked calculations.
The {hardware} won’t be happy as a result of the Recreation Boy Shade solely runs at 8 MHz, which equates to roughly 140,000 cycles every 60 FPS body. There isn’t any multiply command, so Spencer needed to get creative. He had no hassle swapping multiplications for logarithms and lookup tables. Log tables convert merchandise into sums, whereas energy tables do the reverse. All values are compressed into 8-bit fractions from 1 to 1, with indicators hidden away within the highest bits. Damaging numbers in logarithmic house? No want to fret, he flags them independently and makes modifications on the fly.

To cut back the workload, Spencer shifted to spherical coordinates, by which vectors grow to be angles: tilt (theta) and spin (phi), the place mild theta stays fixed and also you solely alter phi to maneuver the sunshine. The dot product is an easy method: sin(Nθ)sin(Lθ)cos(Nφ – Lφ) + cos(Nθ)cos(Lθ). One subtraction later, he’s incorporating a customized cos_log desk, a mixture of cosine and logarithm, to hurry issues up. 5 lookups each pixel, subtract, add, lookup, add, for a complete of 960 pixels and 89% of the body funds.

Spencer can patch the shader technique in actual time, swapping reminiscence masses for hard-coded immediates. That’s an extra 8 cycles saved each subtraction, for a complete of 11,520 over the body. He skips over rows that comprise no pixels at a price of three cycles per pop. Because of this, all the frames stay constant, even with some slight LCD ghosting to deal with.

You’ll be able to look at the code for your self within the GitHub repository, which was compiled with the RGBDS toolkit and consists of Python scripts to rework Blender regular maps into ROM knowledge. Two ROMs seem: teapot and gbspin. The releases web page accommodates pre-compiled variations that can get you up and working. You’ll be able to launch the BGB emulator or flash it onto a cart. Or, higher but, merely press some keys on Spencer’s web emulator.
[Source]
Elevate your perspective with NextTech Information, the place innovation meets perception.
Uncover the newest breakthroughs, get unique updates, and join with a world community of future-focused thinkers.
Unlock tomorrow’s developments at present: learn extra, subscribe to our publication, and grow to be a part of the NextTech neighborhood at NextTech-news.com

