Skip to content
Jupiter documentation
Menu

How the 3D demo works

A software renderer that draws a shaded torus knot at 49 frames per second on both cores.

Mode 2 runs a software 3D renderer in main/knot.c. It draws a lit torus knot at 49 frames per second, which is the display's own rate of about 49.8 Hz.

The scene#

Pixel output#

The monitor shows three levels: black (0x00), normal (0x01) and bright (0x03). The renderer works in 8-bit brightness and uses an 8x8 ordered (Bayer) dither to choose between the two nearest levels for each pixel. It scales x by 1.54 so that shapes stay round, because pixels on a 4:3 tube showing 720x350 are taller than wide.

Each frame#

  1. Prepare (core 0, about 2.2 ms). Rotate the vertices and normals with one combined matrix, project them, light them, drop back-facing triangles and sort the rest far to near with a bucket sort.
  2. Rasterise (both cores, about 15 ms each). The screen is split into ten strips of 35 lines. Each core takes the next unclaimed strip, draws it into a small buffer in internal RAM, and copies it into the PSRAM frame buffer. A core that is busy with display interrupts takes fewer strips.
  3. Flip. The firmware calls esp_lcd_panel_draw_bitmap with the finished buffer, which tells the driver to scan it out from the next frame. It then waits until the driver has switched to the new buffer before it reuses the old one. See How the video works.

Frames take 17 to 18 ms to render, against 20.07 ms between V-syncs.

What made it fast#

The first version ran at 25 fps with 27 to 29 ms per frame. These changes brought it to 49 fps:

Source: belikh/monochrome HEAD