public Star(SystemController controller, int seed, GameObject gameObject) : base(controller, gameObject, seed, new CelestialType.Star()) { MeshFilter filter = gameObject.AddComponent <MeshFilter>(); MeshRenderer renderer = gameObject.AddComponent <MeshRenderer>(); filter.mesh = Octahedron.Create(5, radius); Material mat = new Material(controller.materialController.starMaterial); CelestialType starType = new CelestialType.Star(); mat.SetInt("_Temp", (int)Utility.GetRandomBetween(new System.Random(seed), starType.minTemperature, starType.maxTemperature)); renderer.material = mat; renderer.receiveShadows = false; renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; gameObject.transform.localScale = Vector3.one; var light = gameObject.AddComponent <Light>(); light.type = LightType.Point; light.range = 2000000; light.bounceIntensity = 0; light.renderMode = LightRenderMode.ForcePixel; light.intensity = 1; light.shadows = LightShadows.Soft; light.shadowNearPlane = .1f; }
private void CreateStar(Transform parent, float a, float b, float angle, int segment) { float x = Mathf.Cos(Mathf.Deg2Rad * angle) * a; float z = Mathf.Sin(Mathf.Deg2Rad * angle) * b; float deviationA = (outerA - innerA) / segmentCount; float deviationB = (outerB - innerB) / segmentCount; x += (float)Utility.GetRandomBetween(random, -deviationA, deviationA) * 0.9f; z += (float)Utility.GetRandomBetween(random, -deviationB, deviationB) * 0.9f; float abs = new Vector3(x, 0, z).magnitude; float s = Mathf.Clamp((abs - innerB) / (outerB - innerB), 0, 1); float maxheight = GetGalaxyHeight(s) * 10; float y = (float)Utility.GetRandomBetween(random, -maxheight, maxheight); int starSeed = starCount * 10; GameObject star = GameObject.CreatePrimitive(PrimitiveType.Sphere); star.transform.parent = parent; star.transform.localPosition = new Vector3(x, y, z); star.transform.localRotation = Quaternion.identity; CelestialType starType = new CelestialType.Star(); double temperature = Utility.GetRandomBetween(new System.Random(starSeed), starType.minTemperature, starType.maxTemperature); float temp_f = Mathf.Clamp((float)(temperature - starType.minTemperature) / (starType.maxTemperature - starType.minTemperature), 0, 1); Color color = starSpectrum.GetPixel((int)(temp_f * starSpectrum.width), 0); star.name = starSeed.ToString(); Material mat = new Material(starMaterial); mat.SetColor("_Color", Color.black); mat.SetColor("_EmissionColor", color + Color.white); star.GetComponent <Renderer>().material = mat; float scale = (float)Utility.GetRandomBetween(new System.Random(starSeed), 0.5, 1); star.transform.localScale = new Vector3(scale, scale, scale); starCount++; }