void MakeTexture()
    {
        if (useSeed)
        {
            NoiseS3D.seed = seed;
        }

        if (noiseTex)
        {
            Destroy(noiseTex);
        }

        if (UseOctaves)
        {
            NoiseS3D.octaves = octaves;
        }
        else
        {
            NoiseS3D.octaves = 1;
        }

        noiseTex = NoiseS3D.GetNoiseRenderTexture(Screen.width, Screen.height, noiseOffset.x, noiseOffset.y, noiseScale);

        if (noiseTex)
        {
            noiseTex.filterMode = FilterMode.Point;

            noiseImage.texture = noiseTex;
        }
    }
Пример #2
0
    float[,] GenerateHeights()
    {
        Texture2D noiseTex = new Texture2D(xSize, ySize);

        noiseTex.filterMode = FilterMode.Point;

        float[,] heights = new float[xSize, ySize];
        for (int x = 0; x < xSize; x++)
        {
            for (int y = 0; y < xSize; y++)
            {
                float xCoord = (float)(x - xSize / 2) / xSize * noiseScale + xOffset;
                float yCoord = (float)(y - ySize / 2) / ySize * noiseScale + yOffset;

                if (useOctaves)
                {
                    NoiseS3D.octaves = octaves;

                    heights[x, y] = (float)NoiseS3D.NoiseCombinedOctaves(xCoord, yCoord);
                }
                else
                {
                    heights[x, y] = Mathf.PerlinNoise(xCoord, yCoord);
                }
            }
        }

        return(heights);
    }
Пример #3
0
    void Start()
    {
        GameObject cubeParent = new GameObject();

        cubeParent.name = "Noise Cubes";

        for (int x = 0; x < gridSize; x++)
        {
            for (int y = 0; y < gridSize; y++)
            {
                for (int z = 0; z < gridSize; z++)
                {
                    float noiseValue = (float)NoiseS3D.NoiseCombinedOctaves(x * noiseScale, y * noiseScale, z * noiseScale);

                    //remap the value to 0 - 1 for color purposes
                    noiseValue = (noiseValue + 1) * 0.5f;

                    GameObject noiseCube = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    noiseCube.GetComponent <Renderer>().sharedMaterial = Instantiate(noiseMat) as Material;
                    Destroy(noiseCube.GetComponent <Collider>());

                    noiseCube.GetComponent <Renderer>().sharedMaterial.SetColor("_TintColor", new Color(noiseValue, noiseValue, noiseValue, noiseValue * 0.015f));

                    noiseCube.transform.SetParent(cubeParent.transform);
                    noiseCube.transform.position = new Vector3(x, y, z);
                }
            }
        }

        cubeParent.transform.position -= new Vector3(gridSize / 2, 0, gridSize / 2);
    }
Пример #4
0
    public static Texture2D MakeTexture(int height, int width, int octaves, float noiseScale)
    {
        Texture2D noiseTex = new Texture2D(width, height);

        noiseTex.filterMode = FilterMode.Point;

        for (int x = 0; x < noiseTex.width; x++)
        {
            for (int y = 0; y < noiseTex.height; y++)
            {
                float noiseValue = 0;

                NoiseS3D.octaves = octaves;
                noiseValue       = (float)NoiseS3D.NoiseCombinedOctaves(x * noiseScale, y * noiseScale);



                //remap the value to 0 - 1 for color purposes
                noiseValue = (noiseValue + 1) * 0.5f;

                noiseTex.SetPixel(x, y, new Color(noiseValue, noiseValue, noiseValue));
            }
        }

        return(noiseTex);
    }
Пример #5
0
    void Update()
    {
        for (int i = 0; i < originalVertices.Count; ++i)
        {
            //Vector3 dir = normals[i];
            float   r1  = (float)NoiseS3D.Noise(originalVertices[i].x * scale + 1001.12441, originalVertices[i].y * scale, originalVertices[i].z * scale, Time.time * speed);
            float   r2  = (float)NoiseS3D.Noise(originalVertices[i].x * scale + 124.1278, originalVertices[i].y * scale, originalVertices[i].z * scale, Time.time * speed);
            float   r3  = (float)NoiseS3D.Noise(originalVertices[i].x * scale + 5201.75141, originalVertices[i].y * scale, originalVertices[i].z * scale, Time.time * speed);
            Vector3 dir = new Vector3(r1, r2, r3).normalized;
            modifiedVertices[i] = originalVertices[i] + dir * amplitude * (float)NoiseS3D.Noise(originalVertices[i].x * scale, originalVertices[i].y * scale, originalVertices[i].z * scale, Time.time * speed);
        }

        UploadVertices();
    }
Пример #6
0
    void MakeTexture()
    {
        if (useSeed)
        {
            NoiseS3D.seed = seed;
        }

        if (noiseTex)
        {
            Destroy(noiseTex);
        }

        noiseTex            = new Texture2D(Screen.width, Screen.height);
        noiseTex.filterMode = FilterMode.Point;

        for (int x = 0; x < noiseTex.width; x++)
        {
            for (int y = 0; y < noiseTex.height; y++)
            {
                float noiseValue = 0;

                if (UseOctaves)
                {
                    NoiseS3D.octaves = octaves;
                    noiseValue       = (float)NoiseS3D.NoiseCombinedOctaves(x * noiseScale, y * noiseScale);
                }
                else
                {
                    noiseValue = (float)NoiseS3D.Noise(x * noiseScale, y * noiseScale);
                }

                //remap the value to 0 - 1 for color purposes
                noiseValue = (noiseValue + 1) * 0.5f;

                if (colorize)
                {
                    noiseTex.SetPixel(x, y, Color.HSVToRGB(1f - noiseValue, 1, 1));
                }
                else
                {
                    noiseTex.SetPixel(x, y, new Color(noiseValue, noiseValue, noiseValue));
                }
            }
        }

        noiseTex.Apply();

        noiseImage.texture = noiseTex;
    }
Пример #7
0
    void Update()
    {
        id = EventsManager.I.getEventID();

        px = transform.localPosition.x;
        py = transform.localPosition.y;

        x = NoiseS3D.Noise(Time.time);

        if (id < 20)
        {
            transform.localPosition = new Vector3(px, py, 1f + (float)x);
        }
        else
        {
            transform.localPosition = new Vector3(px, py, 1f + (float)x / 10f);
        }
    }
Пример #8
0
        IEnumerator ApplyPerlinNoise()
        {
            if (genType == GenerationType.Mesh)
            {
                for (int i = 0; i < vertices.Length; i++)
                {
                    float noise = (float)NoiseS3D.Noise((vertices[i].x + perlinOffset) * perlinScale, (vertices[i].z + perlinOffset) * perlinScale) * perlinMagnitude;
                    vertices[i].y += noise;
                    mesh.vertices  = vertices;

                    if (useVisualisation)
                    {
                        visCounter++;
                        if (visCounter > visCounterTarget)
                        {
                            visCounter = 0;
                            yield return(null);
                        }
                    }
                }

                StartCoroutine(GenerateNodes());
            }
            else if (genType == GenerationType.HexTile)
            {
                for (int i = 0; i < hexGrid.Length; i++)
                {
                    float noise = (float)NoiseS3D.Noise((hexGrid[i].transform.position.x + perlinOffset) * perlinScale, (hexGrid[i].transform.position.z + perlinOffset) * perlinScale) * perlinMagnitude;
                    hexGrid[i].transform.Translate(Vector3.up * noise);

                    if (useVisualisation)
                    {
                        visCounter++;
                        if (visCounter > visCounterTarget)
                        {
                            visCounter = 0;
                            yield return(null);
                        }
                    }
                }
                StartCoroutine(ColorMeHexes());
            }
            yield break;
        }
Пример #9
0
    private float RipleNoise(Vector3 point, Vector3 origin, Vector3 offset)
    {
        Vector3 position       = point + origin + offset;
        float   noise          = 0;
        float   localScale     = noiseSettings.roughness;
        float   localMagnitude = 1;

        for (int i = 0; i < noiseSettings.noiseLevels; i++)
        {
            float detail = 1 - Mathf.Abs((float)(NoiseS3D.Noise(position.x * localScale, position.y * localScale, position.z * localScale)));
            detail         *= detail;
            detail          = (detail) * localMagnitude;
            noise          += detail;
            localScale     *= noiseSettings.frequency;
            localMagnitude *= noiseSettings.dampValue;
        }
        noise = Mathf.Max(0, noise - noiseSettings.minValue);
        return(noise * noiseSettings.magnitude);
    }
Пример #10
0
    //this was used to compare the values from the normal noise function and the gpu version and make sure they match up
    void tmpArrayTestTexture()
    {
        NoiseS3D.octaves = 1;
        NoiseS3D.seed    = 10;

        Vector2[] noiseData = new Vector2[100];
        for (int t = 0; t < 100; t++)
        {
            noiseData[t] = new Vector2(t, Random.Range(0, 100000));
        }

        float[] outputNormal = new float[100];
        for (int t = 0; t < 100; t++)
        {
            outputNormal[t] = (((float)NoiseS3D.Noise(noiseData[t].x * 0.01, noiseData[t].y * 0.01)) + 1) * 0.5f;
        }

        float[] outputNoise = NoiseS3D.NoiseArrayGPU(noiseData);

        for (int t = 0; t < 100; t++)
        {
            Debug.Log("norm" + t + " = " + outputNormal[t] + "  :  array" + t + " = " + outputNoise[t]);
        }
    }
Пример #11
0
 public WorldGenerator(int seed)
 {
     noiseCore      = new NoiseS3D();
     noiseCore.seed = seed;
 }
Пример #12
0
    // Use this for initialization
    void Start()
    {
        //tmpArrayTestTexture();
        //return;

        int testCount = (int)(testRes.x * testRes.y);

        sw.Start();
        for (int i = 0; i < iterations; i++)
        {
            for (int t = 0; t < testCount; t++)
            {
                float noiseValue = Mathf.PerlinNoise(i, t);
            }
        }
        sw.Stop();
        Debug.Log("Unity 2D perlin noise: " + sw.ElapsedMilliseconds / iterations + " Avg milliseconds to perform " + testCount + " noise calls.");
        outputText.text += "Unity 2D perlin noise: " + sw.ElapsedMilliseconds / iterations + " Avg milliseconds to perform " + testCount + " noise calls.\n";

        sw.Reset();

        sw.Start();
        for (int i = 0; i < iterations; i++)
        {
            for (int t = 0; t < testCount; t++)
            {
                double noiseValue = NoiseS3D.Noise(i, t);
            }
        }
        sw.Stop();
        Debug.Log("NoiseS3D 2D noise : " + sw.ElapsedMilliseconds / iterations + " Avg milliseconds to perform " + testCount + " noise calls.");
        outputText.text += "NoiseS3D 2D noise: " + sw.ElapsedMilliseconds / iterations + " Avg milliseconds to perform " + testCount + " noise calls.\n";

        sw.Reset();


        NoiseS3D.octaves = 1;
        sw.Start();
        for (int i = 0; i < iterations; i++)
        {
            RenderTexture noiseTex = NoiseS3D.GetNoiseRenderTexture((int)testRes.x, (int)testRes.y);
        }
        sw.Stop();
        Debug.Log("NoiseS3D 2D noise RenderTexture on GPU: " + sw.ElapsedMilliseconds / iterations + " Avg milliseconds to perform " + testCount + " noise calls.");
        outputText.text += "NoiseS3D 2D noise RenderTexture on GPU: " + sw.ElapsedMilliseconds / iterations + " Avg milliseconds to perform " + testCount + " noise calls.\n";

        sw.Reset();

        NoiseS3D.octaves = 1;
        sw.Start();
        for (int i = 0; i < iterations; i++)
        {
            Texture2D noiseTex = NoiseS3D.GetNoiseTexture((int)testRes.x, (int)testRes.y);
        }
        sw.Stop();
        Debug.Log("NoiseS3D 2D noise Texture2D on GPU: " + sw.ElapsedMilliseconds / iterations + " Avg milliseconds to perform " + testCount + " noise calls.");
        outputText.text += "NoiseS3D 2D noise Texture2D on GPU: " + sw.ElapsedMilliseconds / iterations + " Avg milliseconds to perform " + testCount + " noise calls.\n";

        sw.Reset();
        sw.Stop();

        //create this data outside of the timer, otherwise its not fair comparision bc the other tests did not need to create data
        Vector2[] noiseData = new Vector2[testCount];
        for (int t = 0; t < testCount; t++)
        {
            noiseData[t] = new Vector2(t, Random.Range(0, 100000));
        }

        sw.Reset();

        NoiseS3D.octaves = 1;
        sw.Start();
        for (int i = 0; i < iterations; i++)
        {
            float[] outputNoise = NoiseS3D.NoiseArrayGPU(noiseData);
        }
        sw.Stop();
        Debug.Log("NoiseS3D 2D noise array on GPU not including array creation: " + sw.ElapsedMilliseconds / iterations + " Avg milliseconds to perform " + testCount + " noise calls.");
        outputText.text += "NoiseS3D 2D noise array on GPU not including array creation: " + sw.ElapsedMilliseconds / iterations + " Avg milliseconds to perform " + testCount + " noise calls.\n";

        sw.Reset();

        NoiseS3D.octaves = 1;
        sw.Start();
        for (int i = 0; i < iterations; i++)
        {
            Vector2[] noiseOutput = new Vector2[testCount];
            for (int t = 0; t < testCount; t++)
            {
                noiseOutput[t] = new Vector2(i, t);
            }
            float[] outputNoise = NoiseS3D.NoiseArrayGPU(noiseOutput);
        }
        sw.Stop();
        Debug.Log("NoiseS3D 2D noise array on GPU including array creation: " + sw.ElapsedMilliseconds / iterations + " Avg milliseconds to perform " + testCount + " noise calls.");
        outputText.text += "NoiseS3D 2D noise array on GPU including array creation: " + sw.ElapsedMilliseconds / iterations + " Avg milliseconds to perform " + testCount + " noise calls.\n";

        sw.Reset();
    }