Tuesday, February 19, 2013

Screens of the day 29 - These are features actually

I started creating the standalone library that will be the base of the engine. Right now engine code and game code are all in the same project. Before the split can occur, I need to clean up both and then make sure that the library only has generic functionality.

So while cleaning up the code, I got an idea: what if I investigate the range of texture weights that a terrain chunk has. If a chunk can be made to only sample 1/2/3 textures instead of the 4 that it currently does, I'm sure I can greatly improve the performance. But the numbers were not as prone to cooperate and most chunks seem to use 3 textures. I was hoping for more chunks to have 1/2. This distribution depends a lot on the properties of the terrain. Large smooth hills will probably have a more desirable distribution.

But since my terrain has its current structure, I decided to move this feature to the backlog. It will be a worthwhile optimization and might allow terrain than uses any number of textures, not just maximum 4 (with the caveat that a single chunk can have maximum 4 textures), but the benefits I would get right now are not worth it.

But since I started going over the terrain and shaders, I decided to try out spherical harmonics for terrain. Now, I am still not an expert in this domain and would greatly appreciate any input, but let's see my results.

So here is a terrain with basic shading and texturing:

Texturing looks good, but there is no fine surface detail. We traditionally fix this with normal mapping:

This add a fair amount of detail to surfaces that have such an angle that they receive enough light. But if you take a look at the area under the crosshair, which that is not under direct light, there is zero detail added by normal mapping. So here is where adding spherical harmonics might help, giving this result:

Better? I think so. Not sure if this is the way it should look. The effect is also quite subtle. Which is not ideal, since it is a fairly expensive one. It only works with pixel shader 3 or higher. Surprisingly, while the effect is pretty expensive, it is not significantly more expensive than normal normal mapping. Normal. This running joke is getting so old! Anyway, one could optimize it. Experimentally I noticed that for distant terrain, while the difference between no normal mapping and normal mapping is big, at least shading wise, the difference between normal mapping and spherical harmonics is not noticeable, except that the terrain gets a just a little bit darker. So the engine could decide to skip this effect for distant terrain.

Here are three more samples, in the same order:

Hopefully I did not mess up the upload order :)! Here the effect is harder to see because the whole surface is facing directly away from the sun. To better see the effect, download the pictures and use a program that allows fast swapping between them.

And a third sample:

OK, so what do you think? Does it look good? Is it worth it? Anyway, the engine now supports 3 quality settings for terrain. If your PC is beefy enough, there is nor reason not to turn one the spherical harmonics based rendering (which in the options menu will be called "high"), since I don't think it looks uglier.

Here is another screenshot, this time with antialiasing for a little bit of eye candy:

XNA support antialiasing out of the box and my engine also supported it pretty much from day one, but this feature was lost once I switched over form normal rendering to rendering to offscreen targets. Antialiasing is back and more customizeable than ever. Previously you could only choose if you wanted it or not, and XNA did its best to try and follow that suggestion. Now you can choose the number of samples.

Also, you may notice that the terrain is slightly more vibrant. I started messing around with the parameters and brought terrain lighting more in line with object lighting, creating a better illusion that everything is illuminated by the same sun.

And I continued experimenting. Not all of them turned out OK:

I'll continue to clean up the code and prepare for finalizing terrain code.

No comments:

Post a Comment