# Why is my perlin-noise generated texture a uniform grey?

I'm following Brackeys' tutorial for perlin noise and i'm at the point where he's just done the offset thing but this whole time all that i'm seeing in my project is a plain gray square, no matter what settings i change. Here's my code:

using UnityEngine;

public class PerlinNoise : MonoBehaviour
{
public int width = 256;
public int height = 256;

public float scale = 20f;

public float offsetX = 100f;
public float offsetY = 100f;

void Update ()
{
Renderer renderer = GetComponent<Renderer>();
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(x, y);
return new Color(sample, sample, sample);
}
}


Here's the result i get:

and here's the settings in the editor:

In the function CalculateColor, you calculate values for the variables xCoord and yCoord, but then you never use them. You are using the pixel coordinates x and y instead. The result is that you are generating perlin noise on integer values. Due to the way Perlin noise works, integer values will always give you the same results.

float sample = Mathf.PerlinNoise(xCoord, yCoord);

By the way, Perlin noise is actually obsolete. Over 20 years ago, Ken Perlin himself created Simplex Noise as a drop-in replacement which not only has less weird quirks and artifacts (including this one) but is also faster to compute. The reason why it didn't replace Perlin noise already is because Simplex noise used to be patented. But the patent ran out 2 years ago. So nowadays Simplex noise is almost always the better choice. You can find a simplex noise implementation in the Unity math library. If you want to give it a try, add using Unity.Mathematics; at the top of your script, and try this instead:
float sample = noise.snoise(new float2(xCoord, yCoord)) * 0.5f + 0.5f;

(the * 0.5f + 0.5f part is required because noise.snoise generates noise in the range of -1 to 1 instead of 0 to 1 like Mathf.PerlinNoise).