[WIP] Flash quake/descent style renderer.
Been poking around with this idea for a week or two and I finally came up with something that works OK. It's a first-person-style renderer than can handle arbitrary geometry and spit out a perspective correct scene regardless of view orientation. Well, almost perspective correct: correction is done every 32 pixels. The previous doom-a-like faked the elevation rotation, but this code handles that case and you can even roll the whole viewport about the camera line-of-sight. This is pretty disorienting ... makes me remember why I sucked so bad at descent.
The scene is pretty simple and the camera just moves along a fixed track, but I expect this code will scale much more attractively with scene complexity than the doom-a-like. Although no lighting model is in place yet, adding doom-style sector lighting will be essentially free. The lighting buffer is already being filled, but it is being filled with uniform brightness (for sector-based lighting, filling the lightbuffer is much more expensive than computing what goes in it). I intend to experiment with more complicated lighting models too, like directional lights and maybe bumpmapping too.
Just like in the doom clone, rasterization is done by pushing one pixel into a bitmap at a time. I really wanted to get a papervision style subdivision scheme to work. But to get a decent approximation to perspective correct, surfaces had to be subdivided really deeply, and the end result was a huge number of tiny triangles being rendered each frame. It was ultimately slower than just doing the rasterization pixel by pixel. However, I think that affine texture mapping via graphics.beginBitmapFill will work _great_ for rendering 3D polygonal enemies, because they will far enough from the viewpoint that there is little variation in z over their entire extends. As I recall, both descent and quake used affine texture mapped enemies, and you can hardly notice. In short, I don't think displaying enemies on the screen will load the engine very heavily at all. on the other hand, clipping them against the view portal might be somewhat costly.
I will post source code after I clean it up a bit, the design is very disorganized at the moment. In the demo, you can use the arrow keys to rotate the viewpoint around. You can also use shift/control to roll the whole viewport around (don't get dizzy!). This is the easiest way to see how perspective is approximated... just roll the view 45 degrees and you'll see these artifacts where the texture sort of ripples on the surface. This is a worst-case viewing situation - ugly but tolerable. Hitting the spacebar toggles debug lines in and out.
Bug reports and performance quotes are welcome feedback. :)
Demo .swf file. (pixel rasterizer)
Demo .swf file. (papervision style subdivision)
Look how horrible/ripply the floor looks from some angles - be sure to check this out with debug lines to see how it works.
(reference)Doom-a-like thread