Mathf.PerlinNoise randomly started glitching

solved, it was my shader :confused: or that I compressed the resolution and expanded it

Hi, it’s the 3rd time that it happens to me, I work on a project that uses Mathf.PerlinNoise, I change something in my code, and then I get this:


THERE ARE LINES!
it becomes glithy, there are lines all over the place, but why?

this is the code:

//I generate it with:
private short[][] generateNoisLayer(short[][] layer, float scale,int min, int max) {

        short[][] tmpLayer = copyMat(layer);

        float seedx = Random.Range(0, 0);
        float seedy = Random.Range(-0, 0);
        //the values are ajusted so the max value will be the largest possible outcome
        max = max - min;

        for (int x = 0; x < 1920; x++)
        {
            for (int y = 0; y < 1080; y++)
            {
                tmpLayer[x][y] = (short)(min + (short)(Mathf.PerlinNoise(x / scale + seedx, y / scale + seedy) * max));
            }
        }

        return tmpLayer;
    }

//I call the method with:
   
 debuglayer =
        debuglayer = generateNoisLayer(elevation, 5.5f, -100, 100);



I draw the result with:

    private Texture2D getMapDebug(short[][] map, float largestVal)
    {
        Texture2D tmp = new Texture2D(1920, 1080);
        for (int x = 0; x < 1920; x++)
        {
            for (int y = 0; y < 1080; y++)
            {
                float normalized = (map[x][y] - (-largestVal)) / (largestVal - (-largestVal));
                Color tmpC = new Color(normalized, normalized, normalized);
                tmp.SetPixel(x, y, tmpC);
            }
        }
        worldObj.GetComponent<Renderer>().material.SetTexture("_mapTexture", tmp);
        tmp.Apply();
        return tmp;
    }

for the testing I set the seeds to 0, so I don’t use large floats, I tried setting the seeds to anything that you can think about, I tried restarting the PC. things that worked few hours ago, now give me glitches…

float to short conversion introduces data loss
try to generate noise into texture without any type conversions
i believe it will be smooth

It’s not it, even if I generate it with much larger numbers where the conversion won’t matter at all, I see the same peoblem

I generated with

  • debuglayer = generateNoisLayer(elevation, 5.5f, -1000, 1000);

and it gave the same problem, so it can’t be the conversion
here is what I get with the the command above

SOLVED!!! IT WAS MY FUCKING STUPID IDIOT SHADER that I made!! nothing is wrong with the noise!!!

2 Likes