Cornell University ECE4760
Polygon Rendering for 640x480 VGA 16-color
Pi Pico rp2350 (works slowly on 2040)
3D rendering
The code implements vector and matrix operations so that a full geometric transformation sequence produces a triangle list for rendering. You can specify vertices and face-lists to define objects, and combine them. There are modeling tranforms to move, scale, and rotate objects. After objects are built and positioned, a camera transform converts to 3D camera coordinates, followed by a perspective projection. Back-face culling is implemented and depth ordering is done by painters algorithm, because there is not enough memory for a z-buffer. Clipping is not yet implemented, so scenes have to be conservatively designed to fit in the view volume. Two pixel intensive steps: frame clear, and draw triangle, were accelerated using low-level memset operations to draw horizontal lines.
The code uses s15x16 fixed point for all matrix operations. Since many of the matrices are sparse, a small optimizaiton lets the mulitply macro exit early if either input is zero. The usual vector opeations were implemented: add, subtract, scaler multiply, magnitude, norm, dot product, and cross product. 4x4 homogenous matrix operations implemented: matrix multiply, vector times matrix. Routines to rotate objects, scale, translate, view transform objects, build objects, and combine objects produces a triangle view list which is passed to a depth sorter and rasterizer.
The image below is a frame from animation sequence running at ~30 fps.
About half the draw-time is spent on vertex arithmetic and about half on triangle fill rasterization.
Some of the code (matrix multiply, triangle scan conversion) was copied from a student project:
https://ece4760.github.io/Projects/Fall2023/av522_dy245/index.html
by
Alix Virgo and Demian Yutin.
Quicksort is from
https://stackoverflow.com/questions/55976487/get-the-sorted-indices-of-an-array-using-quicksort
The low level VGA graphics routines were modified to use memset for drawHLine
The changes made to the graphics routines were incorporated into vga_graphics_v2
in May 2025.
Code, Project ZIP
Copyright Cornell University May 24, 2025