If you want to look into ambient occlusion a bit more, here are some interesting sources that we stumbled across.
I thought it would be nice to make fields of grass, only I would need a way to place these guys into my scene so that they would actually correspond to the terrain height. I figured the best way to do this was to make use of the array I used earlier to map my camera to the terrain, and re-apply it to generate billboards for my terrain. Then I decided that, while I was at it, I might as well make an easy way to pick which areas of my terrain I wanted to be grassy.
So I made a nice little PlantGen function, that will take in a grayscale image, and generate billboards at the corresponding locations on my terrain. It slightly randomizes both density of plants and location, But in general, the whiter the pixel, the more grass you’re going to get at that location.
Here’s a zoomed out shot to show the plant mapping image and the corresponding render of grass in my scene.
Below is a short video that shows what its like to run through these lush grasslands…
[youtube http://www.youtube.com/watch?v=9DfTZ4Wlfwg?feature=player_detailpage]
Up close, the water looks more like this:
This feature took quite a bit of effort to get working correctly. Initially, the reflection on the water would just reflect the same image, regardless of where you were standing. The same section of the skybox would always be displayed at the center of the screen. After some investigation, I discovered that the vector used as our angle of incidence in the reflection was in clip space, meaning it will always be the same at any one point on the screen, regardless of where the camera is located or facing. In order to correct this, I had to modify the shader to do the reflection calculation using world space instead. The new angle of incidence became the difference between the camera position and the water’s vertex positions. This resulted in the nice looking reflections shown below.
[youtube http://www.youtube.com/watch?v=-33FhcqdL4o?feature=player_detailpage]
Here is some screenshots comparing the untextured and textured landscapes:
Here is a short video showing the landscape in action:
[youtube http://www.youtube.com/watch?v=XArhbtsYEls?feature=player_detailpage]
The skybox I used came from http://jpclifton.blogspot.com/2011/03/terragen-skybox.html. Unfortunately, there is a bit of a visible crease on one side, which may have been the result of me chopping it up into individual images. It looks pretty good though.
Here is a quick little video showing the skybox in action.
[youtube http://www.youtube.com/watch?v=_WNILh7xa6Y?feature=player_detailpage]
The 2D array is then passed back to the camera class and used to set the camera’s height to the terrain after every movement. If the camera goes off the terrain, it is free to fly about as it pleases.
I used bi-linear interpolation to smooth the camera’s movement across the terrain.
Here’s a shot showing how awesomely the bi-linear interpolation can keep us grounded even on the steepest of steep hills:
Here’s a shot of us flying around outside the terrain a bit:
This video probably does a far better job of showcasing this feature, so here it is:
[youtube http://www.youtube.com/watch?v=m8qysNZHvVU?feature=player_detailpage]
Initially, the terrain produced was very jagged and blocky, so I decided to implement some terrain smoothing. There is a nice tutorial at http://www.nfostergames.com/lessons/TerrainSmoothing.htm which covers some basic terrain smoothing. Essentially, it works by averaging the heights of all the neighbours of each location in the grid.
Here are some side to side shots of my hightmap and generated terrain:
Here is a short video showing this monster terrain in action:
[youtube http://www.youtube.com/watch?v=_f3gXRH5PMA?feature=player_detailpage]
Here are side by side comparisons of the models with and without specular highlights added.
And because I know you all want to see these glorious specular highlights all over those flower petals and dinosaur parts, I’ve included a short video demonstrating all this lighting business.
[youtube http://www.youtube.com/watch?v=XK_5RtvNJLg?feature=player_detailpage]
]]>For example, this file can now be read without issue:
Here is a snapshot of the models after they are loaded:
For a little bit more information on the updated ObjUtilities (or more dinosaur and flower action), watch the video below.
[youtube http://www.youtube.com/watch?v=SNNFqZ0de40?feature=player_detailpage]
All I used for references were the videos posted by Chris Johnson. The spectacular models and ObjUtilities code were all my handiwork.
]]>