Update on my Game Boy 3D engine! This is running on real hardware (my Analogue Pocket), with the original Game Boy version on the left and the new Game Boy Color version on the right. The colours on the left are just the Pocket's palette for original Game Boy games.
This isn't a flat grid maze. The level is a full 3D model made in Blender and converted into the engine: an old water mill (ment to be anyways) with different floor heights, ramps, stairs, a sluice, a wheel pit and thin walls, and you walk up and down all of it in real time. Nothing is pre-rendered.
In the video I'm cycling through the three render modes with the Select button. The number under the mode name in the bottom bar is the live frame rate.
ON is the default mode. It puts textures on the walls, with plain floors and ceilings.
FULL adds textures to the floors as well. It's the most detailed mode, but also the slowest.
OFF turns the textures off and just draws shaded walls, which is the fastest.
Under the hood, every frame is drawn in software into a buffer and streamed into video memory only in the short gaps when the screen isn't being drawn, with a timer trick to double the lines. The textures are mapped per column and have lower detail versions for walls far away, so they don't pop in.
The Game Boy Color version draws exactly the same black and white picture. It just uses the Color's double speed CPU and its DMA transfers, so it runs about twice as fast. Averaged over a walk through the level, that's about 12 fps on the original Game Boy against 28 on the Color with textures on, 9 against 22 in FULL, and 19 against 30 with textures off (the Color version is capped at 30).
For the Game Boy devs, here's how it works:
The level is 32 by 32 cells, and every cell can have its own floor and ceiling height, so there are stairs, ledges, windows, a slope down the sluice and open sky. Walls aren't solid blocks either. Each one is a thin plane on a grid line, with its own bottom and top.
Rendering is a raycaster with one ray per 8 pixel column. Every map cell stores small event codes for its neighbours, so a ray only stops where something actually changes (a floor or ceiling height, a step, a lintel or a wall) and jumps straight to a handler for that case. The ray maths uses no multiplies or divides: distances and heights are kept as logarithms, so projecting a height is one 16 bit add and a table lookup.
The picture is drawn as a 160 x 56 bitmap in RAM, laid out in tile order, and a timer interrupt moves the scroll register every other line so each line shows twice. Tiles that are one flat colour aren't drawn at all, they just point at 16 shared flat tiles, and columns that match their neighbour share tiles too, so most frames only need a few dozen real tiles. Two pictures alternate in VRAM, and the copy into VRAM only runs during HBlank and VBlank, using copy routines generated by a Python script with a cycle exact timing model. An accurate emulator confirms zero VRAM writes while the screen is being drawn.
The textures are mapped per column, with smaller copies and a matching flat tone for distance, all stored in ROM banks (the ROM is 512 KB, MBC5). The ROM's pictures are checked pixel for pixel against a Python model of the renderer. On the Game Boy Color build the CPU runs at double speed, and the picture goes into VRAM by DMA during VBlank, with a new picture every 2 frames.