Terrain rendering in fewer than 20 lines of code
github.com
github.com
I've been investigating the terrain generation / rendering quite a bit for the past ten days and have started to play with https://threejs.org/, webgl and shaders, the current result (https://twitter.com/maxmre/status/933860624773283842) is quite humbling when I see how nicely the Comanche engine works :)
EDIT: It is! Had the commodore version - fun memories :)
Edit: fixed game name
The main algorithm fits easily in 20 lines. However, the JavaScript code is optimized and contains also the initializing routines and input device logic.
It is also a little bit unfair to compare this with shadertoy. He doesn't have to include the render algorithm but relies on a GPU. The Voxel Space engine just draws vertical lines and doesn't need a GPU.
If I extract the code and delete what I can see might be extraneous setup boilerplate (event handling, camera navigation, init function, image download helper utility, various config object initialisations), it still comes in at around 150-200 lines. The render function alone is 38 lines, not including the external dependencies of that function (DrawVerticalLine, screen, camera).
Again, not a criticism of the work, just querying the title.
Next to me, however, was someone who seemed light years ahead of me. He had programmed his own voxel terrain rendering just like this. I had no earthly idea at the time how that was even possible.
In retrospect, he was not so much farther along, but he was passionate enough about game development to read books about these techniques and work out the details. I've always wondered what happened to him, and if he ever followed his passion to become a game developer...
So I ended up doing bits of QBasic, Visual Basic, and C++ (since all three books were in the room, and QB was easier to generate flashy visuals with, as a beginner).
On a side note, fast forward to today, I've taken up metal working as a hobby and kind of wished I had taken metal shop instead. Except for the fact that the highlight of metal shop in my year was when a bunch of knuckleheads ground another kid's teeth down in the grinder while the teacher wasn't looking. So, actually, yea I'm glad I opted for computer lab.
Could probably search for him on LinkedIn maybe it is ha
I don't remember my classmate's name, unfortunately.
Delta Force 2, released in 1999, still used a voxel engine which could already be hardware-accelerated, supporting "stretched voxels" which were able to simulate high grass.
<3 <3 <3
...and for 4K, this one from 2009:
p.s. yeah we edited the terrain to hide the signature pyramid :)
But even without the pyramid it is very obvious, that these maps in your demo were from the game Comanche.
Everyone seems to be in flashback mode, so I'll add mine: I remember getting a good grade in my multiprocessing class by making a voxel terrain generator using mpi and with the same technique, but also with clouds (just think of upside down white mountains). But I just randomly generate them, without any lighting. The color of the voxels were determined by their height. Using (nice) color and height textures adds a lot indeed! It's a shame I didn't know that trick on that time, I remember playing with vistapro[1] or terragen[2].
[1] http://www.creative-3d.net/images/vistaprointerface.jpg (I had an older, ms-dos based version)
[2] http://planetside.co.uk/ (It's great to see that it's still alive after so many years..)
For anyone who wants a refreshing/fun code project, strongly recommend implementing some kind of software renderer. A raytracer or raycasting engine like this one, or something more fundamental like a polygon renderer.
http://www.playfuljs.com/a-first-person-engine-in-265-lines/
Also read the readme file of this Voxel Space engine. Maybe this is already enough to understand the principle.
http://iquilezles.org/www/articles/terrainmarching/terrainma...
Be sure to browse his other articles:
http://iquilezles.org/www/index.htm
and his awesome video tutorials (which tend to be more about the math than the code):
https://www.youtube.com/user/mari1234mari
Enjoy!
How's the rolling in comanche done? The lines are no longer vertical then, so seems trickier.
Roll means the horizon is no longer horizontal by the way, what is labeled roll in the demo is actually pitch :)
I have a bit of a fetish for old-school 3D tricks, I'm currently working on a 3D project for the Sega Saturn using jo-engine.
The re-released it on GOG last year, and remade it this year with a Unity engine (all polygons now).
(edited for more clarity and info)
This would also be a cool thing to give an example of across programming languages. Sort of like how https://github.com/drujensen/fib does it.
Read the explanation of this algorithm and you will see how the 20 lines are meant.
Once you understand the algorithm, it's conceptually even simpler than 20 lines.
The repo contains also the scripts, to generate the GIF animations on the start page and the tools to extract the maps from the Comanche computer games.