See previous journal update for reference.
Displacements
As I mentionned in the previous update, I've experimented horizontal displacements to create cliffs, overhangs and hard edges. It also creates interesting rock formations, similar to what you'd find on volcanoes. The result is looking quite nice, but as expected there are some issues:
- texture deformations
- terrain is no longer a heightmap, so you can't take a world-space position and cast a ray down anymore, and sample the height in the heightfield to get back the world-space position on the terrain.
- lighting is messed up ( more about that soon ), as the deformation only moves the vertex and not the normal
- performance goes down yet a bit lower
- terrain can self-intersect if the displacement is too high
An overview of the algorithm:
- generate a planetary tangent space for the given sample position
- generate a height from procedural algorithms
- generate a vertex in planet space by displacing the vector going from the planet center to the surface by the planet radius plus the height
- use this new vertex as input to fractal noise - get 2 displacement values, one along x coordinate, another along z coordinate
- displace the mesh by using the tangent space and the given 2 displacement values.
Lighting
To generate normals I was simply derivating the heightfield ( taking the 4 adjacent heights ). But after displacement the mesh is no longer a heightfield, so there are two possibilities:
- the wrong ( but easy ) one, is to not do anything and ignore the displacement: lighting is not correct anymore, but it doesn't look too bad. The only real thing I'm worried about is when adding shadow maps later, the diffuse lighting won't match the angle at which the shadow map starts, so you might see strange artifacts.
- the right ( but hard ) way, is to generate the triangles on the cpu and perform a cross product between the adjacent triangles. Unfortunately, the hard part comes from the fact that you get seams between terrain patches, as you only have access to an adjacent patch's heightfield ( and not mesh ). Fixing it would require a few design changes in the terrain code.
I haven't decided which solution I'll finally use, I guess this will mostly depend on how serious the shadow mapping artifacts will be.
Collisions
Yesterday I also implemented collisions on the terrain, just for fun. Wasn't really hard to do it in the "brute force" way: when the mesh of a terrain patch is generated, I also create a collision mesh for it. I then implemented a canon-ball launcher with the left mouse click, and played with launching balls on the terrain for a good half-an-hour. It was funny to see them bounce and roll on this complex terrain. Performance was okay on the collision tests, but generating the collision mesh ( especially as each time a terrain patch gets subdivided in 4, it generates 4 children, each with its collision mesh ) causes small slowdowns.
Pictures time
As usual, click on an image for the 1024x768 version.