I am working on terrain rendering with elevation data by using SRTM. Does anyone have example program about bicubic/bilinear interpolation? I found some through google and vterrain website but they did not provide example C/C++ program.
Above is both bilinear / bicubic filter lookup, but for volume data. Should be easy to port to 2D.
But not sure if what i did here really is what people mean when saying ‘bicubic’. There should be better resources. I know there are at least some shadertoy examples, but probably that's about optimization and obscures the initial idea. What i did was to make tangents from neighboring voxel values, and interpolate them with smoothstep to get a curve instead a straight line:
To illustrate, get light blue / red lines from neighbor samples, transport them to sample values (dark blue and red), and interpolate both vectors for the 1D case. It's pretty simple.
@sword7 Just a small warning and note (from years of experience with height data sets taken from satellites), keep in mind that those datasets contain errors (not just noise - it might be completely invalid data - like altitude 65535 meters).
There are some very good filtered data sets like http://www.viewfinderpanoramas.org/ - but the resolution tends to be lower (3" … but has whole world), I think SRTM can be obtained up to 1" but not for whole world … also its precision is quite poor for most of Europe that is available at this resolution.
As for interpolation of data (and what we've used) - take samples from data, validate (i.e. min and max height - to throw off invalid samples) and push as a point set (at given x, y … height being value). Then we resampled it with a filter into 2D texture at discrete resolution.
The filter searched for N nearest points and used weighted average (weight being calculated based on distance of those points).
Why?
You will often need area that crosses borders between tiles (assuming your data set is tiled - which most likely is)
You may need area covering many tiles
It is possible you will have part of your data available at high resolution of 1" and part at resolution of 3"
Possibility of combining multiple data sets into one (thus possibility of fixing the errors)
Both of these cases will most likely require resampling of the dataset into new height maps
Results may look like:
Left: One of the datasets used (there is more different datasets used) - this one is 3" Middle: Mix of multiple datasets with radius based filter, it will still yield some invalid values Right: After additional filtering step (interpolation for missing values)
@joej Despite my inactivity on GameDev.net, I'm still not dead yet! Glad to see you're still active.
@Vilem Otte I now got it. Thanks. I got latest SRTM v3.0 global 1 arcsecond datasets (600 GB+) but it only cover 60 degrees from equator both hemispheres. I am now looking for elevation datasets above 60 degrees (both poles).