So due to other commitments I haven't had much time to work on this project. This evening I decided that I at least needed to get basic shadows working. Shortly after finishing writing my post last time, I changed from a blocky-rendering technique to one where it just takes one pixel for each height from the height value and then connects and colors those accordingly. This mostly gets rid of the weird glitch that I was having before, but sometimes I will still see things flashing, I'll figure that one out eventually. 

When I started working on this project today I had a map colored completely flat. I couldn't see hills or valleys very well except the tops of the mountains and the color of the tiles.



Like I said last time, in order to light anything in a computer you need normals to tell the computer which way something is facing so that it knows if it is facing away or towards the light source. Last time it was simple because when using the boxes I just needed simple 1 or -1 normals for each face, since each face was facing 90 degrees some way or another. Now because each vertex is connected to it's neighbors and makes a tile, these no longer face in 90 degree increments. Again, credit for figuring out this stuff is mostly Shamus Young in the post I linked last time. To find the surface normal of each vertex you need to find the cross-product of it's neighbors, which will point straight out of the surface telling the program exactly where it is facing. You are supposed to do this step on the GPU (Graphics Processing Unit, basically is like a mini computer that is super fast at graphics processing, but is very very bad at everything else) but because I didn't have much time or energy I decided to just hard code it on the CPU (Central Processing Unit) meaning it will be easier and faster for me to write the code, but I will only be able to do static shading, i.e. nothing can move or else it won't make a shadow. After I implement the basic code for finding the cross products (much easier than I was expecting mind you) and calculating the normals, I get something like this.



Obviously there are still some problems (the entire left side thinks it is facing away from the light and the entire right side thinks it's a mountain with the same height as the rest of the water), but I am happy with this result and it is a good place to stop and write a blog post. Perhaps I should move this blog somewhere else, as it has little to do with the villager sim project, even if this might be used eventually. Next time: bug fixes and more interesting landscape!