public void LateUpdate()
	{
		if (oblatenessGameObject == null) oblatenessGameObject = SGT_Helper.CreateGameObject("Oblateness", gameObject);
		if (surfaceGameObject    == null) surfaceGameObject    = SGT_Helper.CreateGameObject("Surface", oblatenessGameObject);
		if (atmosphereGameObject == null) atmosphereGameObject = SGT_Helper.CreateGameObject("Atmosphere", oblatenessGameObject);
		if (atmosphereMesh       == null) atmosphereMesh       = new SGT_Mesh();
		if (starObserver         == null) starObserver         = SGT_Helper.FindCamera();
		if (surfaceTexture       == null) surfaceTexture       = new SGT_SurfaceTexture();
		if (surfaceMultiMesh     == null) surfaceMultiMesh     = new SGT_SurfaceMultiMesh();
		
		SGT_Helper.SetParent(oblatenessGameObject, gameObject);
		SGT_Helper.SetLayer(oblatenessGameObject, gameObject.layer);
		SGT_Helper.SetTag(oblatenessGameObject, gameObject.tag);
		
		SGT_Helper.SetParent(surfaceGameObject, oblatenessGameObject);
		SGT_Helper.SetLayer(surfaceGameObject, oblatenessGameObject.layer);
		SGT_Helper.SetTag(surfaceGameObject, oblatenessGameObject.tag);
		
		SGT_Helper.SetParent(atmosphereGameObject, oblatenessGameObject);
		SGT_Helper.SetLayer(atmosphereGameObject, oblatenessGameObject.layer);
		SGT_Helper.SetTag(atmosphereGameObject, oblatenessGameObject.tag);
		
		if (atmosphereDensityColour == null)
		{
			atmosphereDensityColour = new SGT_ColourGradient(false, true);
			atmosphereDensityColour.AddColourNode(new Color(1.0f, 1.0f, 0.0f, 1.0f), 0.0f);
			atmosphereDensityColour.AddColourNode(new Color(1.0f, 0.5f, 0.0f, 1.0f), 0.5f).Locked = true;
			atmosphereDensityColour.AddColourNode(new Color(1.0f, 0.0f, 0.0f, 1.0f), 1.0f);
		}
		
		UpdateTransform();
		UpdateGradient();
		UpdateMaterial();
		UpdateShader();
		
		surfaceMultiMesh.GameObject           = surfaceGameObject;
		surfaceMultiMesh.HasMeshRenderers     = true;
		surfaceMultiMesh.MeshRenderersEnabled = true;
		surfaceMultiMesh.MeshCollidersEnabled = true;
		surfaceMultiMesh.SetSharedMaterials(surfaceMaterials);
		surfaceMultiMesh.Update(gameObject.layer, gameObject.tag);
		
		atmosphereMesh.GameObject          = atmosphereGameObject;
		atmosphereMesh.HasMeshRenderer     = true;
		atmosphereMesh.MeshRendererEnabled = true;
		atmosphereMesh.SharedMaterial      = atmosphereMaterial;
		atmosphereMesh.Update();
		
#if UNITY_EDITOR == true
		SGT_Helper.HideGameObject(oblatenessGameObject);
		
		atmosphereMesh.HideInEditor();
		surfaceMultiMesh.HideInEditor();
#endif
	}
Esempio n. 2
0
    public static SGT_SurfaceTexture Field(string handle, string tooltip, SGT_SurfaceTexture field, bool required = false)
    {
        if (CanDraw == true)
        {
            switch (field.Configuration)
            {
            case SGT_SurfaceConfiguration.Sphere:
            {
                field.SetTexture(ObjectField(handle, tooltip, field.GetTexture(0), required), 0);
            }
            break;

            case SGT_SurfaceConfiguration.Cube:
            {
                var rectP = ReserveField(handle, tooltip);
                var rectN = ReserveField();

                var pX = SGT_RectHelper.HorizontalSlice(rectP, 0.0f / 3.0f, 1.0f / 3.0f);
                var pY = SGT_RectHelper.HorizontalSlice(rectP, 1.0f / 3.0f, 2.0f / 3.0f);
                var pZ = SGT_RectHelper.HorizontalSlice(rectP, 2.0f / 3.0f, 3.0f / 3.0f);

                var nX = SGT_RectHelper.HorizontalSlice(rectN, 0.0f / 3.0f, 1.0f / 3.0f);
                var nY = SGT_RectHelper.HorizontalSlice(rectN, 1.0f / 3.0f, 2.0f / 3.0f);
                var nZ = SGT_RectHelper.HorizontalSlice(rectN, 2.0f / 3.0f, 3.0f / 3.0f);

                field.SetTexture(DrawTextureFieldWithLabel(pX, "X+", 25, field.GetTexture(CubemapFace.PositiveX), required), CubemapFace.PositiveX);
                field.SetTexture(DrawTextureFieldWithLabel(pY, "Y+", 25, field.GetTexture(CubemapFace.PositiveY), required), CubemapFace.PositiveY);
                field.SetTexture(DrawTextureFieldWithLabel(pZ, "Z+", 25, field.GetTexture(CubemapFace.PositiveZ), required), CubemapFace.PositiveZ);

                field.SetTexture(DrawTextureFieldWithLabel(nX, "X-", 25, field.GetTexture(CubemapFace.NegativeX), required), CubemapFace.NegativeX);
                field.SetTexture(DrawTextureFieldWithLabel(nY, "Y-", 25, field.GetTexture(CubemapFace.NegativeY), required), CubemapFace.NegativeY);
                field.SetTexture(DrawTextureFieldWithLabel(nZ, "Z-", 25, field.GetTexture(CubemapFace.NegativeZ), required), CubemapFace.NegativeZ);
            }
            break;
            }
        }

        return(field);
    }
Esempio n. 3
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
    }
Esempio n. 4
0
    public void LateUpdate()
    {
        if (oblatenessGameObject == null)
        {
            oblatenessGameObject = SGT_Helper.CreateGameObject("Oblateness", gameObject);
        }
        if (surfaceGameObject == null)
        {
            surfaceGameObject = SGT_Helper.CreateGameObject("Surface", oblatenessGameObject);
        }
        if (atmosphereGameObject == null)
        {
            atmosphereGameObject = SGT_Helper.CreateGameObject("Atmosphere", oblatenessGameObject);
        }
        if (atmosphereMesh == null)
        {
            atmosphereMesh = new SGT_Mesh();
        }
        if (starObserver == null)
        {
            starObserver = SGT_Helper.FindCamera();
        }
        if (surfaceTexture == null)
        {
            surfaceTexture = new SGT_SurfaceTexture();
        }
        if (surfaceMultiMesh == null)
        {
            surfaceMultiMesh = new SGT_SurfaceMultiMesh();
        }

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

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

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

        if (atmosphereDensityColour == null)
        {
            atmosphereDensityColour = new SGT_ColourGradient(false, true);
            atmosphereDensityColour.AddColourNode(new Color(1.0f, 1.0f, 0.0f, 1.0f), 0.0f);
            atmosphereDensityColour.AddColourNode(new Color(1.0f, 0.5f, 0.0f, 1.0f), 0.5f).Locked = true;
            atmosphereDensityColour.AddColourNode(new Color(1.0f, 0.0f, 0.0f, 1.0f), 1.0f);
        }

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

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

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

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

        atmosphereMesh.HideInEditor();
        surfaceMultiMesh.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
    }