I put a new video up on YouTube to show how it’s going. I’ve added some new features to the code to take the strain off of generating all of those terrain patches. Note that I intentionally included seams between the nodes to show the LOD changing at work.
I use a couple of runs of Perlin noise to generate elevation data for nodes in my quadtree. This is done recursively until I hit a leaf node, at which point GPU resources are allocated so that I can render to the screen. All nodes consist of 65*65 vertices, all of which need to run through my noise function to determine things like screen space error constants and bounding volumes. Noise generation is by far the slowest piece of code I have right now. Through experimentation I’ve found that I can only squeeze two nodes through the noise function per frame, otherwise the program will “hiccup” as you move around.
First thing I tried to speed things up was to implement a LRU cache for nodes. Each quadtree node is given a cache ID for itself and it’s potential children. When it comes time to switch to a lower LOD, a request is made to the TerrainNodeGenerator object. This object checks the cache, and returns the data if it’s available. If not it creates the elevation data, throws it in the cache, then returns it to the requesting node. When detail levels change the data gets reused if it was recently generated and in cache.
This smoothed things out when moving short distances, but I still needed to limit the amount of requests per frame.
Within the TerrainNodeGenerator object I created a queue of TerrainNodeRequests. New requests are now put into a queue, which were worked off at a configurable interval. This was the magic bullet I needed and framerates jumped way up. Hiccups are gone and I can now start working on materials and texturing.