But, thanks to lots of help from Ryan, the frame rate has easily doubled. This should mean that I can go ahead and add particles and god powers and not have to worry about the frame rate any more. Note that I said “should”…
And if you’re an artist or modeller, check out Ryan’s new utility CrazyBump. It “creates normal maps directly from textures”. Not being an artist I don’t know what that means, but lots of people seem to like it.
I’m curious – what did you do to increase the performance?
I’m going to write a whole article about how I did my terrain once the game is done, but here’s what it boiled down to:
* Removed the center point from the water quads, halving the number of water triangles being drawn.
* Used index buffers to only draw the terrain and water in a radius around the look-at point instead of drawing the entire terrain every frame. This made my vertex buffers much smaller and also prevented me from having to update them every frame.
* I’m now testing to see if the camera has moved before updating the index buffers with new triangles to draw.
With these optimizations, I’m getting about 75 fps when the camera is still or rotating and about 45 when the camera is panning. The movement just “feels” much better now. I could probably do even better, and I probably will at some point. For instance, my water undulations are done using a cos(); I really need to get rid of that.
“For instance, my water undulations are done using a cos(); I really need to get rid of that.”
Um.. no chance of using vertex shaders? Other than that, the only thing that comes to my mind (apart from render-to-vertex-buffer trickery) is that if the api has some kind of matrix palette thingy for skinning, that might be useful..
Anyhow, just based on that one line I’m guessing you’re spending a lot of time uploading vertices to video memory.
The fact that the index range thing really helped is surprising, as you should be able to render tons and tons of primitives at once. As long as you make sure the data is in the video memory and stays there. Perhaps it’s another side effect of transfering lots of static data around..
I don’t want to use vertex shaders because a) I would then have to learn vertex shaders and b) Planitia would not be able to run on video cards that didn’t have shaders.
And I would have thought that rendering the whole terrain every frame wouldn’t have been a big deal either, but apparently it was, especially on my home video card (a 6800 GT if I recall correctly). It’s possible I’m not doing something right with my vertex buffers, but again, I’m not sure what.
“Planitia would not be able to run on video cards that didn’t have shaders.”
Well, how many cards nowadays don’t support vertex shader model 1.0, or at least fixed functions? Not many. But of course I understand not exactly wanting to learn how to implement them… 🙂
Vertex shaders are automatically emulated in software if your card doesn’t support them! Hardware support is required for pixel shaders, but it’s optional for vertex shaders.
Mind you, without hardware support you won’t see any speed benefit from the shaders… but you won’t sacrifice compatibility either.
I agree with ya, though… now’s the time for God powers and particles and other shiny things!
… and after those shiny things have eaten away the framerate, then will come the time for further optimization!
Yes, first make it work, then make it fast.
You might consider disabling the waves and see if it has a dramatic effect on the framerate.. perhaps just animate the water texture or something, if so.