Wednesday, 30 May 2012

OpenGL Terrain: Now with Vertex Normals

Just a quick update on the progress I have made today. This morning I added some much more useful camera controls, which support keyboard and mouse, making it much easier to navigate the small piece of world I am currently generating. The second major change has been the inclusion of vertex normals. Previously, the lighting looked like this:


Here you can clearly see the individual quads that make up the terrain. This is due to the fact that the normals (which are used in lighting calculations) are made on per surface basis. To improve the lighting, these can be calculated for each vertex, e.g. for each of the four corners of the quad. This is a pretty simple operation which takes the average of the surface normals from the quads that share a vertex. To write the code for this took far longer than I expected, but that was mostly because I also ended up tidying up and refactoring previous work as well. The end result is that the terrain now looks like this:


Much nicer, don't you think?

No comments:

Post a comment