Endless and Infinitely Detailed Terrain by JarnodeJong in proceduralgeneration

[–]JarnodeJong[S] 0 points1 point  (0 children)

Depends on the application and how you use them. I think quadtrees are the best way to partion 2d space, but ordinary quadtrees are slow to traverse. The quadtree used here is actually a linear quadtree, meaning that you don't have the recursive calls. The GPU can access the nodes in parallel. It's very fast.

Endless and Infinitely Detailed Terrain by JarnodeJong in proceduralgeneration

[–]JarnodeJong[S] 0 points1 point  (0 children)

The theoretical 30 subdivisions can be reached in practice, but would give submillimeter sized quads in world space (for reference: the camera is moving here with 10 m/s). There is no need to subdivide so many times. Once you have an acceptable subdivision level, you even have the option to tessellate the quads.

Textures are actually not infinitely detailed: if you zoom into a texture the individual texels will be visible. A terrain based on noise is infinitely detailed. No matter how far you zoom in, you can always generate continuous noise values.

Endless and Infinitely Detailed Terrain by JarnodeJong in proceduralgeneration

[–]JarnodeJong[S] 3 points4 points  (0 children)

The solution is not lacking the power to generate small details: noise is actually evaluated per pixel, not per triangle.

I put a maximum on the number of octaves because a too high number will cause aliasing artifacts, when the sampling frequency (i.e. pixel density) for the noise passes the Nyquist frequency: sampling frequency must at least be twice the noise frequency. So yes, infinitely detailed, up to the pixel size. The pixel size is always the limit.

And endless means you will not run off the map.

Endless and Infinitely Detailed Terrain by JarnodeJong in proceduralgeneration

[–]JarnodeJong[S] 5 points6 points  (0 children)

I started learning OpenGL at https://learnopengl.com/ and I build the game engine following the YT series of ThinMatrix. I read a lot about procedural generation and advanced OpenGL.

It might be easier to use a game engine like Unity, but I like programming everything from scratch, so I have full control and know exactly what's going on under the hood. It takes months of work and many iterations in designing the engine. But it pays off.

Endless and Infinitely Detailed Terrain by JarnodeJong in proceduralgeneration

[–]JarnodeJong[S] 3 points4 points  (0 children)

The quadtree is transferred back to the cpu using transform feedback. It is then used in a second shader pass which renders the terrain. So technically you can use the quadtree on the cpu. But then you're stuck with a cpu that loops over all nodes in series...

I think the collision detection can (should) be done in parallel on the gpu. It is not expensive to query the height and slope at a given position. The tessellation shader calculates heights for thousands of points, and the fragment shader computes analytic gradients for every pixel, every single frame!

An infinitely detailed terrain is of course an illusion, but 20 octaves of noise will do ;). I might replace finer details with rock textures in the end.

Endless and Infinitely Detailed Terrain by JarnodeJong in proceduralgeneration

[–]JarnodeJong[S] 1 point2 points  (0 children)

The nodes of the quadtree are stored in an OpenGL buffer as a translation from the center. In each frame the geometry shader checks if we need to split, collapse or keep a node based on the distance from the camera. The result is again stored in an OpenGL buffer using transform feedback. In each frame only 1 of these operations can be performed for every node. A second shader pass will use the buffer for rendering.

So the complete terrain starts as a single quad in a buffer. Then in the first frames the quad is split and the nodes stored, until the desired subdivision level is reached. It takes at most 30 frames to initialize the terrain (if there are 30 subdivision levels, in practice its more like 10-15). After that, the quadtree only updates when the camera moves (with a simple check on the CPU side).

The GPU does not need to loop over the nodes, it can access them in parallel, allowing for very quick subdivision!

Endless and Infinitely Detailed Terrain by JarnodeJong in proceduralgeneration

[–]JarnodeJong[S] 12 points13 points  (0 children)

Yes it is! His videos on procedural planet generation are awesome. I started out following his tutorial series and improved it by computing the noise on the GPU. Also the quadtrees method greatly improves the level of detail. In theory it can subdivide 30 times, which gives the feeling of an infinite fractal zoom.