Hacker News new | ask | show | jobs
by derefr 4698 days ago
I guess I'm a bit spoilt, but these days I kind of expect "procedural", in graphics demos, to also imply "infinite in all directions, without repetition, with deterministic results in regard to position, generated in real-time, and without caching anything you're not currently looking at." Maybe I'm too picky...

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.

2 comments

Well, that's NOT the meaning of procedural. That's why Minecraft is infinite AND procedural, because they're different things (often the former requiring the latter).
I agree with you, except the "without caching anything". Realistically, it's nearly impossible to generate a full 1080p screen of high resolution objects and textures without some amount of caching. Possible for some corner cases, yes, but not if you want a realistic world.

> 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.

[1] https://github.com/judnich/Kosmos/blob/master/README.md

See Highway 4k (combined 4k winner at Assembly 2013!) for a REALLY SHINY example of what can be done with WebGL shaders:

http://pouet.net/prod.php?which=61668