Making Some Noise

Posted by SkidRunner on Oct. 16, 2013, 11:57 a.m.

So it has been some time since I have created a post on 64D but I am back. Last night I decided that I wanted to start creating a world that I have never seen, dreamt or even thought about. I want to create a game from this world that also I did not design. This sounds a lot harder in concept then it really is. The first thing that came to mind is that to have a game world you need some ground to walk on which isn’t that hard to do using Perlin Noise I should be able to create variations in the terrain to my liking. So I needed to get a basic understanding of how Perlin Noise works.

Subdivide the height map into x chunks generate a random number from 0.0 to 1.0 for each creating a new height map (Keep doing this until your chunks are the size of a pixel). Stack the images together by finding the average value across all images for each pixel. Blur the stacked image height map values until there is a smooth transition between each value on the height map. Expand all values on the height map so the lowest value is 0.0 and the highest value is 1.0.

So in a nut shell my process is:

1. Subdivide

2. Stack

3. Smooth

4. Expand

This is just sudo code my cross of VB and Crap[:)]

Width = 256
Height = 256
Scale = 2
NoiseImages() As Image

'Create noise layers
For Each Image In NoiseImages
    RecWidth = Width / Scale
    RecHeight = Height / Scale
    For X = 0 To Scale
        For Y = 0 To Scale
            RecX = X * RecWidth
            RecY = Y * RecHeight
            Image.DrawRectangle(RecX, RecY, RecWidth, RecHeight, Random)
        Next
    Next
    Image = CreateNoise(Width, Height, Scale)
    Scale = Scale * 2
Loop

'Create a average value noise map
For X = 0 To Width
    For Y = 0 To Height
        Value = 0
        Count = 0
        For Each Image In NoiseImages
            Value = Value + Image.GetPixcle(X, Y)
            Count = Count + 1
        Loop
        LayeredNoiseImage.SetPixcel(X, Y, Value / Count)
    Next
Next

'Get the min and max of the average value noise map
MaxValue = 0
MinValue = 1
For X = 0 To Width
    For Y = 0 To Height
        Value = LayeredNoiseImage.GetPixcle(X, Y)
        If Value > MaxValue Then MaxValue = Value
        If Value < MinValue Then MinValue = Value
    Next
Next

'Set the average value noise map to extend from min to max
For X = 0 To Width
    For Y = 0 To Height
        Value = LayeredNoiseImage.GetPixcle(X, Y)
        Value = (Value - MinValue) * (1 / (MaxValue - MinValue))
        LayeredNoiseImage.SetPixcel(X, Y, Value)
    Next
Next

'Create a smooth value noise map
For Count = 0 To 16
    For X = 0 To Width
        For Y = 0 To Height
            'Centre
            Value = LayeredNoiseImage.GetPixcle(X, Y)
            'North
            Value = Value + LayeredNoiseImage.GetPixcle(X - 1, Y)
            'South
            Value = Value + LayeredNoiseImage.GetPixcle(X + 1, Y)
            'West
            Value = Value + LayeredNoiseImage.GetPixcle(X, Y - 1)
            'East
            Value = Value + LayeredNoiseImage.GetPixcle(X, Y + 1)
            'North West
            Value = Value + LayeredNoiseImage.GetPixcle(X - 1, Y - 1)
            'North East
            Value = Value + LayeredNoiseImage.GetPixcle(X - 1, Y + 1)
            'South West
            Value = Value + LayeredNoiseImage.GetPixcle(X + 1, Y - 1)
            'South East
            Value = Value + LayeredNoiseImage.GetPixcle(X + 1, Y + 1)
            smoothNoiseImage.SetPixcel(X, Y, Value / 9)
        Next
    Next
Next

The final result is a nice set of images

After working through all this I noticed that the end results still aren’t exactly what I was looking for I don’t want to run around a hilly terrain I want mountains and rivers so I will create some variations of my noise generator and see if I can create something nicer

Comments

JuurianChi 11 years, 10 months ago

For some reason, this makes me think about Fallout New Vegas.

F1ak3r 11 years, 10 months ago

Those VB titlecase keywords make me uncomfortable.

SkidRunner 11 years, 10 months ago

Quote: F1ak3r
Those VB titlecase keywords make me uncomfortable.
VB is so verbose that the only purpose for it in my opinion is sudo code… at least I didn’t wright my sudo code in COBOL. If title case makes you uncomfortable full caps might have given you a heart attack… [;)]

I am just messing with you the application is written in Java so I know your feeling.

Alert Games 11 years, 10 months ago

Quote:
full caps might have given you a heart attack…
FULL CAPS??? Reminds me of the old days of HTML 4…. *shivers*

JuurianChi 11 years, 10 months ago

WE MUST NEVER GO BACK

Moikle 11 years, 10 months ago

I love perlin noise so much

you should use bilinear/trilinear imterpolation on those noise octaves before you merge them together