private void AddCelestialBodyLayer(int width, int height, int layerIndex, Color[] colorMap, Texture2D nightGlowMask, CelestialBodySettings celestialBodySettings) { GameObject planetLayer = Instantiate(planetLayerPrefab, transform); planetLayer.name = "Celestial Body Layer " + layerIndex; Texture2D planetLayerTexture = new Texture2D(width, height, TextureFormat.RGBA32, false); planetLayerTexture.filterMode = FilterMode.Point; planetLayerTexture.SetPixels(colorMap); planetLayerTexture.Apply(); CelestialBodyLayer celestialBodyLayer = planetLayer.GetComponent <CelestialBodyLayer>(); celestialBodyLayer.Configure(layerIndex, planetLayerTexture, nightGlowMask, celestialBodySettings.shapeSettings, celestialBodySettings.colorSettings); planetLayer.transform.localPosition = new Vector3(0, 0.01f * layerIndex, 0); }
public void GenerateClouds(int width, int height, CloudSettings cloudSettings) { int cloudPadding = 3; if (cloudPrefab != null && cloudSettings.cloudCentroids > 0 && cloudSettings.cloundCount > 0) { Vector2[] cloudCentroids = new Vector2[cloudSettings.cloudCentroids]; Vector2[] clouds = new Vector2[cloudSettings.cloundCount]; for (int i = 0; i < cloudCentroids.Length; i++) { cloudCentroids[i] = new Vector2(Random.value, Random.value); } for (int i = 0; i < cloudSettings.cloundCount; i++) { int index = Random.Range(0, cloudCentroids.Length - 1); clouds[i] = cloudCentroids[index] + (Random.insideUnitCircle + Vector2.one) / 2 * cloudSettings.cloudDensity; } Texture2D waterMaskTexture = new Texture2D(width, height, TextureFormat.RGBA32, false); waterMaskTexture.filterMode = FilterMode.Point; waterMaskTexture.SetPixels(new Color[width * height]); waterMaskTexture.Apply(); for (int k = 0; k < cloudTextures.Length * cloudPadding; k++) { Texture2D cloudLayerTexture = new Texture2D(width, height, TextureFormat.RGBA32, false); cloudLayerTexture.filterMode = FilterMode.Point; Color[] cloudColors = cloudTextures[k / cloudPadding].GetPixels(); Color[] colors = new Color[width * height]; for (int i = 0; i < clouds.Length; i++) { for (int j = 0; j < cloudColors.Length; j++) { if (cloudColors[j].a == 0) { continue; } int localX = j % cloudTextures[k / cloudPadding].width; int localY = j / cloudTextures[k / cloudPadding].width; int x = ((int)((clouds[i].x * width) % width) + localX) % width; int y = ((int)((clouds[i].y * height) % height) + localY) % height; int index = x * width + y; colors[index] = cloudColors[j] * cloudSettings.cloudTint.Evaluate(k / (float)(cloudTextures.Length * cloudPadding)); } } cloudLayerTexture.SetPixels(colors); cloudLayerTexture.Apply(); CelestialBodyLayer cloud = Instantiate(planetLayerPrefab, transform).GetComponent <CelestialBodyLayer>(); cloud.gameObject.name = "Cloud Layer " + k; cloud.Configure(k, cloudLayerTexture, waterMaskTexture, celestialBodySettings.shapeSettings, celestialBodySettings.colorSettings); //TODO fix to be better cloud.radius = cloudSettings.cloudRadiusStart + cloudSettings.cloudRadiusChange * k; cloud.allowRotate = true; cloud.transform.localPosition = new Vector3(0, 0.01f * k + 0.01f * celestialBodySettings.colorSettings.layers, 0); cloud.tint = cloudSettings.cloudTint.Evaluate(k / (cloudTextures.Length * cloudPadding)); cloud.shadowColor = new Color(0.05288889f, 0.04848149f, 0.119f); } } }