In my engine I create infinite terrain with usage of Perlin noise alghoritm computed on CPU.
Creation of terrain goes like this:
- If camera is near unloaded patch, create it
- Compute 513x513 noise array with given boundaries
- Compute normals, tangent, binormal, indices
- Pass data to vbo
Pros:
- Only needs to be rendered when needed
- Easy to make collision
Con
- Slow 64 513x513 patches are created in 3,1s(one thread). For each tile ~20ms noise creation, ~25ms vertices, normals, tangent, bitangent, indices. When camera moves fast, user can notice tiles loading.
- memory consuming???
Now I was wondering how to speed this up by generating terrain completely on GPU But there are some doubts:
- If shaders run every frame, isn't this computation power waste to compute noise over and over? This can be avoided by writing result into RBGA texture and used later in vertex shader for displacement, but increase memory usage. From the other hand if the creation would be super fast, only visible tiles should stay in memory. However detaching buffer causes gpu-cpu sync which may slow down the app (am I right?)
- If the terrain is just a flat grid displaced by vertex shader, the same work needs to be done on CPU to compute height and normal at given point for collision.
- This is just a concept, but to speed everything up I was thinking about projecting grid on viewport so only minimal amount of vertices is used. Do you think this would work?
My final question is:
What the best/fastest/broadly used technique to create infinite terrain on GPU?