[Idea and Method] Improved heightmap generation

Got an idea for OpenTTD? Post it here!

Moderator: OpenTTD Developers

User avatar
Zephyris
Tycoon
Tycoon
Posts: 2831
Joined: 16 May 2007 16:59

[Idea and Method] Improved heightmap generation

Post by Zephyris »

Hi all!

So one thing which bugs me about the terrain generation in OpenTTD is that there is no long distance variation... the maps feel very bland with few landmarks. I think the most fundamental cause of this is the terrain hillyness is uniform across all terrain, you don't get ranges of hills and mountains don't feel like mountains. While I can't program I can do image manipulation, and given the terrain generation starts life as perlin noise (or so I assume) all the following image processing steps I am going to talk about should be directly analagous.

1. Perlin noise.
tmp.png
tmp.png (250.54 KiB) Viewed 5984 times
Bland, boring scaleless. The current terrain generator essentially stops here.

2. Curves.
Curves Demp.png
Curves Demp.png (22.95 KiB) Viewed 5984 times
Apply a curves intensity modification.
Modification of this curve will give different terrain properties, you just need to shift the control points.
Shifting the second point horizontally: Controls quantity of water
Shifting the third point vertically: Controls the hillyness of hilly terrain
Shifting the fourth point horizontally: Controls the quantity and extensiveness of mountains
Shifting the fifth point vertically: Controls the height of mountainous terrain

3. Modified noise.
tmp2.png
tmp2.png (148.45 KiB) Viewed 5984 times
More varied; now with lakes and mountain ranges!
User avatar
Zephyris
Tycoon
Tycoon
Posts: 2831
Joined: 16 May 2007 16:59

Re: [Idea and Method] Improved heightmap generation

Post by Zephyris »

4. Final terrain.
3dplotsmall.png
3dplotsmall.png (155.15 KiB) Viewed 5968 times
I think this is a lot more interesting (at very little cost) than the current terrain generation.

Top points of this generation method:
* Simple extension of existing code:
* Could simply rescale existing terrain...
* ... or be a new implementation using 255 height steps, rescaling, and application via heightmap code.
* Improves gameplay:
* Adds additional obstacles to construction...
* ... while opening up new passes/regions of flat land for constrution.
* Feels more interesting to play:
* Looks and feels more like real terrain.
Eddi
Tycoon
Tycoon
Posts: 7578
Joined: 17 Jan 2007 00:14

Re: [Idea and Method] Improved heightmap generation

Post by Eddi »

if you can extract the mathematical representation of the image transformation, i'm sure it should be possible to port that to tgp [the landscape generator]
You might not exactly be interested in Ferion, but if you are, have fun :)
User avatar
Gremnon
Tycoon
Tycoon
Posts: 1517
Joined: 16 Sep 2005 12:23
Skype: the_gremnon
Location: /home
Contact:

Re: [Idea and Method] Improved heightmap generation

Post by Gremnon »

I like this idea, the only downside I see to it is OpenTTD's somewhat limited means of defining heights - limited by way of the fact that you cannot have sharp hills and gentle hills, it's all done in steps.
While I understand that's never going to be easy to change, it does suggest that at least a partial implementation of cliffs could help. Partial, because until the unlikely event of viewport rotation happens, only the frontal two views could ever really be done properly.

I'd like to see this ingame though. Can I ask though, that image of the final product - what's that generated with?
User avatar
FHS
Director
Director
Posts: 577
Joined: 18 Apr 2009 17:17
Location: Basel, CH

Re: [Idea and Method] Improved heightmap generation

Post by FHS »

What you need for more interesting terrain would be the MoreHeights patch and a rewritten TGP.
User avatar
Zephyris
Tycoon
Tycoon
Posts: 2831
Joined: 16 May 2007 16:59

Re: [Idea and Method] Improved heightmap generation

Post by Zephyris »

For input perlin noise values of 0-255:

Code: Select all

x=perlin noise value at a point
For resulting heightmap values of 0-255:

Code: Select all

y=resulting terrain height at that point

Code: Select all

control point 0: (0, 0)
control point 1: (x1, 0)
control point 1: (x2, y2)
control point 1: (255, y3)
Heightmapscalingsimple_smallwhite.png
Heightmapscalingsimple_smallwhite.png (3.89 KiB) Viewed 5940 times

Code: Select all

if (x<=x1) {
	y=0;
} else if (x>x1 && x=x2) {
	y=y1+(x-x1)*(y2-y1)/(x2-x1);
} else {
	y=y2+(x-x2)*(y3-y2)/(x3-x2);
}
Water quantity:
x1=0 to 192
almost no water to approx 3/4 water

Hill height:
y2=32 to 192
hills of approx 4 to 12 in height

Proportion of mountains:
x2=x1 to 224
all mountains to very few mountains

Height of mountains
y3=y2 to 255
mountains of hill height to maximum height

To convert the typical values to other scales (eg. y values to OpenTTD heights 0-15) simply scale 0-255 for all corresponding variables (in this case y2, y3) to the new range.
Gremnon wrote:Can I ask though, that image of the final product - what's that generated with?
That was made with the interactive surface plotter (essentially a heightmap plot) with a custom surface texture (blue/green according to height) in ImageJ. It is a Java image editing program designed for scientific (particualarly microscopy) image analysis, manipulation and quantification. I like it because it has a very powerful macro/scripting language for image editing and analysis.
Gremnon wrote:I'd like to see this ingame though.
See attachment for an in-game demonstration of the above heightmap...
Attachments
InTTD.png
User avatar
CommanderZ
Tycoon
Tycoon
Posts: 1872
Joined: 07 Apr 2008 18:29
Location: Czech Republic
Contact:

Re: [Idea and Method] Improved heightmap generation

Post by CommanderZ »

Eddi wrote:if you can extract the mathematical representation of the image transformation, i'm sure it should be possible to port that to tgp [the landscape generator]
The mathematical basis of such transformation is fairly trivial - it is like 3 lines of code (as long as you don't need fancy splines to define the transformation), you just have to map the original values onto transformed values.

Wait a few days, there will be will a bigger gun for you to play with then.
Dwachs
Engineer
Engineer
Posts: 46
Joined: 02 Jun 2005 07:28

Re: [Idea and Method] Improved heightmap generation

Post by Dwachs »

I do not see, how this method can generate long distance variation. All it does is apply a different scaling to the height levels. It does not change the location of hills/mountains. It only modifies their shape.
User avatar
Zephyris
Tycoon
Tycoon
Posts: 2831
Joined: 16 May 2007 16:59

Re: [Idea and Method] Improved heightmap generation

Post by Zephyris »

It exaggerates the effect of rare (very bright/high) regions on the heightmap so "feels" more varied. Mathematically (eg. fourier analysis) will still show the same minimum frequency cutoff as the original heightmap.
peter1138
OpenTTD Developer
OpenTTD Developer
Posts: 1646
Joined: 30 Mar 2005 09:43

Re: [Idea and Method] Improved heightmap generation

Post by peter1138 »

Here is an implementation for the TGP landscape generator, using a fixed complex curve map.
Attachments
heightcurves.diff
(1.6 KiB) Downloaded 141 times
He's like, some kind of OpenTTD developer.
User avatar
XeryusTC
Tycoon
Tycoon
Posts: 15415
Joined: 02 May 2005 11:05
Skype: XeryusTC
Location: localhost

Re: [Idea and Method] Improved heightmap generation

Post by XeryusTC »

The mountains are quite sudden on this method, I would like it more if they could be kept more fluently.
Don't panic - My YouTube channel - Follow me on twitter (@XeryusTC) - Play Tribes: Ascend - Tired of Dropbox? Try SpiderOak (use this link and we both get 1GB extra space)
Image
OpenTTD: manual #openttdcoop: blog | wiki | public server | NewGRF pack | DevZone
Image Image Image Image Image Image Image
User avatar
Gremnon
Tycoon
Tycoon
Posts: 1517
Joined: 16 Sep 2005 12:23
Skype: the_gremnon
Location: /home
Contact:

Re: [Idea and Method] Improved heightmap generation

Post by Gremnon »

I like it better this way. In conjunction with More Height Levels, this could provide some interesting maps.
User avatar
Zephyris
Tycoon
Tycoon
Posts: 2831
Joined: 16 May 2007 16:59

Re: [Idea and Method] Improved heightmap generation

Post by Zephyris »

The mountains are quite sudden on this method, I would like it more if they could be kept more fluently.
This is a matter of tweaking the curves, if you increase the height of the hills the mountains will be less "sudden". A hill height of 128 and a proportion of mountains of (255-x1)/2 will give you vanilla OpenTTD no sharp start to mountains.
Here is an implementation for the TGP landscape generator, using a fixed complex curve map.
Excellent, now just have to get OpenTTD compiling under my new win7 install :s
User avatar
ChillCore
Tycoon
Tycoon
Posts: 2666
Joined: 04 Oct 2008 23:05
Location: Lost in spaces

Re: [Idea and Method] Improved heightmap generation

Post by ChillCore »

Very nice idea Zephyris.
I tried this with the more height levels patch and so far the generated terrain looks amazing.

petern,
Trunk please.
If not can I steal your code please ?
-- .- -.-- / - .... . / ..-. --- .-. -.-. . / -... . / .-- .. - .... / -.-- --- ..- .-.-.-
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.

Playing with my patchpack? Ask questions on usage and report bugs in the correct thread first, please.
All included patches have been modified and are no longer 100% original.
User avatar
Zephyris
Tycoon
Tycoon
Posts: 2831
Joined: 16 May 2007 16:59

Re: [Idea and Method] Improved heightmap generation

Post by Zephyris »

With some curve preset values for the different standard terrain options (ie. sea level, flatness, [roughness is unchanged]) would this have a chance for trunk?
peter1138
OpenTTD Developer
OpenTTD Developer
Posts: 1646
Joined: 30 Mar 2005 09:43

Re: [Idea and Method] Improved heightmap generation

Post by peter1138 »

Possibly. This new version has four curves which are randomly selected and applied in a non-linear manner across the map, providing a boost of variety across the map. It deviates from your original curve 'template' a bit.

Some sample screenshots of maps produced:

http://fuzzle.org/~petern/ottd/variety2.png
http://fuzzle.org/~petern/ottd/variety3.png
http://fuzzle.org/~petern/ottd/variety4.png
http://fuzzle.org/~petern/ottd/variety5.png
Attachments
heightcurves2.diff
(7.09 KiB) Downloaded 120 times
He's like, some kind of OpenTTD developer.
User avatar
FHS
Director
Director
Posts: 577
Joined: 18 Apr 2009 17:17
Location: Basel, CH

Re: [Idea and Method] Improved heightmap generation

Post by FHS »

Lookin great, now to find a way to prevent towns being built on unsuitable locations and make smoother coast lines.
User avatar
Zephyris
Tycoon
Tycoon
Posts: 2831
Joined: 16 May 2007 16:59

Re: [Idea and Method] Improved heightmap generation

Post by Zephyris »

I think that looks really good, esp. variety2.png, though that may be because the terrain can more clearly be seen.
User avatar
ChillCore
Tycoon
Tycoon
Posts: 2666
Joined: 04 Oct 2008 23:05
Location: Lost in spaces

Re: [Idea and Method] Improved heightmap generation

Post by ChillCore »

petern.
Could it be that STR_TERRAIN_TYPE_MIXED slipped in trunk by accident?
I did not see it being used other than in v2?

Offcourse from v2 (and trunk now) it does not work with the more height levels patch enabled.
(Terrain gets clipped at level 16 if I apply variation, I think I need to add a swith somewhere,
but that discussion does not belong here.)
-- .- -.-- / - .... . / ..-. --- .-. -.-. . / -... . / .-- .. - .... / -.-- --- ..- .-.-.-
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.

Playing with my patchpack? Ask questions on usage and report bugs in the correct thread first, please.
All included patches have been modified and are no longer 100% original.
Post Reply

Return to “OpenTTD Suggestions”

Who is online

Users browsing this forum: No registered users and 3 guests