コード例 #1
0
    private PlanetArchetypes.Archetype GetPlanetBlueprint(StarSystem parentSystem)
    {
        PlanetArchetypes.Archetype[] archetypes = PlanetArchetypes.Generate();
        float goldilocksDistance = Distance / parentSystem.Star.HabitableZoneCenter;

        float[] chances = new float[archetypes.Length];

        float sum = 0;

        for (int i = 0; i < archetypes.Length; i++)
        {
            float temp = archetypes[i].GetOccuranceChanceAtDistance(goldilocksDistance);
            chances[i] = temp + sum;
            sum       += temp;
        }

        float pick = Random.Range(0, sum);

        for (int i = 0; i < archetypes.Length; i++)
        {
            if (pick < chances[i] || i + 1 == archetypes.Length)
            {
                return(archetypes[i]);
            }
        }

        return(archetypes[0]);
    }
コード例 #2
0
ファイル: Planet.cs プロジェクト: Bullshitzu/SGU
    private static Texture2D GeneratePlanetDiffuseMap(PlanetArchetypes.Archetype blueprint, Texture2D heightmap)
    {
        //todo: this

        Color[] palette = blueprint.ColorPalette;

        float v;
        Color[] pixelsHeightmap = heightmap.GetPixels();
        Color[] pixels = new Color[textureSize * textureSize];

        for (int y = 0; y < textureSize; y++) {
            for (int x = 0; x < textureSize; x++) {
                v = pixelsHeightmap[x + y * textureSize].grayscale;
                pixels[x + y * textureSize] = Color.Lerp(palette[0], palette[1], v);
            }
        }

        if (blueprint.Type == PlanetArchetypes.PlanetType.Temperate) {
            for (int y = 0; y < textureSize; y++) {
                for (int x = 0; x < textureSize; x++) {

                    v = pixelsHeightmap[x + y * textureSize].grayscale;
                    float h = v;
                    v = 1 - Mathf.Clamp01((v - 0.35f) * 5);

                    Color tempColor = Color.Lerp(pixels[x + y * textureSize], new Color32(11, 36, 56, 255), v);

                    if (!blueprint.HasPoleColor()) {
                        pixels[x + y * textureSize] = tempColor;
                        continue;
                    }

                    float poleMult = (float)y / textureSize;
                    poleMult = Mathf.Clamp01(6.25f * Mathf.Pow(poleMult, 2) - 6.25f * poleMult + 1);

                    pixels[x + y * textureSize] = Color.Lerp(tempColor, blueprint.PolesColor, poleMult+h-0.6f);
                }
            }
        }

        Texture2D temp = new Texture2D(textureSize, textureSize);
        temp.SetPixels(pixels);
        temp.filterMode = FilterMode.Point;
        temp.wrapMode = TextureWrapMode.Clamp;
        temp.Apply();

        return temp;
    }
コード例 #3
0
ファイル: Planet.cs プロジェクト: Bullshitzu/SGU
 private void GeneratePlanetProperties(PlanetArchetypes.Archetype blueprint)
 {
     this.Mass = Random.Range(blueprint.MassRange.x, blueprint.MassRange.y);
     this.TemperatureRange = new Vector2(
         Random.Range(blueprint.TemperatureRange.x, blueprint.TemperatureRange.y),
         Random.Range(blueprint.TemperatureRange.x, blueprint.TemperatureRange.y));
     if (this.TemperatureRange.x > this.TemperatureRange.y)
         this.TemperatureRange = new Vector2(this.TemperatureRange.y, this.TemperatureRange.x);
     this.DayLength = Random.Range(blueprint.DayLengthRange.x, blueprint.DayLengthRange.y);
     this.AtmosphereDensity = Random.Range(blueprint.AtmospherePressureRange.x, blueprint.AtmospherePressureRange.y);
 }
コード例 #4
0
ファイル: Planet.cs プロジェクト: Bullshitzu/SGU
 private static void GeneratePlanetResources(PlanetArchetypes.Archetype blueprint)
 {
     // todo: generate resource maps based on blueprint
 }
コード例 #5
0
ファイル: Planet.cs プロジェクト: Bullshitzu/SGU
    private static Texture2D GeneratePlanetNormalmap(PlanetArchetypes.Archetype blueprint, Texture2D heightmap)
    {
        if (blueprint.Type == PlanetArchetypes.PlanetType.Ice) {

            Color[] pixelsHeightmap = heightmap.GetPixels();
            Color[] pixels = new Color[pixelsHeightmap.Length];

            for (int y = 0; y < textureSize; y++) {
                for (int x = 0; x < textureSize; x++) {
                    float v = pixelsHeightmap[x + y * textureSize].grayscale;
                    v = Mathf.Clamp01(-2.38f * Mathf.Pow(v, 2) + 3.38f * v);
                    pixels[x + y * textureSize] = new Color(v, v, v, 1);
                }
            }

            Texture2D temp = new Texture2D(textureSize, textureSize);
            temp.SetPixels(pixels);
            temp.filterMode = FilterMode.Point;
            temp.Apply();

            return Utility.TextureHelper.GreyscaleToNormal(temp);
        }

        return Utility.TextureHelper.GreyscaleToNormal(heightmap);
    }
コード例 #6
0
ファイル: Planet.cs プロジェクト: Bullshitzu/SGU
    private static Texture2D GeneratePlanetIlluminationMap(PlanetArchetypes.Archetype blueprint, Texture2D heightmap)
    {
        switch (blueprint.Type) {
            case PlanetArchetypes.PlanetType.Lava:
                // todo: add other types that have lava (inferno/toxic/protoplanet...)

                Color[] pixelsHeightmap = heightmap.GetPixels();
                Color[] pixels = new Color[textureSize * textureSize];

                for (int x = 0; x < textureSize; x++) {
                    for (int y = 0; y < textureSize; y++) {

                        float v = pixelsHeightmap[x + y * textureSize].grayscale;
                        v = Mathf.Clamp01((1 - v - 0.5f) * 2);

                        pixels[x + y * textureSize] = new Color(v * 4, v, 0, v);
                    }
                }

                Texture2D temp = new Texture2D(textureSize, textureSize);
                temp.SetPixels(pixels);
                temp.filterMode = FilterMode.Point;
                temp.wrapMode = TextureWrapMode.Clamp;
                temp.Apply();

                return temp;
            default:
                return null;
        }
    }
コード例 #7
0
ファイル: Planet.cs プロジェクト: Bullshitzu/SGU
    private static float[] GeneratePlanetHeightmapData(PlanetArchetypes.Archetype blueprint)
    {
        float[] height = new float[textureSize * textureSize];

        LibNoise.RidgedMultifractal Generator = new LibNoise.RidgedMultifractal();
        blueprint.SetNoiseGenerator(Generator);

        float correctMin = float.MaxValue;
        float correctMax = float.MinValue;

        float currValue;

        for (int y = 0; y < textureSize; y++) {
            for (int x = 0; x < textureSize; x++) {
                currValue = (float)Generator.GetValue((float)x / textureSize, (float)y / textureSize, 1);
                if (currValue < correctMin) correctMin = currValue;
                if (currValue > correctMax) correctMax = currValue;
                height[x + y * textureSize] = currValue;
            }
        }

        float oldValue;

        for (int y = 0; y < textureSize; y++) {
            for (int x = 0; x < textureSize; x++) {

                float mult = (float)x / textureSize;

                oldValue = height[x + y * textureSize];
                currValue = (float)Generator.GetValue(((float)x / textureSize) + 1, (float)y / textureSize, 1);

                float yMult = (float)y / textureSize;
                yMult = Mathf.Clamp01(11.11f * Mathf.Pow(yMult, 2) - 11.11f * yMult + 1);

                height[x + y * textureSize] = Mathf.Lerp(currValue, oldValue, mult);
                height[x + y * textureSize] = Mathf.Lerp(height[x + y * textureSize], 0, yMult);
            }
        }

        for (int y = 0; y < textureSize; y++) {
            for (int x = 0; x < textureSize; x++) {
                height[x + y * textureSize] = (height[x + y * textureSize] - correctMin) / (correctMax - correctMin);
            }
        }

        return height;
    }
コード例 #8
0
ファイル: Planet.cs プロジェクト: Bullshitzu/SGU
    private static Texture2D GeneratePlanetHeightmap(PlanetArchetypes.Archetype blueprint)
    {
        /*
         * SeamlessNoise( float x, float y, float dx, float dy, float xyOffset );
         * where: x, y are normalized coordinates (in [0..1] space).
         * dx, dy are noise scale in x and y axes.
         * xyOffset is noise offset (same offset will result in having the same noise).
         * The method returns a float value in [-1..1] space.
         */

        float[] height = GeneratePlanetHeightmapData(blueprint);

        // todo: add craters depending on atmosphere thickness and mass

        Color[] image = new Color[textureSize * textureSize];

        for (int x = 0; x < textureSize; x++) {
            for (int y = 0; y < textureSize; y++) {
                float currValue = 1 - height[x + y * textureSize];
                image[x + y * textureSize] = new Color(currValue, currValue, currValue, 1);
            }
        }

        Texture2D temp = new Texture2D(textureSize, textureSize);
        temp.SetPixels(image);
        temp.Apply();
        return temp;
    }