Playing with Heightmaps

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

Playing with Heightmaps

Post by HackaLittleBit »

Here a patch to handle heightmaps.
The reason for this patch is that I like to manipulate and enhance heightmaps with graphic editors
and before starting a game I like to prepare a scenario.
In the game are two places where you can play with heightmaps.
First place is 'Play heightmap'.
Second place is in the scenario editor.
Here you can load and save heightmaps at will.
Normally after creating a map I save it and edit it with a graphic editor.
After editing I load it again in ottd to see the results, make some changes and save it again.
Until I am happy.

Things that it should do:
Load 16 level height maps correct without loss of information.(old format)
Save 16 level height maps in without loss of information.(old format)
Load 256 level height maps correct without loss of information.
Save 256 level height maps correct without loss of information.
Scale maps properly.

It works as follows.
If user does not change the level with option 'maximum map height' the map will be loaded without scaling.
There is however a procedure 'FixSlopes' that fixes differences of more than 1 between tiles.
It will smoothen things out.
Heightmaps generated with ottd however should be loaded and saved without loss of data!

If user changes the level with option 'maximum map height' the scaling will be activated.
The program checks the level of the highest tile in the heightmap data.
When found it adjusts the maximum map height to that tile level.
The scaling itself tries if possible to raise or lower the highest peak to the desired 'maximum map height' level.
If user does not touch the 'maximum map height' option no scaling will take place.
After scaling an extra 5 tile levels are added to 'maximum map height' to facilitate some extra construction.
To add an extra 5 levels without scaling you simply save and reload the heightmap.

Attachment includes patch and 2 heightmaps for testing.
To see if maps are saved without loss of data you should keep in mind that the file header of the original file may be different.
.
Have fun.;-)
Attachments
HM1.png
(230.31 KiB) Downloaded 4 times
HM2.png
HM2.png (1.49 KiB) Viewed 2585 times
Heightmap_Loading_r27060_v1.1.patch
(4.8 KiB) Downloaded 88 times
Last edited by HackaLittleBit on 18 Nov 2014 15:22, edited 1 time in total.

User avatar
romazoon
Tycoon
Tycoon
Posts: 1291
Joined: 20 Jun 2010 23:16

Re: Playing with Heightmaps

Post by romazoon »

would your patch help solving problem when only the "coast tile" are too high (2-3-4 tiles high) ? it happens a lot when i try higher maxlevel height with some heightmap thatwere made with the help of Microdem and some geodatas, mountains seems perfect, but i don t manage to get the coast right.

User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

Re: Playing with Heightmaps

Post by HackaLittleBit »

No it is not the purpose of this patch.
You can however avoid that coast problem if you do not raise the height level more than the double of the original level.
Then save the heightmap and reload that saved map with again a higher level.

For each tile the amount to raise is calculated with the following formula.

newheight = 'old height tile' * 'disired height' / 'higest actual tile level'

example for tile on level 1;

'higest actual tile level' = 16
'disired height' = 31
'old height tile' = 1
newheight = 1 * 31 / 16 = 1,9375

result: newheight = 1; (rest behind the comma is disgarded)

'higest actual tile level' = 16
'disired height' = 33
'old height tile' = 1
newheight = 1 * 33 / 16 = 2,0625

result: newheight = 2; (rest behind the comma is disgarded)

You can see that if you take less than double, tiles that were 1 stay 1.
Hope this helps

There are many programs for manipulting images.
Irfanview for example has a filter to explode the image.
This has a great effect on the relief.
You have to experiment.
Attachments
Book1.xls
See calculations in worksheet
(29.5 KiB) Downloaded 92 times

User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

Re: Playing with Heightmaps

Post by HackaLittleBit »

Here an other way to solve the coast problem.
Download the heightmap HM1.png in the first post.
Put it in your heightmap folder.
Open it with OTTD and check the land area's in the north-west side of the map.
Most flat area is two tiles high.
We want 1 tile high. So...
Open HM1.png in Irfanview.
(If you download that program also install the plugins.)
Choose options 'Image', 'Palette', 'Edit palette'.
This will open a window 'palette entries'.
Read the instructions at the bottom of this window.
e.g. 'Click on color to select, double click to edit.'
Single click on the top left coler of 'palette entries'.
You will see it is color RGB(0,0,0).
That is sealevel.
Next color is RGB(1,1,1).
Those are tiles at level 1.
Next color is RGB(2,2,2).
Now you double click on that color and change the value in RGB(1,1,1) and click OK.
Now you have changed all level 2 tiles in level 1.
Save the file with different name in your heightmap folder and open it with OTTD.
You will see that that the coast levels have changed.

What you also can do is chnge a level in a very contrasting color (red fo example).
Save file and edit it with microsoft paint.

I combine this technique with microsoft paint.
There I use flood fill and spraying to get desired effects.
You can also use certain filters in Irfanview.
'Image', 'Effects', 'Explosion' is nice.

For Linux-freaks there must be other ways.;-)

To program all individual desires is hard and goes beyond scope of OTTD I think.
And..... It is fun to play (HackaLittleBit) with these hightmaps.
Success.

User avatar
romazoon
Tycoon
Tycoon
Posts: 1291
Joined: 20 Jun 2010 23:16

Re: Playing with Heightmaps

Post by romazoon »

thanks a lot for the tip :bow: , i gave it a fast try and it indeed works like a charm now :)

User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

Re: Playing with Heightmaps

Post by HackaLittleBit »

:D

Code cleanup.
Newer version of patch.
See first post.

Eddi
Tycoon
Tycoon
Posts: 7438
Joined: 17 Jan 2007 00:14

Re: Playing with Heightmaps

Post by Eddi »

honestly, from reading the description multiple times i still have no idea what this patch is meant to do, or how this differs from current behaviour.
You might not exactly be interested in Ferion, but if you are, have fun :)

User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

Re: Playing with Heightmaps

Post by HackaLittleBit »

Let me help you eddy.

'loss of information' == losing information.
in german: Informationsverlust.

http://lmgtfy.com/?q=course+in+english+reading
If you are able you could try the patch. ;-)

Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 11 guests