Beispiel #1
0
    // main generation function called on to generate each point in the mesh
    // experiment with noise here!
    Vector3 GeneratePoint(float x, float y)
    {
        Vector3 position = new Vector3(x, 0.0f, y);

        float mountains = Noise.Ridged(position + offset1, 6, 0.0075f);

        mountains *= .5f;
        mountains += .5f;
        //float hills = Noise.Fractal(position + offset1, 5, 0.005f);
        float hills = Noise.Billow(position + offset1, 5, 0.005f);

        hills *= .25f;
        hills -= .25f;

        float blendNoise = Noise.Fractal(position + offset2, 5, 0.003f);
        float total      = Noise.Blend(mountains, hills, blendNoise, -0.5f, 0.5f);

        total = (total + 1) / 2.0f;
        //Color c = grad.Evaluate(total);
        total = total * 0.8f;
        //float colnoise = (Noise.Billow(position, 4, 0.02f) + 1.0f) / 2.0f;
        //Color c = new Color(0.2f, 0.1f, colnoise);
        //c = new Color(.6f, .6f, .1f + colnoise / 3.0f);
        return(new Vector3(x, total * 60.0f, y));

        //float xf = x * 0.04f + offset1.x;
        //float yf = y * 0.04f + offset1.y;
        //WorleySample ws = Noise.Worley3(xf, yf, 0, 2, DistanceFunction.EUCLIDIAN);
        //float h = 1.0f - (float)ws.F[0];

        //Vector3 pos = new Vector3(x, h * 25.0f, y);
        //return new TerrainPoint(pos, grad.Evaluate(h));
    }
Beispiel #2
0
    public static Voxel EvalTerrain(Vector3 worldPos, float voxelSize)
    {
        float d = worldPos.y;

        d += Noise.Fractal(worldPos + new Vector3(-100, 600, -500), 9, 0.01f, 0.5f, 2.0f) * 20.0f;
        sbyte db = (sbyte)(Mathf.Clamp(Mathf.Round(d * 128.0f / voxelSize), -128.0f, 127.0f));

        return(new Voxel(db, 0));
    }
Beispiel #3
0
    public static Voxel EvalBigPlanet(Vector3 worldPos, float voxelSize)
    {
        float   rad = 14000.0f;
        Vector3 wp  = worldPos;

        wp.y -= rad;
        float planet = (wp - new Vector3(0, -rad, 0)).magnitude - rad;

        //float mainNoise = Noise.Fractal(wp + Vector3.one * 1000.0f, 7, 0.001f, 0.5f, 2f);

        float mainNoise = Noise.Ridged(wp + Vector3.one * 1000.0f, 7, 0.001f, 0.5f, 2f, true) * -1.0f;

        float col = mainNoise;
        byte  mat = 0;

        float grassLevel = Noise.Fractal(wp + Vector3.one * 50.0f, 5, 0.01f) * 0.2f;

        if (col < -.7f)
        {
            mat = 0;
        }
        else if (col < 0.3f + grassLevel)
        {
            mat = 1;
        }
        else
        {
            mat = 2;
        }

        float highFreqNoise = Noise.Ridged(wp + Vector3.one * 250.0f, 5, 0.02f) * 10.0f * 1.0f;
        // this was basically doing what smoothValleys in ridged does
        float n = Mathf.LerpUnclamped(0.3f, 1.0f, (mainNoise + 1.0f) / 2.0f);

        planet += mainNoise * 100.0f;
        planet += highFreqNoise * (1.0f - n * n);
        float d = planet;

        Voxel v;

        v.density  = (sbyte)(Mathf.Clamp(Mathf.Round(d * 128.0f / voxelSize), -128.0f, 127.0f));
        v.material = mat;
        //v.material = (byte)Random.Range(0, 2);

        //float col = Noise.Fractal3(worldPos, Vector3.one * 100.0f, 4, 0.005f);
        //float col = offset;
        // need to figure out way to understand how to think in terms of density lol...

        //System.Random r = new System.Random();
        // figure out way to do multithreaded randoms



        return(v);
    }
Beispiel #4
0
    public static Voxel EvalSphereTest(Vector3 worldPos, float voxelSize)
    {
        float d = 0.0f;

        float rad = 1000.0f;

        d = Sphere(worldPos, new Vector3(0, 0, 0), rad);
        float offset = Noise.Fractal(worldPos + Vector3.one * 1000.0f, 8, 0.001f, 0.5f, 2f) * 100.0f;
        //d += offset;

        sbyte db  = (sbyte)(Mathf.Clamp(Mathf.Round(d * 128.0f / voxelSize), -128.0f, 127.0f));
        byte  mat = (byte)((int)(worldPos.magnitude / 50.0f) % 3);

        return(new Voxel(db, mat));
    }
Beispiel #5
0
        private float ReturnFractalNoiseValueAtSpot(float factor, Vector2 location, Noise randomnoise)
        {
            var FractalType = 2;
            var iterations  = 1;
            var detail      = 0.5f;
            var turbulence  = 0f;

            var ret = (randomnoise.Fractal(location.x, location.y, 1, iterations, detail, turbulence, FractalType)
                       * 2 - 1) * 1 * factor;

            // do a true / false coin flip.
            if (FlipALocationCoin(location))
            {
                return(-ret);
            }
            else
            {
                return(ret);
            }
        }
Beispiel #6
0
        private static void Noise(MatrixWorld matrix, Noise noise, StopToken stop,
                                  int type, float intensity, float size, float detail, float turbulence, Vector2D offset)
        {
            int iterations = (int)Mathf.Log(size, 2) + 1;            //+1 max size iteration

            Coord min = matrix.rect.Min; Coord max = matrix.rect.Max;

            for (int x = min.x; x < max.x; x++)
            {
                for (int z = min.z; z < max.z; z++)
                {
                    Vector2D relativePos = new Vector2D(
                        (float)(x - matrix.rect.offset.x) / (matrix.rect.size.x - 1),
                        (float)(z - matrix.rect.offset.z) / (matrix.rect.size.z - 1));

                    Vector2D worldPos = new Vector2D(
                        relativePos.x * matrix.worldSize.x + matrix.worldPos.x,
                        relativePos.z * matrix.worldSize.z + matrix.worldPos.z);

                    float val = noise.Fractal(worldPos.x + offset.x, worldPos.z + offset.z, size, iterations, detail, turbulence, (int)type);
                    val *= intensity;

                    if (val < 0)
                    {
                        val = 0;                              //before mask?
                    }
                    if (val > 1)
                    {
                        val = 1;
                    }

                    matrix[x, z] += val;
                }

                if (stop != null && stop.stop)
                {
                    return;                                          //checking stop every x line
                }
            }
        }
Beispiel #7
0
    public static Voxel EvalWorldTest(Vector3 worldPos, float voxelSize)
    {
        float d = 0.0f;

        float rad = 1000.0f;

        d = Sphere(worldPos, new Vector3(0, 0, 0), rad);

        float offset = Noise.Fractal(worldPos + Vector3.one * 1000.0f, 8, 0.001f, 0.5f, 2f) * 100.0f;

        d += offset;

        Voxel v;

        // this seems wierd still i dunno
        v.density = (sbyte)(Mathf.Clamp(Mathf.Round(d * 128.0f / voxelSize), -128.0f, 127.0f));

        float col = Noise.Fractal(worldPos + Vector3.one * 100.0f, 4, 0.005f);
        //float col = offset;
        // need to figure out way to understand how to think in terms of density lol...
        byte mat = 0;

        if (col < -.7f)
        {
            mat = 0;
        }
        else if (col < 0.3f)
        {
            mat = 1;
        }
        else
        {
            mat = 2;
        }

        v.material = mat;

        return(v);
    }
Beispiel #8
0
    public void OnFrame()
    {
        var pos     = WorldPos;
        var right   = WorldRot.Right * 4;
        var forward = WorldRot.Forward * 4;
        var up      = WorldRot.Up * 50;
        var offset  = Time.Now * 2.0f;
        var offsetz = Time.Now * 0.1f;

        var mode = (int)((Time.Now * 0.3f) % 5);

        switch (mode)
        {
        case 0:
        {
            DebugOverlay.Text(pos, "Perlin");
            break;
        }

        case 1:
        {
            DebugOverlay.Text(pos, "SparseConvolution");
            break;
        }

        case 2:
        {
            DebugOverlay.Text(pos, "SparseConvolutionNormalized");
            break;
        }

        case 3:
        {
            DebugOverlay.Text(pos, "Turbulence");
            break;
        }

        case 4:
        {
            DebugOverlay.Text(pos, "Fractal");
            break;
        }
        }


        var size = 100;

        pos -= right * size * 0.5f;
        pos -= forward * size * 0.5f;

        for (float x = 0; x < size; x++)
        {
            for (float y = 0; y < size; y++)
            {
                float val = 0;

                switch (mode)
                {
                case 0:
                {
                    val = Noise.Perlin(x * 0.1f + offset, y * 0.1f, offsetz) * 0.5f;
                    break;
                }

                case 1:
                {
                    val = Noise.SparseConvolution(x * 0.1f + offset, y * 0.1f, offsetz) * 0.5f;
                    break;
                }

                case 2:
                {
                    val = Noise.SparseConvolutionNormalized(x * 0.1f + offset, y * 0.1f, offsetz) * 0.5f;
                    break;
                }

                case 3:
                {
                    val = Noise.Turbulence(2, x * 0.1f + offset, y * 0.1f, offsetz) * 0.5f;
                    break;
                }

                case 4:
                {
                    val = Noise.Fractal(2, x * 0.1f + offset, y * 0.1f, offsetz) * 0.5f;
                    break;
                }
                }

                var start = pos + x * right + y * forward;
                DebugOverlay.Line(start, start + up * val, Color.Lerp(Color.Red, Color.Green, (val + 1.0f) / 2.0f));
            }
        }
    }
Beispiel #9
0
    public static Voxel Eval(Vector3 worldPos, float voxelSize)
    {
        float d = 0.0f;

        // FRACTAL PLANET ----------------------------------------------------------------
        //float rad = 800.0f;
        //Vector3 wp = worldPos;
        //wp.y -= rad;
        //float planet = (wp - new Vector3(0, -rad, 0)).magnitude - rad;
        //planet += Noise.Fractal3(wp, new Vector3(-100, 10, 25), 5, 0.009f, 0.45f, 2.07f) * 25.0f;

        //float sphere = Sphere(worldPos, Vector3.zero, 785.0f);
        //sphere += Noise.Fractal3(worldPos, Vector3.zero, 3, 0.05f);

        //d = Union(planet, sphere);
        ////d = sphere;
        //--------------------------------------------------------------------------------

        // BIG PLANET ------------------------------------------------------


        //float sphere = Sphere(worldPos, Vector3.zero, 785.0f);
        //sphere += Noise.Fractal3(worldPos, Vector3.zero, 3, 0.05f);
        //d = Union(planet, sphere);
        //d = sphere;
        //------------------------------------------------------------------

        //warping test----------------------------
        float rad = 1000.0f;

        //Vector3 wp = worldPos;
        //wp.y -= rad;
        //float qx = Noise.Fractal3(wp, new Vector3(0.0f, 0.0f, 0.0f), 3, 0.01f);
        //float qy = Noise.Fractal3(wp, new Vector3(5.2f, 1.3f, -2.0f), 3, 0.01f);
        //float qz = Noise.Fractal3(wp, new Vector3(1.5f, 2.7f, 3.7f), 3, 0.01f);
        //wp = wp + 20.0f * new Vector3(qx, qy, qz);

        //float planet = (wp - new Vector3(0, -rad, 0)).magnitude - rad;
        //planet += Noise.Fractal3(wp, Vector3.one * 1000.0f, 8, 0.001f, 0.5f, 2f) * 100.0f;
        //d = planet;

        //worldPos.y -= rad;
        //d = Sphere(worldPos, Vector3.zero, rad);
        d = Sphere(worldPos, new Vector3(0, 0, 0), rad);

        float offset = Noise.Fractal(worldPos + Vector3.one * 1000.0f, 8, 0.001f, 0.5f, 2f) * 100.0f;

        d += offset;

        //d = Sphere(worldPos, Vector3.zero, 14000.0f);

        //-----------------------------------------

        // WORLEY NOISE TEST--------------------------------------------------------------
        // change fractal3 code to use worley instead
        // this is currently broke and may show vurnerability in mesh generation
        // because parents arent getting meshes sometimes with this
        //d += Noise.Fractal3(worldPos, new Vector3(-100, 10, 25), 3, 0.001f, 0.45f, 2.07f) * 25.0f;
        //--------------------------------------------------------------------------------

        //float warp = Noise.Simplex3(worldPos.x * 0.04f, worldPos.y * 0.04f, worldPos.z * 0.04f);
        //worldPos += Vector3.one * warp * 20;


        //d += (float)Noise.Simplex3(worldPos.x * 4.03, worldPos.y * 4.03, worldPos.z * 4.03) * 5f;
        //d += (float)Noise.Simplex3(worldPos.x * 1.96, worldPos.y * 1.96, worldPos.z * 1.96) * 0.5f;
        //d += (float)Noise.Simplex3(worldPos.x * 1.01, worldPos.y * 1.01, worldPos.z * 1.01) * 1.0f;

        //simple rotated cube test -------------------------------------------------------
        //worldPos = Quaternion.AngleAxis(45.0f, Vector3.right) * worldPos;
        //worldPos = Quaternion.AngleAxis(45.0f, Vector3.up) * worldPos;
        //d = Cuboid(worldPos, new Vector3(20, 0, 10), Vector3.one * 5);
        //--------------------------------------------------------------------------------

        //d = worldPos.y - 10.0f;

        //float sphere = Sphere(worldPos, new Vector3(20.0f, 20.0f, 20.0f), 8.0f);
        //float torus = Torus(worldPos, new Vector3(20.0f, 20.0f, 30.0f), new Vector2(12.0f, 4.0f));
        //d = Union(sphere,torus);

        //float sphere = Sphere(worldPos, new Vector3(200.0f, 200.0f, 160.0f), 200.0f);
        //float torus = Torus(worldPos, new Vector3(200.0f, 200.0f, -80.0f), new Vector2(200.0f, 80.0f));
        //float cube = Cuboid(worldPos, new Vector3(0.0f, 400.0f, 0.0f), Vector3.one * 240.0f);

        //d = Union(sphere, torus);
        //d = Subtraction(d, cube);

        // bounds of 64 size area
        //return Cuboid(worldPos, new Vector3(0.0f, 0.0f, 0.0f), Vector3.one * 32.0f);

        //float sqrMag = worldPos.sqrMagnitude;

        //float freq = 0.01f;
        //double d = SimplexNoise.noise(worldPos.x * freq, worldPos.y * freq, worldPos.z * freq);
        ////WorleySample w = Noise.Worley3(worldPos.x * freq, worldPos.y * freq, worldPos.z * freq, 2, DistanceFunction.EUCLIDIAN);
        ////double d = w.F[1] - w.F[0];

        // BASIC FLAT FRACTAL ------------------------------------------------------------
        //d = worldPos.y;
        //d += Noise.Fractal3(worldPos, new Vector3(-100, 600, -500), 9, 0.01f, 0.5f, 2.0f) * 20.0f;
        //--------------------------------------------------------------------------------

        Voxel v;

        // this seems wierd still i dunno
        v.density = (sbyte)(Mathf.Clamp(Mathf.Round(d * 128.0f / voxelSize), -128.0f, 127.0f));

        float col = Noise.Fractal(worldPos + Vector3.one * 100.0f, 4, 0.005f);
        //float col = offset;
        // need to figure out way to understand how to think in terms of density lol...
        byte mat = 0;

        if (col < -.7f)
        {
            mat = 0;
        }
        else if (col < 0.3f)
        {
            mat = 1;
        }
        else
        {
            mat = 2;
        }

        v.material = mat;

        return(v);
    }