stardance has been extended another month! the new deadline is october 31 :)

You are browsing as a guest. Sign up (or log in) to start making projects!

5h 31m 52s logged

3D RENDERER :woa:

I finally got the 3D renderer to work :yayayayayay: It took SO long (18+ hours in total? :pf: ) but it’s so cool and really shows the capabilities of this tiny CPU :yeah:
:actually-nothing:
It took so long to make because I had to write everything in assembly with 🚫 no functions, 🚫 no control structures and 🚫no variables :skulk: :cryin:
:actually-nothing:
Obviously trying to program this CPU with such a tiny ISA and a stupid assembler is borderline impossible - you have to manually deal with register/pin addresses and memory addresses for jumps, so adding a single line changes everything after it and breaks your jumps. :sob-hole:
That’s why I added a few features to the assembler to make my life easier, namely address markers and constants.

  • Address markers allow you to mark instructions and use those marker names within the program to refer to that instruction, which makes conditional stuff, jumps and other stuff much easier.
  • Constants are… well, constants. With them I can assign names to memory addresses. (especially useful when you have more than 120 addresses :pf: )

Additionally, I also introduced a dynamic constants thing in the assembler, which basically just reserves memory addresses and stuff for constants on it’s own, so now I don’t even need to think about those addresses.

new ALU stuff

I added a new ALU (Arithmetic & Logic Unit) function in the CPU for comparisons between two numbers.
:actually-nothing:
The new COMP ALU operation compares the two values in ALU_A and ALU_B and sets the output to:

  • 1 if A > B
  • 2 of A < B
  • 0 if A = B

Trying to make a 3D renderer without these functions is impossible :ohbrother:

renderererer

Ok, now onto how the renderer actually works.
:actually-nothing:
The renderer is just one big program (1300+ lines of assembly) that does a bunch of stuff to try and render a spinning cube on the display. Basically all it does is:

  • :blob_work: Initialize the cube vertices
  • :thumbs-up: Make the edge table for the lines of the cube
  • :thonk-spin: Rotate all the points of the cube by a set amount every frame using a lot of scary math
  • 📽️ Project the new rotated 3D points of the cube into 2D points using even more math
  • :firewriting: Draw all the lines of the cube and refresh the display
  • :wowzers: Repeat from step 3

Here’s a very simplified explanation of the entire program:
:actually-nothing:
The initial positions of the points is hardcoded into the code, and there’s also a getVertex function to get the X, Y and Z coordinates for a specific vertex number.
:actually-nothing:
To rotate the points, you need to do some matrix multiplication :neon-matrix: on each of the points, with a rotation matrix thingy and magically rotation happens.
:actually-nothing:
I don’t actually know what sin/cos is, they didn’t teach us in school yet :sob-hole: as far as I know it’s something to do with the angles of a right angle triangle or whatever who cares
:actually-nothing:
To find the rotated points, it takes each of the coordinates and multiplies X by cos theta + Z * sin theta, and multiplies Z by -X * sin theta + Z * cos theta, where theta is the value it is being rotated by. Sin and Cos values for values 0-90 degrees are hardcoded into the program because it’s very hard to calculate :shrug-1:
:actually-nothing:
Then the program takes those rotated points, and projects them into 2D points. Those equations are much easier:
Projected X = (X * FocalLength)/(Z+FocalLength)
and similarly,
Projected Y = (Y * FocalLength)/(Z+FocalLength)
:actually-nothing:
Then it draws the lines between the points using a hardcoded edge table and bresenham’s line drawing algorithm. :thumbs-up:
:actually-nothing:
It then releases the pixel buffer and gets ready to draw another frame!
:actually-nothing:
And after a lot of debugging, it’s finally finished! :yay:
(The video is at 500 kilohertz btw :shocked: )

0
151

Comments 0

No comments yet. Be the first!