• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
multifractal

Generating Terrain on the GPU vs on the CPU

12 posts in this topic

Hello, 

I am working on a little procedural planet (like many others) and I recently tried putting my terrain algorithms in a GLSL vertex shader to see if there was a performance difference. There wasn't. After seeing this I was wondering why many people decide to do terrain calculations on the GPU. Is there something I am missing to all of this? Thanks for any replies. 

0

Share this post


Link to post
Share on other sites

Last time I heard that in person, a friend of mine was comparing his i7 2xxx to a few years old GF 8600 GT.

If you were doing the computations on CPU, perhaps you were uploading the result as static data?

0

Share this post


Link to post
Share on other sites
You were likely bottlenecked by some other part of the pipeline. Drawcalls, pixel shading...
0

Share this post


Link to post
Share on other sites

Graphical applications usually are bottlenecked by pixel shader, while vertex shader and cpu are being idle most of the time. People usually move computations from cpu to vertex shader to save cpu/memory resources for other cpu specific tasks like AI, physics.

In your case, you have moved some calculation from cpu which was idle most of the time to vertex shader which was also idle most of the time. The performance of your application was determined by pixel shader which was not changed and overall performance of your application was not changed, too. But you should be able to see difference in loads on cpu and vertex shader using some performance profiling tool like Nvidia PerfHud.

0

Share this post


Link to post
Share on other sites

Last time I benchmarked it, I had a roughly 10x performance gain from running all my fractal noise generation and normal map (sobel filter) in the pixel shader, versus on the CPU.

 

That said, there was a significant degree of optimisation behind both my CPU and GPU implementations. If you haven't carefully tuned all aspects of your shader pipeline, you may not see such gains.

0

Share this post


Link to post
Share on other sites

I have also recently (this week) written a marching cubes terrain generator on both the CPU and GPU and measured both generation times based on different grid sizes. 

 
Using a 32x32x32 grid the results are:
GPU:    ~2ms        (30x faster)
CPU:    ~60ms
 
Using a 42x42x42 grid:
GPU:    ~2ms        (80x faster)
CPU:    ~160m
 
Using a 64x64x64 grid:
GPU:    ~2ms        (170x faster)
CPU:    ~340ms
 
These results seemed a little far-fetched to me so I ran the GPU generation every frame since at 2ms, this should mean real-time terrain updates, right? It slowed down considerably but after tweaking how the memory was managed and not having to allocate huge chunks of memory every frame it ran at ~10ms which is quite acceptable for a level editor or similar application. It is worth noting that this implemented using a ATI HD 6870 GPU and a AMD Phenom II x4 840 (3.21GHz) and the CPU was only using a single core. The GPU generation was done using a DX11 compute shader and an AppendStructuredBuffer. As stated above it will depend on your implementation and how that is optimized but here are some numbers to show at least how much of a gain I have seen and that it is worth doing.
 
-BiT
1

Share this post


Link to post
Share on other sites
Wow I didn't think gains like that we're possible. I must be mismanaging something to be getting these subpar results. I will run it through a profiler and see if there are any obvious issues.

Last time I benchmarked it, I had a roughly 10x performance gain from running all my fractal noise generation and normal map (sobel filter) in the pixel shader, versus on the CPU.
 
That said, there was a significant degree of optimisation behind both my CPU and GPU implementations. If you haven't carefully tuned all aspects of your shader pipeline, you may not see such gains.

Yea I really didn't do any optimization before just porting the code over to a shader so this may be a source of the error. Just out of curiosity how do you render terrain from a pixel shader?
0

Share this post


Link to post
Share on other sites


Just out of curiosity how do you render terrain from a pixel shader?

Every terrain tile has a heightmap, a normal map and a colour map - these are all generated into textures using an FBO and a pixel shader. There are three stages, the first generates the heightmap using a ridged multi-fractal simplex noise generator, the second stage takes that heightmap and runs a sobel filter to generate the normal map, and the third stage takes both height and normal maps, and produces a diffuse/specular texture based on the height and slope of the terrain.

 

The terrain itself is a pretty normal quad-tree of mesh tiles, which is all generated and managed on the CPU, and rendered much as you would expect. Basically your standard normal mapping + phong shading.

1

Share this post


Link to post
Share on other sites

Graphical applications usually are bottlenecked by pixel shader, while vertex shader and cpu are being idle most of the time. People usually move computations from cpu to vertex shader to save cpu/memory resources for other cpu specific tasks like AI, physics.

In your case, you have moved some calculation from cpu which was idle most of the time to vertex shader which was also idle most of the time. The performance of your application was determined by pixel shader which was not changed and overall performance of your application was not changed, too. But you should be able to see difference in loads on cpu and vertex shader using some performance profiling tool like Nvidia PerfHud.

 

Most modern GPUs have unified shader models, so there are no dedicated vertex or fragment units. They are shared.

1

Share this post


Link to post
Share on other sites
[quote name="Ameise" post="5079031" timestamp="1374272051"][quote name="ossaltu" post="5078660" timestamp="1374139902"]
Most modern GPUs have unified shader models, so there are no dedicated vertex or fragment units. They are shared.[/quote]

So doing these calculations on the vertex shader are no different (performance wise) than doing them on a pixel shader?


Just out of curiosity how do you render terrain from a pixel shader?

Every terrain tile has a heightmap, a normal map and a colour map - these are all generated into textures using an FBO and a pixel shader. There are three stages, the first generates the heightmap using a ridged multi-fractal simplex noise generator, the second stage takes that heightmap and runs a sobel filter to generate the normal map, and the third stage takes both height and normal maps, and produces a diffuse/specular texture based on the height and slope of the terrain.

The terrain itself is a pretty normal quad-tree of mesh tiles, which is all generated and managed on the CPU, and rendered much as you would expect. Basically your standard normal mapping + phong shading.

That is really interesting. Is it more efficient to generate height maps in a pixel shader than to do the calculations on a vertex shader and just modify the position? Also are each of your quads/tiles individual meshes?
0

Share this post


Link to post
Share on other sites


That is really interesting. Is it more efficient to generate height maps in a pixel shader than to do the calculations on a vertex shader and just modify the position?

The heightmap and normal map are roughly 16x the resolution of the mesh tiles. At one point I had a separate CPU-side noise generator to produce the meshes, but vertex-texture-fetch seems to work just fine.

 

Also are each of your quads/tiles individual meshes?

There are all the exact same mesh, instanced once per tile.

0

Share this post


Link to post
Share on other sites

Most modern GPUs have unified shader models, so there are no dedicated vertex or fragment units. They are shared.


So doing these calculations on the vertex shader are no different (performance wise) than doing them on a pixel shader?


Yes and no.
Per-vertex/per-pixel the amount of time taken will be the same but the pixel shader is going to be (more than likely) executed many more times than if you did the same work per-vertex.
0

Share this post


Link to post
Share on other sites

Sorry to mess with this old thread but after a lot of tweaking I got my openCL program to generate a 128x128 heightmap in ~1ms. I was doing a lot of non-GPU friendly things in my previous implementation...

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0