As of today, I finally cobbled together a matrix implementation that allows me to rotate and translate the camera and objects. This is very early and poorly optimized, as I learned in the pixel thread. I can draw filled triangles, but since I haven’t done any depth calculations, they won’t render properly yet.
This is most similar to @kwx’s 3D implementation Carrier 3D implementation, though his is far more optimal than mine will ever be (I just don’t have a lot of time to work on this right now). I’ve also taken inspiration from @Brohann’s more modern 3D work, which uses some similar techniques.
DONE
drawPixel
drawLine (Bresenham Algorithm)
Wireframe triangles
Filled Triangles
Shaded Filled Triangles (uses an h value for the intensity of each triangle vertex and scales it evenly along the palette)
Instance class, used for instances of 3d objects
Cube class (inherits from instance)
Vector3 and Vector4 classes (inspired by my experience with other game engines)
Matrix class and associated operation functions
Camera class
Implemented rotation (just about world origin for now) and projection Camera math w/ matrices
TODO
Clipping (aka the reason the camera range is so limited in this demo)
Hidden surface removal
Flat shading
Refactor matrix suite to work off of integers alone
Gouraud shading
Texture mapping
Advanced color processing
Store colors of textures/models as hex values
Color quantization/dynamic palette selection using octrees
Dithering (stuck between Floyd-Steinburg and Bayer Matrices atm. Former works better for diverse palettes but worse in motion, latter looks better in motion and more performant, but challenging to implement with a diverse palette)
Eliminate function calls as much as possible to optimize performance. This is very impactful, but I’d like to hold off on it until I finish the literature I’m using to guide my early development.
Currently I don’t have any hardware on me, but I’d imagine it already runs terribly. I haven’t optimized my matrix code to eliminate floating point math and quite frankly my knowledge of linear algebra is so shaky I don’t feel prepared to do it yet, so it’s been sent to the backlog! My plan is to just scale the whole world up like 100x so it won’t be noticeable that every vertex gets snapped to a whole number. I have no idea how to handle the rotation matrices with that yet, though! I don’t anticipate any of my lighting code will ever run well on hardware, I just want to do it for practice/fun. I will keep adding more advanced features until even the most optimal code runs performance to the ground (and then I will back up when I decide to actually use it for a game, lol)
Anyways, if you have any thoughts or input on what kind of 3d games you’d like to see, or questions on where I learned the techniques I’ve used up to this point, let me know! It’s all pretty much new to me, too.
If you’re working on your own 3D stuff, please share that as well!
Update, the preliminary code for clipping is done (based on the tutorial I followed in this textbook), but it’s omega bugged. It works well when facing the negative X direction (left of origin) but does not work almost at all in the positive X direction. Also I don’t think any of the advanced clipping stuff works (partial clipping for objects that lie on the clipping planes), though it’s admittedly unfinished. The textbook left a lot of stuff vague (like literally anything related to moving the camera) and I need to sleep on it to work through the logic.
When I can get clipping and hidden surface removal (next on the list) done, I want to take a break from engine work to make some cool demos. I’d really like to make a wave simulator that takes advantage of my custom fillTriangle with vertex shading, but it might need more optimization before that’s reasonable.
Lol, I get the sentiment as a teacher - my students’ devices frustrate me to no end. However, you underestimate the insane work that the Makecode team has put into the web emulator - it can really make the most of limited resources! On the other hand, I am very inexperienced with optimization (coming from a modern game dev skillset where you can pretty much ignore optimization and be mostly fine), so I have a lot to learn and implement before my engine can perform well on hardware, if that ever happens.
And even if it does, I will push it beyond that point! I intend to program demos as a thought experiement that are really only intended to run on GPUs, as CPUs are not very good at the kind of math that renders 3D graphics. I mostly just want to practice my programming skills, but I also want to show my students how far you can push unsuspecting tools if you commit to learning new things.
First off thank you, you’re very nice! However… here’s the thing:
This is my last day of Spring Break before the chaos that is the last month of school. I’ve only made so much progress so quickly because I’ve probably poured 80 hours of research and development into this project in the past 7 days. Being a schoolteacher means besides the 40 hours a week I spend just at school, I also spend 3-5 hours each day on lesson planning, studying, and grading so that I can be the best teacher possible for my students. If I fall behind on that work, they suffer as a result. Today I am taking a break from my 3D engine and I may not have time to revisit it until next Friday, if then.
I will continue to make progress, but updates will be pretty slow from here, at least until summer time
Boys Its my time I’m gonna figure out how to make a 3d rouge like in makecode.. No experience at all but I’l’ try me best. Anyone wanna help?? pls..
If you’re curious, this is the book I’m using to help develop mine. The digital version is available freely online (it’s a $50 book but I’m borrowing it from my local library)
I’ll be honest, some of the explanations go over my head (I’ve never been the best at understanding textbook math, even though it makes sense to me when I actually try it), but the most important parts are the pseudocode. If you can find out how to put a pixel on the screen, you’re good to start.
I also might recommend peeking at the code inside @Brohann’s 3D stuff - it was a great starting point for me.
Fixed major clipping and culling bugs. Still haven’t implemented smart clipping. Added tank controls so you can walk around the scene. No collision and there won’t be for a long time.
Next step is hidden surface removal (the reason why the colored in cubes look so odd right now - it’s not drawing their faces in the correct order).
I had a dream about specifically this the other night, lol. Would be nice, but I really want to do some graphical tech demos to further practice my math skills first. Maybe long term I’ll try something.