Question by 
               unsukgames · Jul 05, 2021 at 10:15 PM · 
                texturemeshperlin noise  
              
 
              Texture does not scale correctly on a mesh
Hey,
I'm working on a terrain generator using Perlin Noise. I already have the mesh but I want to apply to it a Perlin Noise function but it appears that it is not scaling correctly.
     public int xSize = 20;
     public int ySize = 20;
 
     public float scale = 10f;
 
     public int width = 256;
     public int height = 256;
 
     public float offsetX = 50f;
     public float offsetY = 50f;
    
  void Start()
     {
         offsetX = Random.Range(0f, 9999f);
         offsetY = Random.Range(0f, 9999f);
     }
 
     void Update()
     {
         Renderer renderer = GetComponent<MeshRenderer>();
         renderer.material.mainTexture = GenerateTexture();
     }
 
     Texture2D GenerateTexture()
     {
         Texture2D texture = new Texture2D(width, height);
 
         for(int x = 0; x < width; x++)
         {
             for(int y = 0; y < height;  y++)
             {
                 Color color =  CalculateColor(x, y);
                 texture.SetPixel(x, y, color);
             }
         }
 
         texture.Apply();
         return texture;
     }   
 
     Color CalculateColor(int x, int y)
     {
         float xCoord = (float)x / width * scale + offsetX;
         float yCoord = (float)y / height * scale + offsetY;
 
         float sample = Mathf.PerlinNoise(xCoord, yCoord);
         return new Color(sample, sample, sample);
     }
 
 
               The code is not mine, I tried to make it work on my program.

If I change the offset the color changes too but it does not scale correctly.
 
                 
                unknown.png 
                (51.3 kB) 
               
 
              
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Texture Not Showing On Mesh 0 Answers
Having trouble with a texture not showing on a generated mesh. 1 Answer
Material is not stretching on Meshes 1 Answer
Weird artefact while rotating mesh uvs 0 Answers