Here is my implementation of a 3D software renderer / rasterizer, in js.
The end result is a movable (draggable) z-buffered, backface-culled object, with perspective correct texture, lighting(gouraud, diffuse), shading and bump mapping.
Up until mode 5 I use Painter's Algorithm at the triangle level.
It's done in a super hurry so it could be written better / faster.
But it should render anything as long as it has coordinates for vertexes, triangles, and UVs. ATM, you have to paste your coords in data.js...
I am
not handling antialiasing after the z-buffering.
I could implement some mouse rotation if I had some extra time. -Hah.. extra time...
ChangeLog:
28-09:\> Added a canvas with a 3dsmax/c4d style background.
28-09:\> Created point drawing and line drawing functions for a cube.
29-09:\> Can draw a wireframe, with perspective and a "camera": projectionTransform(translatePoint(rotatePoint(x, y, z))).
29-09:\> Can rotate the camera (actually, the object).
30-09:\> Implemented rendering a cube as triangle wireframes.
30-09:\> Implemented scanline triangle filling with a trippy <canvas> antialiasing-related transparency/flickering "problem".
30-09:\> Added a few radio buttons which change a global flag to 1 2 or 3, which is read in the game loop.
01-10:\> Wrote an efficient triangle fill function that fills using large pixels instead of lineTo. This is for an eventual z-Buffering mode.
01-10:\> Implemented the Painter's Algorithm to order the triangles for now. Though there seems to be a problem with triangles at funny angles. Which happens because of the average distance calculation of this algorithm.
04-10:\> Implemented (fixed) my z-buffer with the interpolation of my z values. Note: As of now, modes 5 and up are no longer low res. I'm actually drawing 1/1 px instead of 1/4. (so it is slow as hell)
06-10:\> Calculating vertice normals.
07-10:\> Calculated averaged vertice normals (keeping in mind adjacent triangles sharing a vertice)
08-10:\> Finally implemented diffuse lighting by interpolating the right stuff. :> ..It does look shite though. Or does it?
10-10:\> Fixed a bunch of stuff and I should be done. I've also added mode 7, which is a diffuse lighting exploit that simulates reflections from some imaginary tiny lights.
You know, this thing is fully supported on any device with a good browser. So try it on your phone, see how many fps you get. :)