Perlin Noise Experiment

How I would use Perlin Noise is my life’s greatest mystery to me at the moment. I tried following along http://lodev.org/cgtutor/randomnoise.html and http://freespace.virgin.net/hugo.elias/models/m_perlin.htm to no avail. Here are the results from my .blend:




If you want to dissect the blend file, here it is:
perlin_noise_terrain.blend (575 KB)

If anyone could help me understand what is going on, I would highly appreciate it. For now I will try to understand how Perlin noise works.

Well, i had the same problem once :smiley:
Welcome!

For starters do you know what dot product is?

I can’t really see what is going on in your blend.
You should start at first with only one layer of noise…

This is what i came up with when the logic hit me:


import math
import random

class Noise:
    #Perlin noise
    #read some papers on how it works
    #I barely managed hash negative coords correctly
    def __init__(self, grid_size,SEED):
        self.grid_size = grid_size
        self.SEED = SEED
        self.perm_size = 256
        perm = list(range(self.perm_size))
        random.seed(self.SEED)
        
        random.shuffle(perm)
        perm += perm
        
        #random vector creation
        random_vectors = []        
        len_of_vectors = 16
        rounding = 4
        for x_vector in range(len_of_vectors):
           for y_vector in range(len_of_vectors):
                random_vectors.append((round(x_vector/(len_of_vectors-1)-0.5,rounding),round(y_vector/(len_of_vectors-1)-0.5,rounding)))
        random.shuffle(random_vectors)
                
        self.perm = perm
        self.random_vectors = random_vectors
        self.len_of_vectors = len_of_vectors


    def grid(self,n):
        return int(n/self.grid_size)
        
    def get_value(self,x,y):
        
        cx = (x/self.grid_size)
        cy = (y/self.grid_size)
        perm_size   =   self.perm_size
        
        
        def corner(corner_x,corner_y):
            
            px          =   int(cx)+corner_x
            py          =   int(cy)+corner_y
            
            if x<0      :   px -= 1
            if y<0      :   py -= 1
                        
            distX, distY = abs((cx)-px), abs((cy)-py)
            
            polyX = 1 - 6*distX**5 + 15*distX**4 - 10*distX**3
            polyY = 1 - 6*distY**5 + 15*distY**4 - 10*distY**3
            
            h_x,h_y = abs(px)%perm_size,abs(py)%perm_size
            
            hashed = self.perm[self.perm[h_x] + h_y]
            
            vector = self.random_vectors[hashed%self.len_of_vectors**2]
            
            scalar = ( ((cx)-px)*vector[0] +  ((cy)-py)*vector[1]  )


            return polyX * polyY * scalar
        
        return (corner(0, 0) + corner(1, 0) + corner(0, 1) + corner(1,1))  
    
    



It would be good if the framerate did not drop too much with this.And you could play it in firstperson with very little framerate drop.With twenty npcs at least that can avoid obstacles.I have played with a blend with dynamically loaded cube ground.It called blockeasyDemo which is on this link.What type of game are you planning to make?Some more people need to respond to this thread if they want this feature.I think it is worth giving a try.

I solved my problem a little bit since I tried applying the noise in 1 dimensions to form a 2-D landscape, like in Terraria:


Here you can see my placeholder player near the “shore” (the blue blocks are placeholders for water).


Here the 2-D landscape is in full view. The landscape is 256 blocks in length and has a noise frequency of 4, wavelength of 64, and a maximal amplitude of 32. The white rectangle is the player placeholder.


In this picture you can see a white line protruding from the player. It is a raycast that allows me to destroy blocks.

I’ll keep on experimenting to get the desired results for the meantime.

What is your framerate you get after playing the game after a while?The true test will be adding npc’s with animations to the videogame.To see if it is playable.

That looks like just broken chunks of one layer noise.
The chunks don’t match each other.

It is probably the hashing for the chunks…

In your inital example the scale was too random and you added to much noise layers…
If you would have had the chunk size bigger and added no layers, it would have looked like a landscape.