Show HN: 3D Renderer Built using 2D HTML Canvas
vivekseth.com
vivekseth.com
For fun i made a 3D thing a few years ago, you can check it here:
http://runtimeterror.com/pages/badsector/nyan/test.html
The code does the clipping part (triRender function) although HSR is painter's algorithm with a simple sorting (triSort) with a heuristic (triCompare) that i came out through trial and error (because of the distortion introduced by the perspective projection this doesn't always work and IIRC i'd need to actually split the polygons for better result but i was too lazy for that :-P).
Note that i wrote this for fun a few years ago, i am not a web dev nor really follow web tech. This is the biggest block of JavaScript code i've written for years :-P.
http://buter.software/rend386/
I played around a lot with that engine "back in the day". Modded a Power Glove to hook up to the parallel port (I also did the same for the Amiga), and I used a slightly modified VictorMaxx Stuntmaster for an HMD when it became available.
I had fun playing the little game you made in this engine. I think its very impressive (heck, you should throw it up on github). There used to be a thing in the late 1990s and early 2000s of something called the "3D Engine List" that listed all the 3D engines in various languages and whatnot (both open source and commercial). Eventually, that all went away for one reason or another. I kinda wish it still existed. When someone shares such work, it always brings a smile to my face. So thank you for sharing your work with us!
EDIT: i forgot. The 3D Engines List (i suspect you mean [1]) lives in DevMaster's DevDb [2]. DevDb was originally just engines and IIRC its initial data was from another database site "3dengines.net" from around 2004, which itself sourced the 3D Engines List.
[1] http://web.archive.org/web/20060107015234if_/http://cg.cs.tu...
You should pump that website up a bit and make sure to name drop people who use it, though I appreciate your humility in that way.
Anyway, awesome work
Here's my creepy 3D rendering: http://mrspeaker.net/dev/head2/ It's not using a real z-buffer (just canvas's path rendering for triangles, and sorted back-to-front) but it's still pretty cool!
"Computer Graphics: Principles and Practice" from Foley and van Dam.
The 1st edition used Pascal, the 2dn C and now the third one uses C++ and C# on their examples.
Its a great exercise, and I found that rendering basic .obj files was a great place to start - the spec is quite easy to follow: https://en.wikipedia.org/wiki/Wavefront_.obj_file
Very smooth, thanks for sharing!
So if those cubes are textured, you'd need to subdivide the texture and approximate each with affine transforms. Here's an example of this hack (which was only necessary years ago before webgl existed): https://acko.net/blog/projective-texturing-with-canvas/
Check out drawLine3D() in until.js to see where I apply the perspective projection.
The readme lists a few useful resources; in my opinion the most difficult part was implementing clipping.
If you’re interested in learning graphics, this is a great place to start!
awesome work!
I was under the impression that to get the best GPU performance, webgl is the answer.