Esempio n. 1
0
    public void LateUpdate()
    {
        if (surfaceGameObject == null)
        {
            surfaceGameObject = SGT_Helper.CreateGameObject("Surface", gameObject);
        }
        if (atmosphereGameObject == null)
        {
            atmosphereGameObject = SGT_Helper.CreateGameObject("Atmosphere", gameObject);
        }
        if (cloudsGameObject == null)
        {
            cloudsGameObject = SGT_Helper.CreateGameObject("Clouds", gameObject);
        }
        if (surfaceMesh == null)
        {
            surfaceMesh = new SGT_SurfaceMultiMesh();
        }
        if (surfaceTextureDay == null)
        {
            surfaceTextureDay = new SGT_SurfaceTexture();
        }
        if (surfaceTextureNight == null)
        {
            surfaceTextureNight = new SGT_SurfaceTexture();
        }
        if (surfaceTextureNormal == null)
        {
            surfaceTextureNormal = new SGT_SurfaceTexture();
        }
        if (surfaceTextureSpecular == null)
        {
            surfaceTextureSpecular = new SGT_SurfaceTexture();
        }
        if (planetObserver == null)
        {
            planetObserver = SGT_Helper.FindCamera();
        }
        if (planetLightSource == null)
        {
            planetLightSource = SGT_LightSource.Find();
        }

        SGT_Helper.SetParent(surfaceGameObject, gameObject);
        SGT_Helper.SetLayer(surfaceGameObject, gameObject.layer);
        SGT_Helper.SetTag(surfaceGameObject, gameObject.tag);

        SGT_Helper.SetParent(atmosphereGameObject, gameObject);
        SGT_Helper.SetLayer(atmosphereGameObject, gameObject.layer);
        SGT_Helper.SetTag(atmosphereGameObject, gameObject.tag);

        SGT_Helper.SetParent(cloudsGameObject, gameObject);
        SGT_Helper.SetLayer(cloudsGameObject, gameObject.layer);
        SGT_Helper.SetTag(cloudsGameObject, gameObject.tag);

        surfaceTextureDay.Configuration      = surfaceMesh.Configuration;
        surfaceTextureNight.Configuration    = surfaceMesh.Configuration;
        surfaceTextureNormal.Configuration   = surfaceMesh.Configuration;
        surfaceTextureSpecular.Configuration = surfaceMesh.Configuration;

        if (surfaceTextureDay.Modified == true)
        {
            updateShader |= ShaderFlags.SurfaceTextureDay;      surfaceTextureDay.Modified = false;
        }
        if (surfaceTextureNight.Modified == true)
        {
            updateShader |= ShaderFlags.SurfaceTextureNight;    surfaceTextureNight.Modified = false;
        }
        if (surfaceTextureNormal.Modified == true)
        {
            updateShader |= ShaderFlags.SurfaceTextureNormal;   surfaceTextureNormal.Modified = false;
        }
        if (surfaceTextureSpecular.Modified == true)
        {
            updateShader |= ShaderFlags.SurfaceTextureSpecular; surfaceTextureSpecular.Modified = false;
        }

        if (atmosphere == true)
        {
            if (atmosphereMesh == null)
            {
                atmosphereMesh = new SGT_Mesh();
            }
        }
        else
        {
            if (atmosphereMesh != null)
            {
                atmosphereMesh.Clear();
            }
        }

        if (clouds == true)
        {
            if (cloudsMesh == null)
            {
                cloudsMesh = new SGT_SurfaceMultiMesh();
            }
            if (cloudsTexture == null)
            {
                cloudsTexture = new SGT_SurfaceTexture();
            }

            if (cloudsTexture.Modified == true)
            {
                updateShader |= ShaderFlags.CloudsTexture; cloudsTexture.Modified = false;
            }
        }
        else
        {
            if (cloudsTexture != null)
            {
                cloudsTexture = null;
            }
            if (cloudsMesh != null)
            {
                cloudsMesh.Clear();
            }
        }

        if (planetLighting == null)
        {
            planetLighting = new SGT_ColourGradient(false, false);
            planetLighting.AddColourNode(Color.black, 0.45f);
            planetLighting.AddColourNode(Color.white, 0.55f);
        }

        if (atmosphereTwilightColour == null)
        {
            atmosphereTwilightColour = new SGT_ColourGradient(false, true);
            atmosphereTwilightColour.AddAlphaNode(1.0f, 0.45f);
            atmosphereTwilightColour.AddAlphaNode(0.0f, 0.65f);
            atmosphereTwilightColour.AddColourNode(new Color(1.0f, 0.19f, 0.0f, 1.0f), 0.5f);
        }

        if (atmosphereDensityColour == null)
        {
            atmosphereDensityColour = new SGT_ColourGradient(false, true);
            atmosphereDensityColour.AddColourNode(new Color(0.17f, 0.53f, 0.85f), 0.2f);
            atmosphereDensityColour.AddColourNode(Color.white, 0.5f).Locked = true;
            atmosphereDensityColour.AddColourNode(new Color(0.17f, 0.51f, 1.0f), 1.0f);
        }

        if (cloudsLimbColour == null)
        {
            cloudsLimbColour = new SGT_ColourGradient(false, true);
            cloudsLimbColour.AddColourNode(Color.white, 0.5f);
        }

        // Rotate?
        if (Application.isPlaying == true)
        {
            if (cloudsRotationPeriod != 0.0f)
            {
                cloudsGameObject.transform.Rotate(0.0f, SGT_Helper.DegreesPerSecond(cloudsRotationPeriod) * Time.smoothDeltaTime, 0.0f);
            }
        }

        // Update scales
        SGT_Helper.SetLocalScale(surfaceGameObject.transform, surfaceRadius);

        if (atmosphere == true)
        {
            SGT_Helper.SetLocalScale(atmosphereGameObject.transform, AtmosphereRadius);

            // Point atmosphere at camera
            if (planetObserver != null)
            {
                var observerPosition  = planetObserver.transform.position;
                var observerDirection = (observerPosition - gameObject.transform.position).normalized;

                SGT_Helper.SetUp(atmosphereGameObject.transform, observerDirection);
            }
        }

        if (clouds == true)
        {
            SGT_Helper.SetLocalScale(cloudsGameObject.transform, CloudsRadius);

            UpdateCloudsOffset();
        }

        UpdateGradient();
        UpdateTechnique();
        UpdateShader();

        surfaceMesh.GameObject           = surfaceGameObject;
        surfaceMesh.HasMeshRenderers     = true;
        surfaceMesh.MeshRenderersEnabled = true;
        surfaceMesh.MeshCollidersEnabled = true;
        surfaceMesh.SetSharedMaterials(surfaceMaterials);
        surfaceMesh.Update(gameObject.layer, gameObject.tag);

        if (atmosphere == true)
        {
            atmosphereMesh.GameObject          = atmosphereGameObject;
            atmosphereMesh.HasMeshRenderer     = true;
            atmosphereMesh.MeshRendererEnabled = true;
            atmosphereMesh.SharedMaterial      = atmosphereMaterial;
            atmosphereMesh.Update();
        }

        if (clouds == true)
        {
            cloudsMesh.GameObject           = cloudsGameObject;
            cloudsMesh.HasMeshRenderers     = true;
            cloudsMesh.MeshRenderersEnabled = true;
            cloudsMesh.SetSharedMaterials(cloudsMaterials);
            cloudsMesh.Update(gameObject.layer, gameObject.tag);
        }

#if UNITY_EDITOR == true
        surfaceMesh.HideInEditor();
        if (atmosphereMesh != null)
        {
            atmosphereMesh.HideInEditor();
        }
        if (cloudsMesh != null)
        {
            cloudsMesh.HideInEditor();
        }

        SGT_Helper.HideGameObject(atmosphereGameObject);
        SGT_Helper.HideGameObject(cloudsGameObject);
#endif
    }
    public void LateUpdate()
    {
        if (oblatenessGameObject == null) oblatenessGameObject = SGT_Helper.CreateGameObject("Oblateness", gameObject);
        if (atmosphereGameObject == null) atmosphereGameObject = SGT_Helper.CreateGameObject("Atmosphere", oblatenessGameObject);
        if (atmosphereMesh       == null) atmosphereMesh      = new SGT_Mesh();
        if (gasGiantLightSource  == null) gasGiantLightSource = SGT_LightSource.Find();
        if (gasGiantObserver     == null) gasGiantObserver    = SGT_Helper.FindCamera();

        SGT_Helper.SetParent(oblatenessGameObject, gameObject);
        SGT_Helper.SetLayer(oblatenessGameObject, gameObject.layer);
        SGT_Helper.SetTag(oblatenessGameObject, gameObject.tag);

        SGT_Helper.SetParent(atmosphereGameObject, oblatenessGameObject);
        SGT_Helper.SetLayer(atmosphereGameObject, oblatenessGameObject.layer);
        SGT_Helper.SetTag(atmosphereGameObject, oblatenessGameObject.tag);

        if (atmosphereLightingColour == null)
        {
            atmosphereLightingColour = new SGT_ColourGradient(false, false);
            atmosphereLightingColour.AddColourNode(Color.black, 0.4f);
            atmosphereLightingColour.AddColourNode(Color.white, 0.7f);
        }

        if (atmosphereTwilightColour == null)
        {
            atmosphereTwilightColour = new SGT_ColourGradient(false, true);
            atmosphereTwilightColour.AddAlphaNode(1.0f, 0.4f);
            atmosphereTwilightColour.AddAlphaNode(0.0f, 0.5f);
            atmosphereTwilightColour.AddColourNode(Color.red, 0.5f);
        }

        if (atmosphereLimbColour == null)
        {
            atmosphereLimbColour = new SGT_ColourGradient(false, true);
            atmosphereLimbColour.AddAlphaNode(0.0f, 0.75f);
            atmosphereLimbColour.AddAlphaNode(1.0f, 1.0f);
            atmosphereLimbColour.AddColourNode(Color.blue, 0.4f);
        }

        if (shadowAutoUpdate == true)
        {
            switch (shadowType)
            {
                case SGT_ShadowOccluder.Ring:
                {
                    var fill = new SGT_FillRingDimensions();

                    SendMessage("FillRingDimensions", fill, SendMessageOptions.DontRequireReceiver);

                    shadowRadius = fill.Radius;
                    shadowWidth  = fill.Width;
                }
                break;

                case SGT_ShadowOccluder.Planet:
                {
                    if (shadowGameObject != null)
                    {
                        var fill = new SGT_FillFloat();

                        shadowGameObject.SendMessage("FillShadowRadius", fill, SendMessageOptions.DontRequireReceiver);

                        shadowRadius = fill.Float;
                    }
                }
                break;
            }
        }

        UpdateTransform();
        UpdateGradient();
        UpdateMaterial();
        UpdateShader();

        // Update mesh
        atmosphereMesh.GameObject          = atmosphereGameObject;
        atmosphereMesh.HasMeshRenderer     = true;
        atmosphereMesh.MeshRendererEnabled = true;
        atmosphereMesh.SharedMaterial      = atmosphereMaterial;
        atmosphereMesh.Update();

        #if UNITY_EDITOR == true
        SGT_Helper.HideGameObject(oblatenessGameObject);

        atmosphereMesh.HideInEditor();
        #endif
    }
Esempio n. 3
0
    public void LateUpdate()
    {
        if (oblatenessGameObject == null)
        {
            oblatenessGameObject = SGT_Helper.CreateGameObject("Oblateness", gameObject);
        }
        if (atmosphereGameObject == null)
        {
            atmosphereGameObject = SGT_Helper.CreateGameObject("Atmosphere", oblatenessGameObject);
        }
        if (atmosphereMesh == null)
        {
            atmosphereMesh = new SGT_Mesh();
        }
        if (gasGiantLightSource == null)
        {
            gasGiantLightSource = SGT_LightSource.Find();
        }
        if (gasGiantObserver == null)
        {
            gasGiantObserver = SGT_Helper.FindCamera();
        }

        SGT_Helper.SetParent(oblatenessGameObject, gameObject);
        SGT_Helper.SetLayer(oblatenessGameObject, gameObject.layer);
        SGT_Helper.SetTag(oblatenessGameObject, gameObject.tag);

        SGT_Helper.SetParent(atmosphereGameObject, oblatenessGameObject);
        SGT_Helper.SetLayer(atmosphereGameObject, oblatenessGameObject.layer);
        SGT_Helper.SetTag(atmosphereGameObject, oblatenessGameObject.tag);

        if (atmosphereLightingColour == null)
        {
            atmosphereLightingColour = new SGT_ColourGradient(false, false);
            atmosphereLightingColour.AddColourNode(Color.black, 0.4f);
            atmosphereLightingColour.AddColourNode(Color.white, 0.7f);
        }

        if (atmosphereTwilightColour == null)
        {
            atmosphereTwilightColour = new SGT_ColourGradient(false, true);
            atmosphereTwilightColour.AddAlphaNode(1.0f, 0.4f);
            atmosphereTwilightColour.AddAlphaNode(0.0f, 0.5f);
            atmosphereTwilightColour.AddColourNode(Color.red, 0.5f);
        }

        if (atmosphereLimbColour == null)
        {
            atmosphereLimbColour = new SGT_ColourGradient(false, true);
            atmosphereLimbColour.AddAlphaNode(0.0f, 0.75f);
            atmosphereLimbColour.AddAlphaNode(1.0f, 1.0f);
            atmosphereLimbColour.AddColourNode(Color.blue, 0.4f);
        }

        if (shadowAutoUpdate == true)
        {
            switch (shadowType)
            {
            case SGT_ShadowOccluder.Ring:
            {
                var fill = new SGT_FillRingDimensions();

                SendMessage("FillRingDimensions", fill, SendMessageOptions.DontRequireReceiver);

                shadowRadius = fill.Radius;
                shadowWidth  = fill.Width;
            }
            break;

            case SGT_ShadowOccluder.Planet:
            {
                if (shadowGameObject != null)
                {
                    var fill = new SGT_FillFloat();

                    shadowGameObject.SendMessage("FillShadowRadius", fill, SendMessageOptions.DontRequireReceiver);

                    shadowRadius = fill.Float;
                }
            }
            break;
            }
        }

        UpdateTransform();
        UpdateGradient();
        UpdateMaterial();
        UpdateShader();

        // Update mesh
        atmosphereMesh.GameObject          = atmosphereGameObject;
        atmosphereMesh.HasMeshRenderer     = true;
        atmosphereMesh.MeshRendererEnabled = true;
        atmosphereMesh.SharedMaterial      = atmosphereMaterial;
        atmosphereMesh.Update();

#if UNITY_EDITOR == true
        SGT_Helper.HideGameObject(oblatenessGameObject);

        atmosphereMesh.HideInEditor();
#endif
    }
    public void LateUpdate()
    {
        if (surfaceGameObject      == null) surfaceGameObject      = SGT_Helper.CreateGameObject("Surface", gameObject);
        if (atmosphereGameObject   == null) atmosphereGameObject   = SGT_Helper.CreateGameObject("Atmosphere", gameObject);
        if (cloudsGameObject       == null) cloudsGameObject       = SGT_Helper.CreateGameObject("Clouds", gameObject);
        if (surfaceMesh            == null) surfaceMesh            = new SGT_SurfaceMultiMesh();
        if (surfaceTextureDay      == null) surfaceTextureDay      = new SGT_SurfaceTexture();
        if (surfaceTextureNight    == null) surfaceTextureNight    = new SGT_SurfaceTexture();
        if (surfaceTextureNormal   == null) surfaceTextureNormal   = new SGT_SurfaceTexture();
        if (surfaceTextureSpecular == null) surfaceTextureSpecular = new SGT_SurfaceTexture();
        if (planetObserver         == null) planetObserver         = SGT_Helper.FindCamera();
        if (planetLightSource      == null) planetLightSource      = SGT_LightSource.Find();

        SGT_Helper.SetParent(surfaceGameObject, gameObject);
        SGT_Helper.SetLayer(surfaceGameObject, gameObject.layer);
        SGT_Helper.SetTag(surfaceGameObject, gameObject.tag);

        SGT_Helper.SetParent(atmosphereGameObject, gameObject);
        SGT_Helper.SetLayer(atmosphereGameObject, gameObject.layer);
        SGT_Helper.SetTag(atmosphereGameObject, gameObject.tag);

        SGT_Helper.SetParent(cloudsGameObject, gameObject);
        SGT_Helper.SetLayer(cloudsGameObject, gameObject.layer);
        SGT_Helper.SetTag(cloudsGameObject, gameObject.tag);

        surfaceTextureDay.Configuration      = surfaceMesh.Configuration;
        surfaceTextureNight.Configuration    = surfaceMesh.Configuration;
        surfaceTextureNormal.Configuration   = surfaceMesh.Configuration;
        surfaceTextureSpecular.Configuration = surfaceMesh.Configuration;

        if (surfaceTextureDay.Modified      == true) { updateShader |= ShaderFlags.SurfaceTextureDay;      surfaceTextureDay.Modified      = false; }
        if (surfaceTextureNight.Modified    == true) { updateShader |= ShaderFlags.SurfaceTextureNight;    surfaceTextureNight.Modified    = false; }
        if (surfaceTextureNormal.Modified   == true) { updateShader |= ShaderFlags.SurfaceTextureNormal;   surfaceTextureNormal.Modified   = false; }
        if (surfaceTextureSpecular.Modified == true) { updateShader |= ShaderFlags.SurfaceTextureSpecular; surfaceTextureSpecular.Modified = false; }

        if (atmosphere == true)
        {
            if (atmosphereMesh == null) atmosphereMesh = new SGT_Mesh();
        }
        else
        {
            if (atmosphereMesh != null) atmosphereMesh.Clear();
        }

        if (clouds == true)
        {
            if (cloudsMesh    == null) cloudsMesh    = new SGT_SurfaceMultiMesh();
            if (cloudsTexture == null) cloudsTexture = new SGT_SurfaceTexture();

            if (cloudsTexture.Modified == true) { updateShader |= ShaderFlags.CloudsTexture; cloudsTexture.Modified = false; }
        }
        else
        {
            if (cloudsTexture != null) cloudsTexture = null;
            if (cloudsMesh    != null) cloudsMesh.Clear();
        }

        if (planetLighting == null)
        {
            planetLighting = new SGT_ColourGradient(false, false);
            planetLighting.AddColourNode(Color.black, 0.45f);
            planetLighting.AddColourNode(Color.white, 0.55f);
        }

        if (atmosphereTwilightColour == null)
        {
            atmosphereTwilightColour = new SGT_ColourGradient(false, true);
            atmosphereTwilightColour.AddAlphaNode(1.0f, 0.45f);
            atmosphereTwilightColour.AddAlphaNode(0.0f, 0.65f);
            atmosphereTwilightColour.AddColourNode(new Color(1.0f, 0.19f, 0.0f, 1.0f), 0.5f);
        }

        if (atmosphereDensityColour == null)
        {
            atmosphereDensityColour = new SGT_ColourGradient(false, true);
            atmosphereDensityColour.AddColourNode(new Color(0.17f, 0.53f, 0.85f), 0.2f);
            atmosphereDensityColour.AddColourNode(Color.white, 0.5f).Locked = true;
            atmosphereDensityColour.AddColourNode(new Color(0.17f, 0.51f, 1.0f), 1.0f);
        }

        if (cloudsLimbColour == null)
        {
            cloudsLimbColour = new SGT_ColourGradient(false, true);
            cloudsLimbColour.AddColourNode(Color.white, 0.5f);
        }

        // Rotate?
        if (Application.isPlaying == true)
        {
            if (cloudsRotationPeriod != 0.0f)
            {
                cloudsGameObject.transform.Rotate(0.0f, SGT_Helper.DegreesPerSecond(cloudsRotationPeriod) * Time.smoothDeltaTime, 0.0f);
            }
        }

        // Update scales
        SGT_Helper.SetLocalScale(surfaceGameObject.transform, surfaceRadius);

        if (atmosphere == true)
        {
            SGT_Helper.SetLocalScale(atmosphereGameObject.transform, AtmosphereRadius);

            // Point atmosphere at camera
            if (planetObserver != null)
            {
                var observerPosition  = planetObserver.transform.position;
                var observerDirection = (observerPosition - gameObject.transform.position).normalized;

                SGT_Helper.SetUp(atmosphereGameObject.transform, observerDirection);
            }
        }

        if (clouds == true)
        {
            SGT_Helper.SetLocalScale(cloudsGameObject.transform, CloudsRadius);

            UpdateCloudsOffset();
        }

        UpdateGradient();
        UpdateTechnique();
        UpdateShader();

        surfaceMesh.GameObject           = surfaceGameObject;
        surfaceMesh.HasMeshRenderers     = true;
        surfaceMesh.MeshRenderersEnabled = true;
        surfaceMesh.MeshCollidersEnabled = true;
        surfaceMesh.SetSharedMaterials(surfaceMaterials);
        surfaceMesh.Update(gameObject.layer, gameObject.tag);

        if (atmosphere == true)
        {
            atmosphereMesh.GameObject          = atmosphereGameObject;
            atmosphereMesh.HasMeshRenderer     = true;
            atmosphereMesh.MeshRendererEnabled = true;
            atmosphereMesh.SharedMaterial      = atmosphereMaterial;
            atmosphereMesh.Update();
        }

        if (clouds == true)
        {
            cloudsMesh.GameObject           = cloudsGameObject;
            cloudsMesh.HasMeshRenderers     = true;
            cloudsMesh.MeshRenderersEnabled = true;
            cloudsMesh.SetSharedMaterials(cloudsMaterials);
            cloudsMesh.Update(gameObject.layer, gameObject.tag);
        }

        #if UNITY_EDITOR == true
        surfaceMesh.HideInEditor();
        if (atmosphereMesh != null) atmosphereMesh.HideInEditor();
        if (cloudsMesh     != null) cloudsMesh.HideInEditor();

        SGT_Helper.HideGameObject(atmosphereGameObject);
        SGT_Helper.HideGameObject(cloudsGameObject);
        #endif
    }