Monday, October 29, 2012

89 – Spherical harmonics, bitch!

Spherical harmonics was not the main thing I worked on since last time, but I have some results and I have great hopes for anything that promises to solve at least partially my lighting issues, so I'll start with it first.

Let me reiterate on the problem. Here is a barrel illuminated by one directional light from the front:

There is something funky going on with the cap and the normal map is not great, but it works. Things break apart when viewing the barrel from the back:

The diffuse contribution gets close to zero and you are left only with ambient lighting, which is dark and flat. You can make it less dark by increasing it coefficient, but it will still be completely flat. The worst part is that that normal mapping is not visible at all. Normal mapping just creates the illusion of complex geometry. Without it the object seems a lot simpler.

I tried a hacked together solution of my own, partially some light factor combination, partially some hacks, partially some trial and error. I have already shown the results of this method:

This method is pretty good, but it produces some artifacts and strangeness, especially when objects are on the move.

Now, let's take a look at our spherical harmonics based ambient lighting form the front:

Better? I think so! And now from behind:

Holly shit! Normal mapping everywhere! This techniques also allows the ambient light to be influenced by a cube map, like a skybox. When I'll have a skybox, and after I implement it, lighting should look a lot less uniform.

Right now I like the effect even better than the results of the directional light!

I owe a lot to the XNA FINAL ENGINE and the helpful people around there. Without drawing some help who knows what I might have implemented? Spherical harmonics? No way! More like cubical dingle berries harmonics!

Here are a few more objects with this rendering technique:

And a ton of barrels,a gain from two angles:

What is interesting is the ambient occlusion like effects that you can see near the bottom of the stool. I hesitate to call these artifacts.

Let's take a closer look, from the behind, where the effect is fully visible:

I think I need to have another go at the meshes, to make sure that everything is set up as it should regarding face smoothing and that those settings play nice with the rendering technique.

As said before, I did not fully implement this method and the coefficients are probably far from optimal. I can play around with them, like accentuating the lighting:

Just now I am realizing that I did all these screenshot without specular highlights. I'm not going in again and redoing them, but here is one screenshot with specularity:

So that's about it for today about ambient lighting. I need to test it, bugfix it and benchmark it to make sure it is feasible to render a whole scene like this.

The other thing I worked on is the terrain. My goal is to finish the terrain for good in about 1-2 weeks. The main problems are performance, memory consumption and terrain size.

In order to try to resolve these, I am phasing out a singular heightmap for the terrain. The terrain now gets generated, then chunked into 128x128 vertex pieces (do the math why this is the max size for the Reach profile) and saved/loaded from disk. The chunked heightmap operates slower than one full map, but it is my hope to keep the whole map in memory, but only generate geometry on the go based on what chunks are in view. There are tons to talk about here describing what I did, but since I spent so much time describing lighting, I'll skip it. I broke the terrain with the new chunker and I had to fix it:

Memory consumption is down from about 1 GiB to 700+ MiBs. A good start, hopefully I can get it down to around 512.

The terrain saving/loading is actually prototype level loading  so soon I will be able to have multiple maps and quicksave/quicklaod.

Then I improved terrain view distance while keeping performance. The view distance/fog is at its worst on high points, so let me show you a before shot from a high point on the map:

And after:

No comments:

Post a Comment