L3DT users' community
Large 3D terrain generator

Heightfield with negative "max Altitude"

Got a problem or need advice?

Heightfield with negative "max Altitude"

Postby HanoGames » Wed Feb 22, 2017 10:39 am

Hi, I'm actually working with bathymetry (ocean floor) files that due to it's nature have a altitude range below sealevel, so for example the minimum altitude would be -3000m and the maximum altitude would be -1000m

Now I'm facing the problem that the "maximum altitude" always resets to "-0.00" when I try to adjust the heightfields vertical range. I'm working with .hfz files if that helps anything. Am I doing anything wrong?

Thanks for your help! :)
HanoGames
New member
 
Posts: 3
Joined: Wed Feb 22, 2017 10:29 am

Re: Heightfield with negative "max Altitude"

Postby Aaron » Wed Feb 22, 2017 12:47 pm

Hi HanoGames,

Welcome to the forum and thank your for your question.

This is most curious. When I use the 'change vertical range' window, I can set the maximum to be negative:

ChangeVertRange.png
ChangeVertRange.png (20.14 KiB) Viewed 2933 times


The only thing I can think of that would reset the maximum altitude to 0 is if you changed the '% above sea-level' value.

Which values are you editing, exactly?

Best regards,
Aaron.
User avatar
Aaron
Site Admin
 
Posts: 3665
Joined: Sun Nov 20, 2005 2:41 pm
Location: Melbourne, Australia

Re: Heightfield with negative "max Altitude"

Postby HanoGames » Wed Feb 22, 2017 5:14 pm

Hi, the problem only occurred with 16.05, I've just upgraded to 16.11 and now I'm able to set negative values for "max altitude" too.

But I'm facing a new problem as you can see below:

Below is the vertical range of the original file, as it should be:
original.jpg
original.jpg (31.52 KiB) Viewed 2930 times


Then I have to resize (from something ~ 1200x1200 to 36000x36000 the heightfield to achive a higher resolution, and the vertical range changes for some reason to:
resized.jpg
resized.jpg (31.49 KiB) Viewed 2930 times


Finally, when I enter the max & min values of the original file again, the "Average Altitude" value changes:
newAR.jpg
newAR.jpg (31.18 KiB) Viewed 2930 times



The result is that in this example some underwater-mountains are ~700m lower than in the original file, is there a way to do this differently? Thanks for your fast support!
HanoGames
New member
 
Posts: 3
Joined: Wed Feb 22, 2017 10:29 am

Re: Heightfield with negative "max Altitude"

Postby Aaron » Thu Feb 23, 2017 12:11 pm

Hi HanoGames,

Thanks for the bug report. I've now been able to reproduce this, but have not yet devised a fix (working on it!)

The explanation for the fault is as follows:

When you resize a small heightfield to a very large one (of the order of 16k x 16k pixels or greater), the resizing operation copies the map data from an un-tiled map to a tiled map (tiling is necessary on large map sizes). In this copying process, it appears to drop the calculated min/max values that are stored with the map. Note that the actual pixel values are copied across OK, just the stored min/max values get corrupted. The effect of this fault is that the greyscale display in the 2D view will have the wrong shading (since the palette is determined from min & max), as will any images exported from the heightfield. I think 'proper' map files like HFZ should be unaffected, as they don't rely on the stored min/max values. The other place the min/max values are displayed are in the 'change vertical heightfield range' window, as you have most helpfully observed.

As for why only the 'max' value is getting corrupted here: I think the min & max are both getting re-set to zero, and then when a pixel value is copied across to the resized map, it will re-set the minimum value if it's smaller than 0 (guaranteed, wince all pixels are less than 0 here), but it won't re-set the maximum because no pixels are greater than 0 (hence max stays at default of 0). The same effect would be observed if you had a map that was entirely above sea-level, except that here the minimum would be getting set to zero, instead of the max. This shouldn't be too hard to track down, I hope...

Anyway, the reason the 'average altitude' value changes when you resize the map is because L3DT takes a shortcut in its calculation (averaging billions of pixel values is very slow), and instead calculates the average from the histogram (which is in turn calculated from sub-sampling the heightfield, and is really fast). Back in the depths of time, I seem to have only given the histogram 512 bins, so in your case the 6751m range implies a histogram bin width of ~12 metres. The difference between the average altitude in your first and second screenshots is, by remarkable coincidence, 12 metres also, which means this is a classic 'fencepost error' where the average has tipped out of one histogram bin into another (possibly due to a slight shift in which pixels are measured in the sub-sampling, which is going to happen when a map is resized). Anyhow, the quick-n-dirty fix here is to increase the number of histogram bins to improve the precision (will be 4096 in next version; 8x more precise). To be completely accurate, L3DT would have to actually calculate the average of all map pixels, which would be way slower than calculating an approximate average from a histogram sample. I'll have to have more of a thinker about that.

As for why the heights in the map change when you re-set the max value to the 'correct' altitude, this is because the re-scaling factors are calculated from the old & new min/max values. If the old max value is incorrect (i.e. 0, when it should be -723), then the scaling factor is going to be incorrect too, meaning the height values in the heightfield pixels will go all wrong.

Anyway, please stay tuned, I will post back here when I have a fix ready. Thanks again for the bug report.

Best regards,
Aaron.
User avatar
Aaron
Site Admin
 
Posts: 3665
Joined: Sun Nov 20, 2005 2:41 pm
Location: Melbourne, Australia

Re: Heightfield with negative "max Altitude"

Postby Aaron » Thu Feb 23, 2017 2:45 pm

Hi HanoGames,

The fix is now included in L3DT Pro 17.02 developmental build 2, which is on the Pro downloads page now (please consult purchase receipt e-mail for link). Thanks again for the bug report, and please let me know if you find any further problems.

Kind regards,
Aaron.
User avatar
Aaron
Site Admin
 
Posts: 3665
Joined: Sun Nov 20, 2005 2:41 pm
Location: Melbourne, Australia

Re: Heightfield with negative "max Altitude"

Postby HanoGames » Thu Feb 23, 2017 9:27 pm

Yes it's much more precise now, thanks for the quick fix! :)
HanoGames
New member
 
Posts: 3
Joined: Wed Feb 22, 2017 10:29 am


Return to Help and support

Who is online

Users browsing this forum: No registered users and 1 guest

cron