- Home /
 
 
               Question by 
               Tatskaari · Jan 22, 2013 at 10:58 PM · 
                generationperlin noisenoiselandscapeperlin  
              
 
              Perlin noise problem
I have been trying to implement a perlin noise genertator however I can't seam to get it to work. Can anybody tell me what I'm doing wrong? It generates ridges rather than nice hills. public class PerlinV2 {
 private int seed;
 private int cellWidth;
 
 public PerlinV2(int seed, int width){
     this.seed = seed;
     this.cellWidth = width;
 } 
 
 public Vector2 getGrad(int x, int y){
     Random.seed = (x+y)*seed;
     Vector2 vec = new Vector2(Random.insideUnitCircle);
     return vec;
 }
 
 public float calculateForPoint(int x, int y){
     int cellx = (int)Mathf.Floor(x/cellWidth);
     int celly = (int)Mathf.Floor(y/cellWidth);
     
     float relx = (float)(x % cellWidth)/cellWidth;
     float rely = (float)(y % cellWidth)/cellWidth;
     
     float s,t,u,v;
     s = dot(getGrad(x,y), new Vector2(relx, rely));
     t = dot(getGrad(x+1, y), new Vector2(relx-1, rely));
     u = dot(getGrad(x,y+1), new Vector2(relx, rely-1));
     v = dot(getGrad(x+1,y+1), new Vector2(relx-1, rely-1));
     return lerp(lerp(s,t,relx),lerp (u,v,relx),rely);
 }
 private float dot(Vector2 a, Vector2 b){
     return a.x * b.x + a.y * b.y;
 }
 private float smooth(float n){
     return 3*n*n - 2*n*n*n;
 }
 private float lerp(float a, float b, float x){
     return a + x*(b-a);
 }
 
               }  
               Comment
              
 
               
              Genertators make me hungry. :)
Sadly I can't be of any help at math. I can barely add half the time.
Your answer