Current state of play of the terrain system.
I have written a tool to generate the height maps from SRTM data.
SRTM data is available in 1 degree arcs, so a single file covers 1 degree of latitude and 1 degree of longitude.
I load this data and convert the values within to signed shorts (16 bits of height) which give us a height range of 65536 M. ( roughly +- 32768 ).
Then I split this down to 1 second of arc. So a single SRTM data file gives us 60 by 60 height maps. Each height map is 1025 by 1025 and stored as a binary file not a bitmap. (A 1025 by 1025 bitmap when loaded would actually occupy 2048 by 2048 pixels in video ram on some graphics cards, obviously not a good thing ).
This turned out to be very complex. I tried many different techniques and all of them produced visible artifacts. In the end I bought a commercial tool and reverse engineered it. Now the normals are good enough. I basically generate a very simple vertex based normal per pixel and then apply a couple of layers of blurs on the top to get something that works.
The technique I originally used should have worked, it is still a puzzle to me why it did not. I generated face normals for all faces in the height map, and added this to a per-pixel accumulator. At the end I normalised these accumulators to create the normal.
Which produced horizontal lines across the terrain. Don't know why.
The generated normal map is stored as a 1024 by 1024 pixel bitmap and sampled in the shader.
Each 1 second of arc region can have 4 textures assigned to it. So I generate a type map where each byte of the pixel represents the blend factor for each of those textures.
On paper this should work well, but coming up with a good way of generating these type maps is proving difficult.
I am currently using 4 curves that overlap and calculating a set of values based on height, but that doesn't handle cliffs well. So I am going to swap to a system based on normals.
My plan is to have two regions. One below 6000 metres and one above.
Below 6000 I will blend between texture 0 and texture 1 based on height, then overwrite any pixels with a normal nearer horizontal with texture 2.
Above 6000 I will blend between 2 and 3 based on height then overwrite any pixels with a normal nearer horizontal with texture 2.
I have a streaming system in place which loads terrain patches from disk when needed. Based on a visibility check and a temporal filter.
Each 1025 by 1025 height map is scaled based on the latitude and longitude. Then the width and height are extended by 10 metres so they overlap with the next height map.
From this I generate a CLOD terrain patch. So only the visible parts are rendered and all have LODS applied.
In the shader I blend the pixel by the type map to get a base colour, then apply lighting.
At the moment the shader also clips the polygons against the ground plane not drawing anything below zero. I did this because the water shader draws a refracted version of the terrain for the region below the water line.
I am going to have to remove this as some parts of the world are dry and below zero altitude, sigh.
The water line is too blocky. I need to change the type map so anything under water has all the blend values set to zero. Then I can use this in the water shader to generate foam or waves to hide this artifact.
SRTM data is taken from satellite data which sees the sea. (Groan). So open water has a height depending on the sea state at the time the data was gathered. I cannot find any GIS data accurate enough to automatically solve this problem.
Sometimes the SRTM data has holes in it. I cannot come up with a good way of automatically fixing these issues. Everything I have tried looks awful.
So guys please join this thread if you have any ideas or questions or sources of GIS data on anything that can help.
At the moment I cannot see any alternative to manually editing all the maps to fix the issues. Something I was desperately trying to avoid.
Ideally I would find a way of getting satellite imagery for each height map and using that as a detail texture, but there are all sorts of problems with that. Time period. Copyright. Alignment. The list goes on.
Any help gratefully accepted.