示例#1
0
    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);
    }
示例#2
0
    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");
        }
    }
示例#3
0
 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();
     }
 }
示例#4
0
    // 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;
 }
示例#6
0
 private void OnEnable()
 {
     shapeFoldout   = EditorPrefs.GetBool(nameof(shapeFoldout), false);
     shadingFoldout = EditorPrefs.GetBool(nameof(shadingFoldout), false);
     generator      = (CelestialBodyGenerator)target;
 }