Problem making cell noise

Hey there,

I am having some struggles making some cell noise, and i really have no clue what is going on, any improvements on my code are always welcome.

my problem is is that a certain part of the texture is being coppied in x en y direction:

Also any feedback on my thread skills are welcome(this is my second one)

using UnityEngine;
using System.Collections;

public static class Noise {

    public static float[,] GenerateNoiseMap(int mapWidth, int mapHeight, int seed, float scale, int octaves, float persistance, float lacunarity, Vector2 offset) {
        float[,] noiseMap = new float[mapWidth,mapHeight];

        System.Random prng = new System.Random (seed);
        Vector2[] octaveOffsets = new Vector2[octaves];
        for (int i = 0; i < octaves; i++) {
            float offsetX = prng.Next (-100000, 100000) + offset.x;
            float offsetY = prng.Next (-100000, 100000) + offset.y;
            octaveOffsets [i] = new Vector2 (offsetX, offsetY);
        }

        if (scale <= 0) {
            scale = 0.0001f;
        }

        float maxNoiseHeight = float.MinValue;
        float minNoiseHeight = float.MaxValue;

        float halfWidth = mapWidth / 2f;
        float halfHeight = mapHeight / 2f;


        for (int y = 0; y < mapHeight; y++) {
            for (int x = 0; x < mapWidth; x++) {
  
                float amplitude = 1;
                float frequency = 1;
                float noiseHeight = 0;

                for (int i = 0; i < octaves; i++) {
                    float sampleX = (x-halfWidth) / scale * frequency + octaveOffsets[i].x;
                    float sampleY = (y-halfHeight) / scale * frequency + octaveOffsets[i].y;

                    float perlinValue = Worley.worleyNoise (sampleX, sampleY, 2) * 2 - 1;
                    noiseHeight += perlinValue * amplitude;

                    amplitude *= persistance;
                    frequency *= lacunarity;
                }

                if (noiseHeight > maxNoiseHeight) {
                    maxNoiseHeight = noiseHeight;
                } else if (noiseHeight < minNoiseHeight) {
                    minNoiseHeight = noiseHeight;
                }
                noiseMap [x, y] = noiseHeight;
            }
        }

        for (int y = 0; y < mapHeight; y++) {
            for (int x = 0; x < mapWidth; x++) {
                noiseMap [x, y] = Mathf.InverseLerp (minNoiseHeight, maxNoiseHeight, noiseMap [x, y]);
            }
        }

        return noiseMap;
    }

}
using UnityEngine;
using System.Collections;

public class MapGenerator {

    public int mapWidth;
    public int mapHeight;
    public float noiseScale;

    [Range(0,8)]
    public int octaves;
    [Range(0,1)]
    public float persistance;
    public float lacunarity;

    public int seed;
    public Vector2 offset;

    public float[,] GenerateMap() {
        float[,] noiseMap = Noise.GenerateNoiseMap (mapWidth, mapHeight, seed, noiseScale, octaves, persistance, lacunarity, offset);
        return noiseMap;
    }

    void OnValidate() {
        if (mapWidth < 1) {
            mapWidth = 1;
        }
        if (mapHeight < 1) {
            mapHeight = 1;
        }
        if (lacunarity < 1) {
            lacunarity = 1;
        }
        if (octaves < 1) {
            octaves = 1;
        }
    }

}
using System;
using System.Collections.Generic;
using UnityEngine;

public static class Worley {
    public static float worleyNoise(float x, float y, int seed)
    {

        //correct
        int xBox = Mathf.FloorToInt(x);
        int yBox = Mathf.FloorToInt(y);

        Vector2[] points = new Vector2[9];  
  


        for (int xs = 0; xs < 3; xs++)
        {
            for (int ys = 0; ys < 3; ys++)
            {
                System.Random xr = new System.Random(unint(xBox + xs - 1));


                float xPos = (xr.Next(0, 1000) / 1000) + xBox + xs - 1;

                System.Random yr = new System.Random(unint(yBox + ys - 1));
          
                float yPos = (yr.Next(0, 1000) / 1000) + yBox + ys - 1;

          
                points[xs + ys] = new Vector2(xPos, yPos);
            }
        }
  
  


        //klopt

        float lowestDist = 10000000;  
  
        for (int i = 0; i < 9; i++)
        {
            float dist = EuclidianDistanceFunc(new Vector2(x,y) , points[i]);

            if (dist < lowestDist)
            {
                lowestDist = dist;
            }
      
        }

  




  

        return lowestDist;
    }


    public static float EuclidianDistanceFunc(Vector2 p1, Vector2 p2)
    {
        return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);
    }

    public static float ManhattanDistanceFunc(Vector2 p1, Vector2 p2)
    {
        return Mathf.Abs(p1.x - p2.x) + Mathf.Abs(p1.y - p2.y);
    }

    public static float ChebyshevDistanceFunc(Vector2 p1, Vector2 p2)
    {
        Vector3 diff = p1 - p2;
        return Mathf.Max(Mathf.Max(Mathf.Abs(diff.x), Mathf.Abs(diff.y)));
    }

    private static int unint(int lastValue)
    {
        System.Random r = new System.Random(lastValue);

        for (int i = 0; i < r.Next(0,10); i++)
        {
            r.Next(0,10);
        }

  


        return r.Next(0,1000) / 1000;
    }


}
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(Mapper))]
[CanEditMultipleObjects]
public class Mapper_Editor : Editor {

    public override void OnInspectorGUI()
    {
        Mapper mapper = (Mapper) target;

        base.OnInspectorGUI();
        if (GUILayout.Button("Generate"))
        {
            mapper.generate();
        }
    }
}
using UnityEngine;
using System.Collections;

public class MapDisplay : MonoBehaviour {

    public Renderer textureRender;

    public void DrawNoiseMap(float[,] noiseMap, Gradient colors) {
        int width = noiseMap.GetLength (0);
        int height = noiseMap.GetLength (1);

        Texture2D texture = new Texture2D (width, height);

        Color[] colourMap = new Color[width * height];
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
          
                colourMap[y * width + x] = colors.Evaluate(noiseMap[x,y]) ;
            }
        }
        texture.SetPixels (colourMap);
        texture.Apply ();

        textureRender.sharedMaterial.mainTexture = texture;
        textureRender.transform.localScale = new Vector3 (width, 1, height);
    }
 
}
using UnityEngine;
using System.Collections.Generic;

[ExecuteInEditMode]
public class Mapper : MonoBehaviour {
    public int mapWidth = 100;
    public int mapHeight = 100;
    public float scale = 1;
    public int seed;
    public Vector2 offset;
 
    public Gradient gradient;
    public Layer[] layers;

 

    public void generate()
    {
  
        float[,] uitkomst = new float[mapWidth,mapHeight];
        for (int i = 0; i < layers.Length; i++)
        {
            MapGenerator mg = new MapGenerator();
            mg.mapWidth = mapWidth;
            mg.mapHeight = mapHeight;
            mg.noiseScale = scale;
            mg.octaves = layers[i].octaves;
            mg.persistance = layers[i].persistance;
            mg.lacunarity = layers[i].lacunarity;
            mg.seed = seed;
            mg.offset = offset;
      
            float[,] values = Noise.GenerateNoiseMap(mapWidth, mapHeight, seed, scale, layers[i].octaves, layers[i].persistance, layers[i].lacunarity, offset);
      




            for (int x = 0; x < mapWidth; x++)
            {

                for (int y = 0; y < mapHeight; y++)
                {
                    if (layers[i].filter == Layer.Filters.Abs)
                    {
                  
                        values[x, y] = Mathf.Abs(values[x, y] / 2 - 1);

                  
                    } else if (layers[i].filter == Layer.Filters.Round)
                    {
                        values[x, y] = Mathf.RoundToInt(values[x, y]);
                    }

                    if (layers[i].invert)
                    {
                        values[x, y] = -values[x, y];
                    }

                    if (layers[i].mixMode == Layer.MixMode.add)
                    {
                        uitkomst[x, y] += values[x, y];
                    }
                    else if(layers[i].mixMode == Layer.MixMode.average)
                    {
                        uitkomst[x, y] = (uitkomst[x, y] + values[x, y]) / 2;
                    }
                    else if (layers[i].mixMode == Layer.MixMode.devide)
                    {
                        uitkomst[x, y] /= values[x, y];
                    }
                    else if (layers[i].mixMode == Layer.MixMode.multiply)
                    {
                        uitkomst[x, y] *= values[x, y];
                    }
                    else if (layers[i].mixMode == Layer.MixMode.subtract)
                    {
                        uitkomst[x, y] -= values[x, y];
                    }
                    else
                    {

                    }
















                }
          
            }

      
        }
        float maxVal = 0;
        float minVal = 0;

        for (int x = 0; x < mapWidth; x++)
        {
            for (int y = 0; y < mapHeight; y++)
            {
                if (uitkomst[x,y] < minVal)
                {
                    minVal = uitkomst[x, y];
                }

                if (uitkomst[x,y] > maxVal)
                {
                    maxVal = uitkomst[x, y];
                }
            }
        }

        for (int x = 0; x < mapWidth; x++)
        {
            for (int y = 0; y < mapHeight; y++)
            {
                uitkomst[x, y] = Mathf.InverseLerp(minVal, maxVal, uitkomst[x,y]);
            }
        }

  

        MapDisplay display = GetComponent<MapDisplay>();
        display.DrawNoiseMap(uitkomst, gradient);
    }

}

[System.Serializable]
public class Layer
{
    [Range(1, 8)]
    public int octaves;
    [Range(0, 1)]
    public float persistance;

    public float lacunarity;
    public bool invert ;
    public enum Filters { none, Abs, Round};
    public Filters filter;
    public enum MixMode { add, subtract, multiply, devide, average, none};
    public MixMode mixMode;
}

I am using this tutorial for creating the noise AFTbit. I am not using the given code because i have not learnt all the fancy stuf with the lcg stuff and the uint’s etc

3278403–253798–worley.unitypackage (20.1 KB)

I can’t see anything obvious wrong with it - it’s probably better to post your whole project (the assets/projectSettings folders) and I can try it on my own PC.

I added the unity package of my entire scene for you :), thanks for helping btw. I already made a few changes which did make it look more like actual worley noise, but it still was repeating. I have uploaded a image with the new look

I’ve had a look but can’t figure it out, there seems to be a problem with your Worley.cs file when it generates random numbers. Because you’re not factoring in the x/y values the random values are always the same. It would probably be worth trying to copy the example you gave from https://aftbit.com/cell-noise-2 more closely until you get something working.

I already tried it, but a lot of things dont work, for example the Func<Vector3, Vector3, float> at the start. And i dont really know what that even is. Ill give a different way a try

That tutorial is absolutely terrible. Avoid it like the plague.

Want to learn noise that just works and makes sense?

http://catlikecoding.com/unity/tutorials/

and go down to the noise section.

Jasper flick, the guy who runs that, does the best non-video tutorials available hands down and youd be wise to learn all from him.

I looked there multiple times already, it doesnt have a tutorial on worley noise tho, which is what im trying to make…
if you have any other sources for a tutorial on worley(worley, cell or voronoi are all the same) noise i’d be happy to give it a try