예제 #1
0
    public void Init(int index)
    {
        ResetMesh();

        int startColumn = planet.columnsPerChunk * index;
        int endColumn   = planet.columnsPerChunk * (index + 1);

        endColumn = Mathf.Min(endColumn, planet.tileColumns);

        for (float i = startColumn; i < endColumn; i++)
        {
            float angle    = (i / planet.tileColumns) * Mathf.PI * 2f;
            float noise    = NoiseFilter.Evaluate(planet.features.noiseFeatures, new Vector2(Mathf.Cos(angle) * planet.radius, Mathf.Sin(angle) * planet.radius));
            int   distance = Mathf.RoundToInt(planet.radius + noise);

            for (int j = distance; j > planet.radius - planet.features.crustThickness; j--)
            {
                Vector2 position = new Vector2(Mathf.Cos(angle) * j, Mathf.Sin(angle) * j);
                Color   color    = planet.features.GetTileColorForHeight(j, distance);
                AddQuadToMesh(position, angle, color);
            }
        }

        UpdateMesh();
    }
예제 #2
0
 public ShapeGenerator(NoiseSettings noiseSettings, float radius)
 {
     this.radius        = radius;
     noiseFilter        = new NoiseFilter();
     elevationMinMax    = new MinMax();
     this.noiseSettings = noiseSettings;
 }
예제 #3
0
    public PlanetMaker(Vector3 solarSysCenter, float orbit)
    {
        //INIT
        this.planetSettings = GameObject.Find("SpaceMaker").GetComponent <CommonSettings>().planetSettings;
        Vector3 seedPosition = solarSysCenter * orbit * CommonSettings.smallNoiseScale;

        seed = ((int)(seedPosition.x)) | (((int)(seedPosition.y)) << 8) | (((int)(seedPosition.z)) << 16);
        //Debug.Log(seed);
        noise = new NoiseFilter(seed);
        Vector3 position = solarSysCenter + Vector3.left * orbit;

        this.radius = planetSettings.minRadius + noise.newValueFromCoords(position) * planetSettings.radiusMultiplier;
        this.orbit  = orbit;
        this.speed  = noise.newValueFromCoords(position) * planetSettings.speedMultiplier;
        //MAKING
        GameObject planet = new GameObject("Planet");

        initialize(planet);
        generateMesh();

        planet.transform.position   = solarSysCenter + Vector3.left * this.orbit;
        planet.transform.localScale = Vector3.one * radius;

        planet.AddComponent(typeof(PlanetBehavior));
        planet.GetComponent <PlanetBehavior>().center = solarSysCenter;
        planet.GetComponent <PlanetBehavior>().radius = this.orbit;
        planet.GetComponent <PlanetBehavior>().speed  = speed;
    }
예제 #4
0
        //@Override
        public Image process(Image imageIn)
        {
            int   width = imageIn.getWidth();
            int   height = imageIn.getHeight();
            Image clone = imageIn.clone();
            int   r = 0, g = 0, b = 0;

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    int k = NoiseFilter.getRandomInt(1, 123456);
                    //像素块大小
                    int dx = x + k % 19;
                    int dy = y + k % 19;
                    if (dx >= width)
                    {
                        dx = width - 1;
                    }
                    if (dy >= height)
                    {
                        dy = height - 1;
                    }
                    r = clone.getRComponent(dx, dy);
                    g = clone.getGComponent(dx, dy);
                    b = clone.getBComponent(dx, dy);
                    imageIn.setPixelColor(x, y, r, g, b);
                }
            }
            return(imageIn);
        }
예제 #5
0
        public float getValue(Vector3 cubeWorldPosition)
        {
            this.frequency   = 0.5f;
            this.lacunarity  = 2;
            this.offset      = 1;
            this.gain        = 2;
            this.exponent    = 1f;
            this.octaveCount = 4f;

            this.gradient  = GradientColors.Grayscale;
            this.quality   = PrimitiveModule.DefaultQuality;
            this.primitive = NoisePrimitive.ImprovedPerlin;
            this.filter    = NoiseFilter.MultiFractal;

            this.pModule = new ImprovedPerlin();

            this.pModule.Quality = quality;
            this.pModule.Seed    = seed;

            this.fModule = new MultiFractal();

            this.scale = new ScaleBias(fModule, 1f, -0.8f);

            this.fModule.Frequency   = frequency;
            this.fModule.Lacunarity  = lacunarity;
            this.fModule.OctaveCount = octaveCount;
            this.fModule.Offset      = offset;
            this.fModule.Gain        = gain;
            this.fModule.Primitive3D = (IModule3D)pModule;

            this.finalModule = scale;

            return(this.finalModule.GetValue(cubeWorldPosition.X, cubeWorldPosition.Y, cubeWorldPosition.Z));
        }
예제 #6
0
 public PlanetShapeGenerator(PlanetShape settings)
 {
     shapeSettings = settings;
     noiseFilters  = new NoiseFilter[settings.noiseLayers.Length];
     for (int i = 0; i < noiseFilters.Length; ++i)
     {
         noiseFilters[i] = new NoiseFilter(settings.noiseLayers[i].noiseSettings);
     }
 }
 public PlanetShapeGenerator(PlanetShapeSettings settings)
 {
     this.settings = settings;
     noiseFilters  = new NoiseFilter[this.settings.noiseLayers.Length];
     for (int i = 0; i < noiseFilters.Length; i++)
     {
         noiseFilters[i] = new NoiseFilter(settings.noiseLayers[i].noiseSettings);
     }
 }
 public ShapeGenerator(ShapeSettings _shapeSettings)
 {
     this.shapeSettings = _shapeSettings;
     noiseFilters       = new NoiseFilter[shapeSettings.noiseLayers.Length];
     for (int i = 0; i < noiseFilters.Length; i++)
     {
         noiseFilters[i] = new NoiseFilter(shapeSettings.noiseLayers[i].noiseSettings);
     }
 }
예제 #9
0
 public ShapeGenerator(ShapeSettings sett)
 {
     settings     = sett;
     noiseFilters = new NoiseFilter[settings.noiseLayers.Length];
     for (int i = 0; i < settings.noiseLayers.Length; i++)
     {
         noiseFilters[i] = new NoiseFilter(settings.noiseLayers[i].noiseSettings);
     }
 }
예제 #10
0
 /// <summary>
 /// Constructor for the cell.
 /// </summary>
 /// <param name="position">The world position of the cell (left, bottom, back).</param>
 /// <param name="settings">Settings for the cell that should be applied to all cells.</param>
 public Cell(Vector3 position, CellSettings settings, NoiseFilter noise)
 {
     this.position = position;
     this.settings = settings;
     this.noise    = noise;
     worldPoints   = new Vector3[settings.resolution + 1, settings.resolution + 1, settings.resolution + 1];
     localPoints   = new Vector3[settings.resolution + 1, settings.resolution + 1, settings.resolution + 1];
     densities     = new float[settings.resolution + 1, settings.resolution + 1, settings.resolution + 1];
 }
        //@Override
        public Image process(Image imageIn)
        {
            int   width = imageIn.getWidth();
            int   height = imageIn.getHeight();
            Image clone = imageIn.clone();
            int   r = 0, g = 0, b = 0;

            int ratio = imageIn.getWidth() > imageIn.getHeight() ? imageIn.getHeight() * 32768 / imageIn.getWidth() : imageIn.getWidth() * 32768 / imageIn.getHeight();

            // Calculate center, min and max
            int cx   = imageIn.getWidth() >> 1;
            int cy   = imageIn.getHeight() >> 1;
            int max  = cx * cx + cy * cy;
            int min  = (int)(max * (1 - Size));
            int diff = max - min;

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    // Calculate distance to center and adapt aspect ratio
                    int dx = cx - x;
                    int dy = cy - y;
                    if (imageIn.getWidth() > imageIn.getHeight())
                    {
                        dy = (dy * ratio) >> 14;
                    }
                    else
                    {
                        dx = (dx * ratio) >> 14;
                    }
                    int distSq = dx * dx + dy * dy;

                    if (distSq > min)
                    {
                        int k = NoiseFilter.getRandomInt(1, 123456);
                        //像素块大小
                        int pixeldx = x + k % 19;
                        int pixeldy = y + k % 19;
                        if (pixeldx >= width)
                        {
                            pixeldx = width - 1;
                        }
                        if (pixeldy >= height)
                        {
                            pixeldy = height - 1;
                        }
                        r = clone.getRComponent(pixeldx, pixeldy);
                        g = clone.getGComponent(pixeldx, pixeldy);
                        b = clone.getBComponent(pixeldx, pixeldy);
                        imageIn.setPixelColor(x, y, r, g, b);
                    }
                }
            }
            return(imageIn);
        }
예제 #12
0
 public void UpdateSettings(ShapeSettings settings)
 {
     this.settings = settings;
     noiseFilters  = new NoiseFilter[settings.noiseLayers.Length];
     for (int i = 0; i < noiseFilters.Length; i++)
     {
         noiseFilters[i] = new NoiseFilter(settings.noiseLayers[i].noiseSettings);
     }
     elevationMinMax = new MinMax();
 }
예제 #13
0
    public ShapeGenerator(ShapeSettings settings)
    {
        this.settings = settings;
        noiseFilters  = new NoiseFilter[settings.NoiseLayers.Length];

        for (var i = 0; i < noiseFilters.Length; i++)
        {
            noiseFilters[i] = new NoiseFilter(settings.NoiseLayers[i].NoiseSettings);
        }
    }
예제 #14
0
 private void Start()
 {
     //INIT
     spaceSettings = GetComponent <CommonSettings>().spaceSettings;
     currentCenter = worldToCell(transform.position);
     noise         = new NoiseFilter(seed);
     //MAKING
     makeCell(currentCenter);
     visited = new List <Vector3>();
     visited.Add(currentCenter);
 }
예제 #15
0
    /// <summary>
    /// Region constructor.
    /// </summary>
    /// <param name="mesh">Mesh reference.</param>
    /// <param name="resolution">Amount of vertices per side.</param>
    /// <param name="radius">Distance from the center.</param>
    /// <param name="localUp">Direction vector away from the center.</param>
    /// <param name="noiseFilter">Noise filter to be applied.</param>
    public Region(Mesh mesh, int resolution, int radius, Vector3 localUp, NoiseFilter noiseFilter)
    {
        _mesh        = mesh;
        _resolution  = resolution;
        _radious     = radius;
        _localUp     = localUp;
        _noiseFilter = noiseFilter;

        _axisA = new Vector3(localUp.y, localUp.z, localUp.x);
        _axisB = Vector3.Cross(localUp, _axisA);
    }
예제 #16
0
 public SolarSystemMaker(Vector3 coords)
 {
     //INIT
     solarSystemSettings = GameObject.Find("SpaceMaker").GetComponent <CommonSettings>().solarSystemSettings;
     center = coords;
     seed   = ((int)coords.x) | (((int)coords.y) << 8) | (((int)coords.z) << 16);
     noise  = new NoiseFilter(seed);
     //MAKING
     makeSun();
     makePlanets();
 }
    NoiseFilter[] noiseFilters; //NoiseFilter noiseFilter;

    public ShapeGenerator(ShapeSettings settings)
    {
        this.settings = settings;
        noiseFilters  = new NoiseFilter[settings.noiseLayers.Length]; //this.noiseFilter = new NoiseFilter(settings.noiseSettings);

        // Loop over noise filter layers and create noise filters
        for (int i = 0; i < noiseFilters.Length; i++)
        {
            noiseFilters[i] = new NoiseFilter(settings.noiseLayers[i].noiseSettings);
        }
    }
예제 #18
0
    public ClimateGenerator(ClimateSettings _settings, int _seed)
    {
        biomesColors[BiomeType.WATER]                       = Color.blue;
        biomesColors[BiomeType.POLAR_ICE]                   = new Color(255, 255, 255) / 255;
        biomesColors[BiomeType.POLAR_DESERT]                = new Color(192, 192, 192) / 255;
        biomesColors[BiomeType.SUBPOLAR_MOIST_TUNDRA]       = new Color(96, 128, 128) / 255;
        biomesColors[BiomeType.SUBPOLAR_WET_TUNDRA]         = new Color(64, 128, 128) / 255;
        biomesColors[BiomeType.SUBPOLAR_RAIN_TUNDRA]        = new Color(32, 128, 192) / 255;
        biomesColors[BiomeType.SUBPOLAR_DRY_TUNDRA]         = new Color(128, 128, 128) / 255;
        biomesColors[BiomeType.BOREAL_DESERT]               = new Color(160, 160, 128) / 255;
        biomesColors[BiomeType.BOREAL_DRY_SCRUB]            = new Color(128, 160, 128) / 255;
        biomesColors[BiomeType.BOREAL_MOIST_FOREST]         = new Color(96, 160, 128) / 255;
        biomesColors[BiomeType.BOREAL_WET_FOREST]           = new Color(64, 160, 144) / 255;
        biomesColors[BiomeType.BOREAL_RAIN_FOREST]          = new Color(32, 160, 192) / 255;
        biomesColors[BiomeType.COOL_TEMPERATE_MOIST_FOREST] = new Color(96, 192, 128) / 255;
        biomesColors[BiomeType.COOL_TEMPERATE_WET_FOREST]   = new Color(64, 192, 144) / 255;
        biomesColors[BiomeType.COOL_TEMPERATE_RAIN_FOREST]  = new Color(32, 192, 192) / 255;
        biomesColors[BiomeType.COOL_TEMPERATE_STEPPES]      = new Color(128, 192, 128) / 255;
        biomesColors[BiomeType.COOL_TEMPERATE_DESERT]       = new Color(192, 192, 128) / 255;
        biomesColors[BiomeType.COOL_TEMPERATE_DESERT_SCRUB] = new Color(160, 192, 128) / 255;
        biomesColors[BiomeType.WARM_TEMPERATE_MOIST_FOREST] = new Color(96, 224, 128) / 255;
        biomesColors[BiomeType.WARM_TEMPERATE_WET_FOREST]   = new Color(64, 224, 144) / 255;
        biomesColors[BiomeType.WARM_TEMPERATE_RAIN_FOREST]  = new Color(32, 224, 192) / 255;
        biomesColors[BiomeType.WARM_TEMPERATE_THORN_SCRUB]  = new Color(160, 224, 128) / 255;
        biomesColors[BiomeType.WARM_TEMPERATE_DRY_FOREST]   = new Color(128, 224, 128) / 255;
        biomesColors[BiomeType.WARM_TEMPERATE_DESERT]       = new Color(224, 224, 128) / 255;
        biomesColors[BiomeType.WARM_TEMPERATE_DESERT_SCRUB] = new Color(192, 224, 128) / 255;
        biomesColors[BiomeType.SUBTROPICAL_DESERT]          = new Color(240, 240, 128) / 255;
        biomesColors[BiomeType.SUBTROPICAL_DESERT_SCRUB]    = new Color(224, 240, 128) / 255;
        biomesColors[BiomeType.TROPICAL_DESERT]             = new Color(255, 255, 128) / 255;
        biomesColors[BiomeType.TROPICAL_DESERT_SCRUB]       = new Color(224, 255, 128) / 255;
        biomesColors[BiomeType.SUBTROPICAL_THORN_WOODLAND]  = new Color(176, 240, 128) / 255;
        biomesColors[BiomeType.TROPICAL_THORN_WOODLAND]     = new Color(192, 255, 128) / 255;
        biomesColors[BiomeType.TROPICAL_VERY_DRY_FOREST]    = new Color(160, 255, 128) / 255;
        biomesColors[BiomeType.SUBTROPICAL_DRY_FOREST]      = new Color(128, 240, 128) / 255;
        biomesColors[BiomeType.TROPICAL_DRY_FOREST]         = new Color(128, 255, 128) / 255;
        biomesColors[BiomeType.SUBTROPICAL_MOIST_FOREST]    = new Color(96, 240, 128) / 255;
        biomesColors[BiomeType.SUBTROPICAL_WET_FOREST]      = new Color(64, 240, 144) / 255;
        biomesColors[BiomeType.SUBTROPICAL_RAIN_FOREST]     = new Color(32, 240, 176) / 255;
        biomesColors[BiomeType.TROPICAL_MOIST_FOREST]       = new Color(96, 255, 128) / 255;
        biomesColors[BiomeType.TROPICAL_WET_FOREST]         = new Color(64, 255, 144) / 255;
        biomesColors[BiomeType.TROPICAL_RAIN_FOREST]        = new Color(32, 255, 160) / 255;

        settings = _settings;

        noiseFilters = new NoiseFilter[_settings.moistureNoiseLayers.Length];

        for (var i = 0; i < noiseFilters.Length; i++)
        {
            noiseFilters[i] = new NoiseFilter(_settings.moistureNoiseLayers[i].noiseSettings, _seed);
        }

        moistureMinMax = new MinMax();
    }
예제 #19
0
 public SunMaker(Vector3 center)
 {
     //INIT
     sunSettings = GameObject.Find("SpaceMaker").GetComponent <CommonSettings>().sunSettings;
     seed        = ((int)center.x) | (((int)center.y) << 8) | (((int)center.z) << 16);
     noise       = new NoiseFilter(seed);
     this.center = center;
     this.radius = sunSettings.minRadius + noise.newValueFromCoords(this.center) * sunSettings.radiusMultiplier;
     //MAKING
     makeSphere(this.center, radius);
 }
예제 #20
0
    public ShapeGenerator(ShapeSettings settings)
    {
        this.settings = settings;

        var layers = settings.GetNoiseLayers;

        noiseFilters = new NoiseFilter[layers.Count];
        for (int i = 0; i < noiseFilters.Length; i++)
        {
            noiseFilters[i] = new NoiseFilter(layers[i].noiseSettings);
        }
    }
예제 #21
0
    public ShapeGenerator(ShapeSettings _settings, int _seed)
    {
        settings = _settings;

        noiseFilters = new NoiseFilter[_settings.shapeNoiseLayers.Length];

        for (var i = 0; i < noiseFilters.Length; i++)
        {
            noiseFilters[i] = new NoiseFilter(_settings.shapeNoiseLayers[i].noiseSettings, _seed);
        }

        elevationMinMax = new MinMax();
    }
        public OldPhotoFilter()
        {
            blurFx       = new GaussianBlurFilter();
            blurFx.Sigma = 0.3f;

            noiseFx           = new NoiseFilter();
            noiseFx.Intensity = 0.03f;

            vignetteFx      = new VignetteFilter();
            vignetteFx.Size = 0.6f;

            gradientFx = new GradientMapFilter();
            gradientFx.ContrastFactor = 0.3f;
        }
예제 #23
0
        public OldPhotoFilter()
        {
            blurFx = new GaussianBlurFilter();
            blurFx.Sigma = 0.3f;

            noiseFx = new NoiseFilter();
            noiseFx.Intensity = 0.03f;

            vignetteFx = new VignetteFilter();
            vignetteFx.Size = 0.6f;

            gradientFx = new GradientMapFilter();
            gradientFx.ContrastFactor = 0.3f;
        }
    public void CreateMaterial(float min, float max)
    {
        if (texture == null || texture.height != settings.biomeColorSettings.biomes.Length)
        {
            texture = new Texture2D(resolution, settings.biomeColorSettings.biomes.Length);
        }
        biomeNoiseFilter = new NoiseFilter(settings.biomeColorSettings.noise);

        material = new Material(settings.shader);

        material.SetVector("_elivationMinMax", new Vector4(min, max));
        UpdateColor();
        material.SetFloat("_specular", settings.specular);
        material.SetFloat("_smoothness", settings.smoothness);
        material.name = settings.materialName;
    }
예제 #25
0
    public void PopulateTiles()
    {
        NoiseFilter noise = new NoiseFilter(new NoiseSettings());

        foreach (Tile tile in tiles)
        {
            Vector3 center = tile.face.Center.normalized;
            float   value  = noise.Evaluate(center);

            if (value < mapSettings.percentLand)
            {
                tile.type = tileSettings.LAND;
            }
            else
            {
                tile.type = tileSettings.OCEAN;
            }
        }
    }
예제 #26
0
    /// <summary>
    /// Get the maximum elevation value.
    /// </summary>
    public static float GetMaxHeight(TerrainConfig config)
    {
        float maxHeight = 0;

        for (int i = 0; i < config.NoiseFilters.Length; i++)
        {
            NoiseFilter noiseFilter = config.NoiseFilters[i];
            if (noiseFilter.clampingEnabled)
            {
                maxHeight += noiseFilter.strength * Mathf.Clamp(noiseFilter.multiplier, noiseFilter.minValue, noiseFilter.maxValue);
            }
            else
            {
                maxHeight += noiseFilter.strength;
            }
        }

        return(maxHeight);
    }
예제 #27
0
    public void Generate(WorldSettings aWorldSettings, SystemSettings aSystemSettings)
    {
        // Initialise
        transform.position = Vector3.zero;
        worldSettings      = aWorldSettings;
        systemSettings     = aSystemSettings;
        sphereCreator      = new SphereCreator(worldSettings);
        noiseFilter        = new NoiseFilter(worldSettings.noiseSettings);

        // Generate World
        mesh = sphereCreator.CreateSphere();

        foreach (Vertice vertice in mesh.vertices)
        {
            float height = noiseFilter.Evaluate(vertice.position);
            vertice.height = height;
        }

        GetComponent <MeshFilter>().mesh = mesh.Render();
    }
예제 #28
0
    public float biomePercentFromPoint(Vector3 pointOnUnitSphere)
    {
        biomeNoiseFilter = new NoiseFilter(settings.biomeColorSettings.noise);
        float heightPercent = (pointOnUnitSphere.y + 1) / 2f;

        heightPercent += (biomeNoiseFilter.SimpleNoiseValueBiome(pointOnUnitSphere) - settings.biomeColorSettings.noiseOffset) * settings.biomeColorSettings.noiseStrengeth;

        float biomeIndex = 0;
        int   numBiomes  = settings.biomeColorSettings.biomes.Length;
        float blendRange = settings.biomeColorSettings.blendAmount / 2f + 0.00001f;

        for (int i = 0; i < numBiomes; i++)
        {
            float dst    = heightPercent - settings.biomeColorSettings.biomes[i].startHeight;
            float weight = Mathf.InverseLerp(-blendRange, blendRange, dst);
            biomeIndex *= (1 - weight);
            biomeIndex += i * weight;
        }

        return(biomeIndex / Mathf.Max(1, numBiomes - 1));
    }
예제 #29
0
 public void AttachFilter(NoiseFilter _filter)
 {
     if (linkedFilters == null)
     {
         linkedFilters    = new NoiseFilter[1];
         linkedFilters[0] = _filter;
     }
     else
     {
         NoiseFilter[] placeHolder;
         placeHolder = new NoiseFilter[linkedFilters.Length + 1];
         for (int i = 0; i < linkedFilters.Length; i++)
         {
             placeHolder[i] = linkedFilters[i];
         }
         placeHolder[placeHolder.Length - 1] = _filter;
         linkedFilters       = placeHolder;
         _filter.FilterIndex = placeHolder.Length - 1;
         _filter.AttachToBase(this);
     }
 }
예제 #30
0
        //@Override
        public Image process(Image imageIn)
        {
            int   width = imageIn.getWidth();
            int   height = imageIn.getHeight();
            Image clone = imageIn.clone();
            int   r = 0, g = 0, b = 0, xx = 0, yy = 0;

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    int pos = NoiseFilter.getRandomInt(1, 10000) % Model;
                    xx = (x + pos) < width ? (x + pos) : (x - pos) >= 0 ? (x - pos) : x;
                    yy = (y + pos) < height ? (y + pos) : (y - pos) >= 0 ? (y - pos) : y;
                    r  = clone.getRComponent(xx, yy);
                    g  = clone.getGComponent(xx, yy);
                    b  = clone.getBComponent(xx, yy);
                    imageIn.setPixelColor(x, y, r, g, b);
                }
            }
            return(imageIn);
        }
예제 #31
0
    public Vector3 calculatePointOnPlanet(Vector3 pointOnUnitSphere)
    {
        this.noise = new NoiseFilter(seed);
        float altitude = 0;

        //BASE LAYER
        if (settings.baseLayer.active)
        {
            altitude = getAltitudeFromNoiseLayer(settings.baseLayer, pointOnUnitSphere);
        }
        //DETAIL LAYERS
        foreach (NoiseSettings layer in settings.noiseLayers)
        {
            if (altitude > 0 && layer.active)
            {
                altitude += getAltitudeFromNoiseLayer(layer, pointOnUnitSphere);
            }
        }

        Vector3 pointOnPlanet = pointOnUnitSphere * (1 + altitude);

        return(pointOnPlanet);// * radius;
    }