I spent a good chunk of time these last two weeks being re-acquainted with some old friends – I found on http://www.gog.com/ some super cheap old games that made up a big part of teenage years; remade to be workable on the modern day processor. Forty bucks and who knows how many hours later, I’ve got Tie Fighter, X-Wing, Alpha Centauri, and Colonization. I also picked up Faster Than Light, a cute little game that’s more recent. It was a sobering reminder that good games don’t need superb graphics; Tie Fighter in particular is simply the best space combat flight simulator I’ve ever played and it used quite basic techniques. The supporting media (music, voice, story) all made it an experience.
Back in the day, I could tear through the skies on the hardest difficulty setting and not take a scratch. Now I’m taking a beating on medium. I guess I got old, huh?
Anyway I managed to tear myself away from the games long enough to do some programming. I wanted to make the ocean sparkle.
So first we need to find a way to seperate the ocean from the land. The way I chose to do this was to filter through each texture fragment and identify if it was ocean or not by checking it’s color. So here we have pixels with more blue in them than red or green, and then when more blue than red AND green.
While performing this, I read about gamma correction on the texture. It seems that the colors on my earth look very washed out, so I applied to gamma correction to see how it looked. It’s quite an improvement.
At this stage, I first started trying to represent the sun as the spot on the surface of the earth at the intersection of the view/light vectors. You can see in the two middle photos above, over India-ish, a slightly brighter sphere. But, when I zoomed in closer to the surface, the circle shrank and vanished. I thought that there might be something wrong with my specular reflection.
I forced each pixel to white so I could see what was going on.
It seems like the white is brighter in the far left photo, but in the middle and right, we can’t see a clear specular highlight. Something’s wrong.
It turns out I couldn’t find the bug in my original shader, so I wrote it again using a new shading method. Blinn-Phong shading uses the same general idea of Phong shading, but instead of calculating the true reflection value, it approximates a reflection vector by getting the half-angle between the surface normal and the view vector. Implementing it was unexpectedly trivial. Blinn-Phong is more computationally efficient and looks as good as Phong. That’s a win-win trade for me. So then it was time to isolate the sea and try out some different effects to find something that looked about right.
Here are some pictures of the real Earth, taken from space/Luna. This is the effect I want to get. On the far left is a shot of the Earth without a sharp solar reflection. The whole sea is awash with blue. The middle and right photos show the sea picking up the reflection of the sun, and the far right one has a sharp angle with the Great Lakes of America almost entirely white.
I don’t think I can achieve all of these things at the same time, using only specular reflection, without also actually implementing the reflection of the sun.
Here I was working out how to get the sea to look the right shade of blue. I was using only diffuse reflection in these photos.
Finally I settled on the below for that distinct silverly-blue.
So that’s where we are for now. This wasn’t really a new capability, I just wanted to make something pretty. But in the end I started looking at different lighting algorithms for different kinds of surfaces (rough, plastic, metal, etc) so I will probably look at these when I get back from Blender.
From here it’s full steam ahead on the Blender tutorials; when that’s done (or as soon as I’m happy enough with the progress) I’ll look at importing the models into C++. My castle class finishes 22 November, so my programming time will effectively double from then. I’m looking forward to it.