public void UpdateSettings(CelestialBodyGenerator generator, Shader shader) { if (material == null || material.shader != shader) { material = new Material(shader); } if (light == null) { light = GameObject.FindObjectOfType <SunShadowCaster> ()?.GetComponent <Light> (); } Vector3 centre = generator.transform.position; float radius = generator.GetOceanRadius(); material.SetVector("oceanCentre", centre); material.SetFloat("oceanRadius", radius); material.SetFloat("planetScale", generator.BodyScale); if (light) { material.SetVector("dirToSun", -light.transform.forward); } else { material.SetVector("dirToSun", Vector3.up); Debug.Log("No SunShadowCaster found"); } generator.body.shading.SetOceanProperties(material); }
public void UpdateSettings(CelestialBodyGenerator generator) { Shader shader = generator.body.shading.atmosphereSettings.atmosphereShader; if (material == null || material.shader != shader) { material = new Material(shader); } if (light == null) { light = GameObject.FindObjectOfType <SunShadowCaster> ()?.GetComponent <Light> (); } //generator.shading.SetAtmosphereProperties (material); generator.body.shading.atmosphereSettings.SetProperties(material, generator.BodyScale); material.SetVector("planetCentre", generator.transform.position); //material.SetFloat ("atmosphereRadius", (1 + 0.5f) * generator.BodyScale); material.SetFloat("oceanRadius", generator.GetOceanRadius()); if (light) { Vector3 dirFromPlanetToSun = (light.transform.position - generator.transform.position).normalized; //Debug.Log(dirFromPlanetToSun); material.SetVector("dirToSun", dirFromPlanetToSun); } else { material.SetVector("dirToSun", Vector3.up); Debug.Log("No SunShadowCaster found"); } }
public EffectHolder(CelestialBodyGenerator generator) { this.generator = generator; if (generator.body.shading.hasOcean && generator.body.shading.oceanSettings) { oceanEffect = new OceanEffect(); } if (generator.body.shading.hasAtmosphere && generator.body.shading.atmosphereSettings) { atmosphereEffect = new AtmosphereEffect(); } }
// void DebugLODInfo () { // if (debugBody && debug) { // float h = CalculateScreenHeight (debugBody); // int index = CalculateLODIndex (h); // Debug.Log ($"Screen height of {debugBody.name}: {h} (lod = {index})"); // } // } float CalculateScreenHeight(CelestialBodyGenerator body) { if (cam == null) { cam = Camera.main; camT = cam.transform; } Quaternion originalRot = camT.rotation; Vector3 bodyCentre = body.transform.position; camT.LookAt(bodyCentre); var radius = body.transform.localScale.x; Vector3 viewA = cam.WorldToViewportPoint(bodyCentre - camT.up * radius); Vector3 viewB = cam.WorldToViewportPoint(bodyCentre + camT.up * radius); float screenHeight = Mathf.Abs(viewA.y - viewB.y); camT.rotation = originalRot; return(screenHeight); }
private void OnEnable() { planetGenerator = (CelestialBodyGenerator)target; }
private void OnEnable() { shapeFoldout = EditorPrefs.GetBool(nameof(shapeFoldout), false); shadingFoldout = EditorPrefs.GetBool(nameof(shadingFoldout), false); generator = (CelestialBodyGenerator)target; }