Exemplo n.º 1
0
    public MapData GenerateMapData(Vector2 centre)
    {
        craterTypeNr = RandomizerType();

        float[,] map = new float[mapChunkSize + 2, mapChunkSize + 2];

        //fetching 2D NoiseMap from the NoiseGenerator Class
        // +2 for the border vertices. generates 1 extra noise value on left and right side
        float[,] noiseMask    = NoiseGenerator.GenerateNoiseMap(mapChunkSize + 2, mapChunkSize + 2, seed, noiseScale, octaves, persistance, lacunarity, centre + offset, normalizeMode);
        float[,] noiseMaskMOD = NoiseGenerator.GenerateNoiseMap(mapChunkSize + 2, mapChunkSize + 2, seed, noiseScale + 10, octaves + 2, persistance + 0.3f, lacunarity + 5, centre + offset, normalizeMode);

        float ringWeightRND = craters[craterTypeNr].ringWeight;
        float ringWidthRND  = craters[craterTypeNr].ringWidth;
        //float falloffIntensityRND = craters[craterTypeNr].falloffIntensity;
        float falloffWeightRND   = craters[craterTypeNr].falloffWeight;
        float falloffstartRND    = craters[craterTypeNr].falloffstart;
        float stripeIntensityRND = craters[craterTypeNr].stripeIntensity;
        float stripeSinRND       = craters[craterTypeNr].stripeSin;
        float stripeQuantityRND  = craters[craterTypeNr].stripeQuantity;
        float sinWIntensityRND   = craters[craterTypeNr].sinWIntensity;
        float sinWQuantityRND    = craters[craterTypeNr].sinWQuantity;
        float sinwCentressRND    = craters[craterTypeNr].sinWCentress;
        float lineStartRND       = craters[craterTypeNr].lineStart;

        float complexHeight      = 0.6f;
        float complexNoiseMod    = 0.01f;
        float complexcentral     = 0.1f;
        float complexProbability = 0f;

        bool complexTrue = false;

        //Randomizes generated Crater in Play Mode
        System.Random craterRNG = new System.Random();
        if (activateRandomizer)
        {
            ringWeightRND = (float)craterRNG.Next(0, 40) / 100;
            ringWidthRND  = (float)craterRNG.Next(-2, 8) / 100;
            //falloffIntensityRND = (float) craterRNG.Next(0, 600)/100;
            //falloffWeightRND = (float)craterRNG.Next(10, 600) / 100;
            //falloffstartRND = (float)craterRNG.Next(0, 7) / 100;
            stripeIntensityRND = (float)craterRNG.Next(0, 200) / 100;
            stripeSinRND       = (float)craterRNG.Next(0, 200) / 100;
            //stripeQuantityRND = (float)craterRNG.Next(100, 400) / 100;
            //sinWIntensityRND = (float)craterRNG.Next(100, 300)/100;
            sinWQuantityRND = (float)craterRNG.Next(0, 130) / 1000;
            //lineStartRND = (float)craterRNG.Next(30, 200) / 100;
            sinwCentressRND = (float)craterRNG.Next(0, 200) / 100;

            complexHeight   = (float)craterRNG.Next(57, 80) / 100;
            complexNoiseMod = (float)craterRNG.Next(0, 10) / 1000;
            complexcentral  = (float)craterRNG.Next(0, 10) / 100;

            //probabiltiy complex craters
            complexProbability = (float)craterRNG.Next(0, 10);
            if (complexProbability < 2)
            {
                complexTrue = true;
            }
        }



        //float[,] ringMask = CraterRingGenerator.GenerateCraterRing(mapChunkSize, craterSize + ringWidthRND,
        //    craterIntensity + craterSize + ringWeightRND, position.x, position.y, ellipse.x, ellipse.y);

        //float[,] ringMask = craterRing;

        craterMap = CraterGenerator.GenerateCrater(mapChunkSize, craterSize, craterIntensity, position.x, position.y, ellipse.x, ellipse.y);

        craterRing = CraterRingGenerator.GenerateCraterRing(mapChunkSize, craterSize + ringWidthRND,
                                                            craterIntensity + craterSize + ringWeightRND, position.x, position.y, ellipse.x, ellipse.y);

        craterFalloff = CraterFalloffGenerator.GenerateCraterFalloff(mapChunkSize, craterSize + ringWidthRND + falloffstartRND,
                                                                     craterIntensity + craterSize + falloffWeightRND, position.x, position.y, ellipse.x, ellipse.y);

        craterStripes = CraterStripesGenerator.GenerateCraterStripes(mapChunkSize, stripeSinRND,
                                                                     stripeQuantityRND);

        craterSinW = CraterSinW.GenerateCraterSinW(mapChunkSize, sinwCentressRND, position.x, position.y, ellipse.x, ellipse.y,
                                                   sinWQuantityRND);

        craterQuadFalloff = CraterQuadFalloffGenerator.GenerateCraterQuadFalloff(mapChunkSize, position.x, position.y, lineStartRND, 0);

        craterCentralPeak = CraterCentralPeak.GenerateCreaterCentralPeak(mapChunkSize, craters[craterTypeNr].centralSize,
                                                                         craters[craterTypeNr].centralPeakness, position.x + craters[craterTypeNr].centralPosition.x,
                                                                         position.y + craters[craterTypeNr].centralPosition.y, ellipse.x,
                                                                         ellipse.y);

        craterTerrace = CraterTerrace.GenerateCraterTerrace(mapChunkSize, craters[craterTypeNr].terraceSize, craters[craterTypeNr].terracePeakness,
                                                            position.x + craters[craterTypeNr].terracePosition.x, position.y + craters[craterTypeNr].terracePosition.y, ellipse.x,
                                                            ellipse.y);


        //Random percentage to get a crater
        System.Random rnd     = new System.Random();
        int           rndFall = rnd.Next(1, 100);

        //all randomizer
        //if (activateRandomizer)
        //{
        //    craters[craterTypeNr].ringWeight = (float)craterRNG.Next(0, 5) / 10;

        //    craters[craterTypeNr].ringWidth = (float)craterRNG.Next(-1, 1) / 10;

        //    craters[craterTypeNr].falloffstart = (float)craterRNG.Next(0, 1) / 10;
        //    craters[craterTypeNr].falloffWeight = (float)craterRNG.Next(5, 50) / 10;
        //    craters[craterTypeNr].falloffIntensity = (float)craterRNG.Next(0, 50) / 10;

        //    craters[craterTypeNr].stripeIntensity = (float)craterRNG.Next(0, 5) / 10;
        //    craters[craterTypeNr].stripeSin = (float)craterRNG.Next(0, 50) / 10;
        //    craters[craterTypeNr].stripeQuantity = (float)craterRNG.Next(20, 50) / 10;
        //    craters[craterTypeNr].stripeWidth = (float)craterRNG.Next(0, 2) / 10;
        //    craters[craterTypeNr].sinWIntensity = (float)craterRNG.Next(1, 3);
        //    craters[craterTypeNr].sinWCentress = (float)craterRNG.Next(0, 10) / 10;

        //    craters[craterTypeNr].sinWQuantity = (float)craterRNG.Next(0, 200) / 100;
        //    craters[craterTypeNr].sinWWidth = (float)craterRNG.Next(20, 50) / 10;

        //    craters[craterTypeNr].lineStart = (float)craterRNG.Next(0, 50) / 10;
        //    craters[craterTypeNr].lineIntensity = (float)craterRNG.Next(0, 10) / 10;

        //    craters[craterTypeNr].centralIntensity = (float)craterRNG.Next(0, 50) / 10;

        //    craters[craterTypeNr].centralNoise = (float)craterRNG.Next(0, 5) / 10;
        //    craters[craterTypeNr].centralHeight = (float)craterRNG.Next(0, 5) / 10;
        //    craters[craterTypeNr].centralSize = (float)craterRNG.Next(0, 20) / 10;
        //    craters[craterTypeNr].centralPeakness = (float)craterRNG.Next(0, 100) / 100;
        //    //craters[craterTypeNr].centralPosition = prng.Next(0, 5);

        //    craters[craterTypeNr].terraceIntensity = (float)craterRNG.Next(0, 20) / 100;

        //    craters[craterTypeNr].terraceNoise = (float)craterRNG.Next(0, 5) / 10;
        //    craters[craterTypeNr].terraceHeight = (float)craterRNG.Next(0, 5) / 10;
        //    craters[craterTypeNr].terraceSize = (float)craterRNG.Next(0, 20) / 10;
        //    craters[craterTypeNr].terracePeakness = (float)craterRNG.Next(0, 5) / 10;
        //    //craters[craterTypeNr].terracePosition = prng.Next(0, 5);


        //    craters[craterTypeNr].ringIntensity = 0;
        //}

        //generate 1D Colormap from 2D Noisemap
        Color[] colourMap = new Color[(mapChunkSize + 2) * (mapChunkSize + 2)];
        for (int y = 0; y < mapChunkSize; y++)
        {
            for (int x = 0; x < mapChunkSize; x++)
            {
                //float ringMask = Mathf.Clamp01(craters[craterTypeNr].ringIntensity * craterRing[x, y]);
                float falloffMask = Mathf.Clamp01(craters[craterTypeNr].falloffIntensity * craterFalloff[x, y]);
                float stripeMask  = Mathf.Clamp01(stripeIntensityRND * craterStripes[x, y] - craterRing[x, y] * craters[craterTypeNr].stripeWidth);
                float sinusMask   = Mathf.Clamp01(sinWIntensityRND * craterSinW[x, y] - craterRing[x, y] * craters[craterTypeNr].sinWWidth);
                float lineMask    = Mathf.Clamp01((craters[craterTypeNr].lineIntensity * (craterQuadFalloff[x, y] - craterFalloff[x, y] * 10)));
                float centralMask =
                    Mathf.Clamp01(-(craterCentralPeak[x, y] - 1) - (craterMap[x, y] - sinusMask) * craters[craterTypeNr].centralIntensity);
                float terraceMask = Mathf.Clamp01((((craterTerrace[x, y])) - craterMap[x, y]) * craters[craterTypeNr].terraceIntensity);
                float pseudoMask  = Mathf.Clamp01(pseudoIntensity * craterPseudoRnd[x, y]);

                if (falloffMask > terrainHeight)
                {
                    falloffMask = terrainHeight;
                }

                if (centralMask > craters[craterTypeNr].centralHeight)
                {
                    centralMask = craters[craterTypeNr].centralHeight;
                }

                if (terraceMask > craters[craterTypeNr].terraceHeight)
                {
                    terraceMask = craters[craterTypeNr].terraceHeight;
                }

                //terrainheight if cant be changed so terrainHeight has to be changed here
                map[x, y] = (-(terrainHeight) + 1) + Mathf.Abs(noiseMask[x, y] / 100 * NoiseIntensity) - pseudoMask;

                if (cleanChunks)
                {
                    map[x, y] = craterMap[x, y] - falloffMask - stripeMask + sinusMask + lineMask + centralMask - terraceMask;
                }
                //while looping through noiseMap. use falloff map
                else if (craterProbability >= rndFall)
                {
                    map[x, y] = (craterMap[x, y] - falloffMask - stripeMask + sinusMask + lineMask + centralMask - terraceMask - pseudoMask) + Mathf.Abs(noiseMask[x, y] / 100 * NoiseIntensity);

                    //For Tests: adds additionally cratertype of complex and old craters
                    if (activateRandomizer)
                    {
                        if (complexTrue)
                        {
                            if (map[x, y] <= complexHeight)
                            {
                                map[x, y] = complexHeight + noiseMaskMOD[x, y] * complexNoiseMod + (centralMask * complexcentral * noiseMaskMOD[x, y] * 4);
                            }
                        }
                    }
                }
                float currentHeight = map[x, y];
                for (int i = 0; i < rockLevels.Length; i++)
                {
                    //sections where we actual assigning the colors
                    if (currentHeight >= rockLevels[i].height)
                    {
                        colourMap[y * mapChunkSize + x] = rockLevels[i].colour; //if its greater, then assign the color
                    }
                    else
                    {
                        break; //only break if its less then the rockLevels height
                    }
                }
            }
        }
        craterSeed++;
        return(new MapData(map, colourMap));
    }
Exemplo n.º 2
0
    public void DrawMapInEditor()
    {
        craterTypeNr = RandomizerType();

        MapData mapData = GenerateMapData(Vector2.zero);

        MapDisplay display = FindObjectOfType <MapDisplay>(); //reference to mapdisplay, gives different options

        if (drawMode == DrawMode.NoiseMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(NoiseGenerator.GenerateNoiseMap(mapChunkSize + 2, mapChunkSize + 2, seed, noiseScale, octaves, persistance, lacunarity, Vector2.zero + offset, normalizeMode)));
        }
        if (drawMode == DrawMode.MixedHeightMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(mapData.heightMap));
        }
        else if (drawMode == DrawMode.ColourMap)
        {
            display.DrawTexture(TextureGenerator.ColourMapTexture(mapData.colourMap, mapChunkSize, mapChunkSize));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            display.DrawMesh(MeshGenerator.GenerateTerrainMesh(mapData.heightMap, meshHeightMultiplier, meshHeightCurve, LOD),
                             TextureGenerator.ColourMapTexture(mapData.colourMap, mapChunkSize, mapChunkSize));
        }
        else if (drawMode == DrawMode.Crater)
        {
            display.DrawTexture(
                TextureGenerator.TextureFromHeightMap(CraterGenerator.GenerateCrater(mapChunkSize, craterSize, craterIntensity, position.x, position.y,
                                                                                     ellipse.x, ellipse.y)));
        }
        else if (drawMode == DrawMode.CraterRing)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(CraterRingGenerator.GenerateCraterRing(mapChunkSize, craterSize + craters[craterTypeNr].ringWidth,
                                                                                                             craterIntensity + craterSize + craters[craterTypeNr].ringWeight, position.x, position.y, ellipse.x, ellipse.y)));
        }
        else if (drawMode == DrawMode.CraterFalloff)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(CraterFalloffGenerator.GenerateCraterFalloff(mapChunkSize, craterSize + craters[craterTypeNr].ringWidth + craters[craterTypeNr].falloffstart,
                                                                                                                   craterIntensity + craterSize + craters[craterTypeNr].falloffWeight, position.x, position.y, ellipse.x, ellipse.y)));
        }
        else if (drawMode == DrawMode.CraterStripes)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(CraterStripesGenerator.GenerateCraterStripes(mapChunkSize, craters[craterTypeNr].stripeSin, craters[craterTypeNr].stripeQuantity)));
        }
        else if (drawMode == DrawMode.CraterSinW)
        {
            display.DrawTexture(
                TextureGenerator.TextureFromHeightMap(CraterSinW.GenerateCraterSinW(mapChunkSize, craters[craterTypeNr].sinWCentress, position.x, position.y, ellipse.x, ellipse.y, craters[craterTypeNr].sinWQuantity)));
        }
        else if (drawMode == DrawMode.CraterQuadFalloff)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(CraterQuadFalloffGenerator.GenerateCraterQuadFalloff(mapChunkSize, position.x, position.y, craters[craterTypeNr].lineStart, 0)));
        }
        //else if (drawMode == DrawMode.CraterSidedParable)
        //{
        //    display.DrawTexture(TextureGenerator.TextureFromHeightMap(CraterSidedParable.GenerateCraterSidedParable(mapChunkSize, craters[craterTypeNr].diagScale, craters[craterTypeNr].diagParable, craters[craterTypeNr].diagDirection)));
        //}
        else if (drawMode == DrawMode.CraterCentralPeak)
        {
            display.DrawTexture(
                TextureGenerator.TextureFromHeightMap(CraterCentralPeak.GenerateCreaterCentralPeak(mapChunkSize, craters[craterTypeNr].centralSize, craters[craterTypeNr].centralPeakness, position.x + craters[craterTypeNr].centralPosition.x, position.y + craters[craterTypeNr].centralPosition.y, ellipse.x,
                                                                                                   ellipse.y)));
        }
        else if (drawMode == DrawMode.CraterTerrace)
        {
            display.DrawTexture(
                TextureGenerator.TextureFromHeightMap(CraterTerrace.GenerateCraterTerrace(mapChunkSize, craters[craterTypeNr].terraceSize, craters[craterTypeNr].terracePeakness, position.x + craters[craterTypeNr].terracePosition.x, position.y + craters[craterTypeNr].terracePosition.y, ellipse.x,
                                                                                          ellipse.y)));
        }
        else if (drawMode == DrawMode.CraterPseudoRnd)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(CraterPseudoRndGenerator.GenerateCraterPseudoRnd(mapChunkSize, pseudoDensity, pseudoPeaks, pseudoVal)));
        }
    }