New Monkey Demo: 3D Heightmapped terrain
Submitted by Earok on Sat, 09/17/2011 - 18:49New HTML5 Monkey Demo - 3D Heightmapped terrain! Try it here, use cursor keys to move, A/Z to move up and down, Plus/Minus to change detail level, and L to set the terrain as infinitely looping. The source code has already been bundled into the Earok's Monkey Demos pack.
This was a fun one to do, certainly not as painful as I had thought it was going to be. The inspiration was the "Voxel" terrain engine from the Novalogic Comanche games, though frankly I find the term "Voxel" to be misleading as it's really a raycaster. The way it works is that rays are casted from each Vertical line across the screen, detecting where the map is hit and drawing to the height of the hit part of the map. The ray travels into the distance until it either hits the maximum distance, or what's already been drawn extends past the top of the screen.
The unfortunate weakness with doing a terrain render this way is that you're limited to four degrees of freedom - meaning you can move freely forward/back, left/right and up/down, but you can only rotate left/right (pitch and roll rotations can be faked to a degree though).
I'm pretty sure that this is a first for Monkey, it may even be a first for HTML5 in general. Unfortunately the framerate slows to a crawl on the higher detail levels (It's fine in the C++ export). I think the big slow down is simply drawing the pixels to the screen, if someone can think of a way to make the demo run much faster, I'd love to hear from you!
(Edit: For bonus points - where did I get the terrain for this demo from?)
Comments
I love it! I'm a big fan of this style.
Where is it from? You didn't procedually generate it?
@Sam cheers, it's certainly a very distinctive look the method generates. The Novalogic guys must have been geniuses, it's quite remarkable when you compare the graphics from Comanche versus comparable games of the era (such as Gunship 2000).
@arran hells no, it's a combination of a pre-existing height map and colour map from another one of my games. I'm not yet smart enough to be able to implement a terrain generation algorithm.
I remember having loads of fun running around the voxel-based landscapes of this game, back in the day:
http://www.mobygames.com/game/dos/lords-of-midnight
And your demo reminded me of that :)
It also reminded me of Outcast, of course.
I had a few issues with that game, but the landscapes were lovely.
Earok, tis not hard. I did it as a uni assignment. :P http://gameprogrammer.com/fractal.html Basically draw a line, split it in half, set the connection point at a random height (well that follows some parameters to keep it sane..) Rince and repeat until you get the detail you are after. Same sort of thing with 3d, but you do it in squares. :P
@sam that's interesting, I wasn't aware of any voxel terrain games not by Novalogic. Cheers for that.
@arran yeah, no, I'm not going to do that =P well, maybe if one of my games actually requires it I'll look at it. Thanks for posting the link though.
Link was first google result. :P