コード例 #1
0
    private void GenerateSurface()
    {
        int width  = celestialBodySettings.textureSize;
        int height = celestialBodySettings.textureSize;

        NoiseMapData noiseMapData = GenerateNoiseMap(width, height, celestialBodySettings.noiseSettings);

        CelestialBodyColorMap celestialBodyData = GenerateCelestialBodyColorMap(width, height, celestialBodySettings.colorSettings, noiseMapData);

        Texture2D nightGlowMask = new Texture2D(width, height, TextureFormat.RGBA32, false);

        nightGlowMask.filterMode = FilterMode.Point;
        nightGlowMask.SetPixels(celestialBodyData.nightGlowColorMap);
        nightGlowMask.Apply();

        for (int i = 0; i < celestialBodyData.layerColorMaps.GetLength(0); i++)
        {
            AddCelestialBodyLayer(width, height, i, celestialBodyData.layerColorMaps[i], nightGlowMask, celestialBodySettings);
        }
    }
コード例 #2
0
    private CelestialBodyColorMap GenerateCelestialBodyColorMap(int width, int height, ColorSettings colorSettings, NoiseMapData noiseMapData)
    {
        Color[][] layerColorMaps    = new Color[colorSettings.layers][];
        Color[]   nightGlowColorMap = new Color[width * height];

        for (int i = 0; i < layerColorMaps.Length; i++)
        {
            layerColorMaps[i] = new Color[width * height];
        }

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                float noiseValue = Mathf.InverseLerp(noiseMapData.minValue, noiseMapData.maxValue, noiseMapData.noiseValues[x, y]);

                float minRange = 0;
                float maxRange = 1;

                int index = 0;

                Gradient gradient;
                float    tones       = 1;
                float    toneFalloff = 1;
                bool     isLand      = false;

                if (noiseValue >= colorSettings.waterLevel)
                {
                    if (colorSettings.waterLevel > 0)
                    {
                        minRange = 1 - colorSettings.waterLevel;
                    }

                    gradient = colorSettings.landGradient;
                    tones    = colorSettings.landTones;
                    isLand   = true;
                }
                else
                {
                    maxRange    = colorSettings.waterLevel;
                    gradient    = colorSettings.waterGradient;
                    tones       = colorSettings.waterTones;
                    toneFalloff = colorSettings.toneFalloff;
                    nightGlowColorMap[x + y * width] = Color.white;
                }

                float normalisedValue = Mathf.InverseLerp(minRange, maxRange, noiseValue);

                if (toneFalloff != 1)
                {
                    normalisedValue = Mathf.Pow(normalisedValue, toneFalloff);
                }

                if (colorSettings.reducedTones)
                {
                    normalisedValue = Mathf.Round(normalisedValue * tones) / tones;
                }

                if (isLand)
                {
                    index = (int)Mathf.Round(normalisedValue * (layerColorMaps.GetLength(0) - 1));
                }

                Color textureColor;
                if (colorSettings.useColor)
                {
                    textureColor = gradient.Evaluate(normalisedValue);
                }
                else
                {
                    textureColor = new Color(normalisedValue, normalisedValue, normalisedValue);
                }

                for (int i = 0; i < 1 + index; i++)
                {
                    layerColorMaps[i][x + y * width] = textureColor;
                }
            }
        }

        CelestialBodyColorMap celestialBodyData = new CelestialBodyColorMap();

        celestialBodyData.layerColorMaps    = layerColorMaps;
        celestialBodyData.nightGlowColorMap = nightGlowColorMap;

        return(celestialBodyData);
    }