Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
8  
Just note that creating terrain on the GPU will make it difficult to do collision detection, picking detection or pretty much any kind of interaction with the terrain. –  Byte56 Jul 17 '13 at 14:25
1  
A compute shader (DX10 or 11) may be used to generate the terrain on the GPU. But as Byte56 stated, you will need to pull the values back out of the GPU in order to interact with it. msdn.microsoft.com/en-us/library/windows/desktop/… –  UnderscoreZero Jul 17 '13 at 17:16
    
creating terrain on a GPU kind of sounds like a bad idea to me. It might work but I figure it would probably work a bit better if you just generate the terrain on the CPU side and send the standard drawing stuff to the GPU. –  Benjamin Danger Johnson Jul 17 '13 at 17:17
    
Just my experience; I actually did just this with aparapi and actually got the damn thing to work; but it actually ended up being slower than just having the cpu do the work. I think because of the overhead of sending data to/from the gpu. If I recall correctly gpu only really works if the calculation is large compared to the size of the data (and also large in absolute terms) –  Richard Tingle Sep 2 '13 at 23:12

1 Answer 1

Well if I was to try to use the GPU for such a thing, I think I would go for compute/opencl/cuda.

However regardless of using the GPU or CPU (which is what I actually do), I would do it in an asynchronous manner, deciding you need some new terrain for the current frame is likely too late (e.g. consider 1000ms / 60 = 16.666ms, and the entire frame wants to fit into that).

Start generating (or loading from compressed files) terrain on a worker thread, and make it available to the rest of the game and rendering once that worker has finished, generally this will be the next frame, or perhaps the frame after that, so the user won't really notice the difference there, but it makes things smoother.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.