How to build a procedural city in WebGL
learningthreejs.com
learningthreejs.com
He wrote a whole article series walking you through it, plus source, etc, starting here: http://www.shamusyoung.com/twentysidedtale/?p=2940
He released the executable at the end of the series, and I'm still sad that, as a non-programmer, I couldn't get it to run on my computer. I would have loved to have a chance to explore the world. Some of his screencaps are mindblowing.
[ETA: Since it's not immediately obvious how to get there from the rest of the articles on Project Frontier, here's the link to the source code: http://www.shamusyoung.com/twentysidedtale/?p=15808]
Along related lines, I saw a similar tutorial yesterday on creating a synth using the Web Audio API: http://noisehack.com/how-to-build-monotron-synth-web-audio-a...
Three.js is taking care of a lot for you, and it's not a bad thing. It's doing scene graphs, matrix math, GL setup and teardown code, shader setup and teardown, buffer setup and teardown, camera math, and much more.
Use a bloody engine unless your explicit goal is learning something arcane.
But it shouldn't be much harder in this case! Layer some octaves of simplex-noise to form a terrain, and then for any non-occluded map region, "grow" a building from the center of each noise feature. Might be possible to only tell the GPU about the terrain-texture, and create the buildings entirely in a shader, actually.
> Layer some octaves of simplex-noise to form a terrain, and then for any non-occluded map region, "grow" a building from the center of each noise feature. Might be possible to only tell the GPU about the terrain-texture, and create the buildings entirely in a shader, actually.
It's possible to generate the simplex multi-fractal texture itself on the GPU purely using GLSL via WebGL [1].
Growing buildings from a heightfield texture purely on the GPU though is a bit more tricky, because you don't want to scan the entire hightfield redundantly every frame to extract noise features. In other words, you'll want to cache this feature data, then "grow" the buildings, then cache that. It may be possible to hack OpenGL/WebGL into doing something similar to this on the GPU, but honestly OpenCL/WebCL will make this so much cleaner to implement I shudder to think how ugly this would look in GLSL.
So I would actually use the GPU to generate terrain heightfields (a good use of its massive parallelism), then a special shader to detect features (e.g. even something as simple as a few order derivatives at low resolution) and download them to the CPU. The CPU would then generate and compile a list of building coordinates, upload to the GPU, and use the GPU to perform instanced building rendering from them.