Exemple #1
0
    public void Regenerate()
    {
        if (modified == false)
        {
            CheckForModifications();
        }

        if (modified == true)
        {
            modified           = false;
            generatedRotations = null;

            SGT_Helper.DestroyObject(generatedMesh);

            if (sliced == true)
            {
                GenerateSliced();
            }
            else
            {
                GenerateStretched();
            }

            if (ringMesh != null)
            {
                ringMesh.SharedMesh = generatedMesh;
                UpdateRingRotations();
            }
        }
    }
    private void UpdateMaterial()
    {
        var targetCoronaTechnique = "Variant";

        if (cullNear == true)
        {
            targetCoronaTechnique += "CullNear";
        }

        if (coronaPerPixel == true)
        {
            targetCoronaTechnique += "PerPixel";
        }

        if (meshType == Type.Ring)
        {
            targetCoronaTechnique += "Ring";
        }

        // Update surface?
        if (coronaTechnique != targetCoronaTechnique || coronaMaterial == null)
        {
            SGT_Helper.DestroyObject(coronaMaterial);

            coronaTechnique = targetCoronaTechnique;
            coronaMaterial  = SGT_Helper.CreateMaterial("Hidden/SGT/Corona/" + coronaTechnique, coronaRenderQueue);
        }
        else
        {
            SGT_Helper.SetRenderQueue(coronaMaterial, coronaRenderQueue);
        }
    }
    public void LateUpdate()
    {
        Color volumetricColour;

        if (SGT_GasGiant.ColourToPoint(Camera.main.transform.position, transform.position, 1.0f, false, false, out volumetricColour) == true)
        {
            if (probeMaterial == null)
            {
                probeMaterial = SGT_Helper.CreateMaterial("Hidden/SGT/Fog/Variant", probeRenderQueue);
            }

            probeMaterial.SetColor("fogColour", volumetricColour);

            SGT_Helper.InsertSharedMaterial(GetComponent <Renderer>(), probeMaterial, probeRecursive);

            SGT_Helper.SetRenderQueue(probeMaterial, probeRenderQueue);
        }
        else
        {
            if (probeMaterial != null)
            {
                SGT_Helper.RemoveSharedMaterial(GetComponent <Renderer>(), probeMaterial, probeRecursive);

                probeMaterial = SGT_Helper.DestroyObject(probeMaterial);
            }
        }
    }
    public static SGT_ColourGradient Field(string handle, string tooltip, SGT_ColourGradient field, bool isField = true)
    {
        if (CanDraw == true && field != null)
        {
            var borderRect   = ReserveField(handle, tooltip);
            var gradientRect = SGT_RectHelper.RemovePx(borderRect, 3.0f);
            var borderStyle  = EditorStyles.objectFieldThumb;
            var overlayStyle = (GUIStyle)(EditorStyles.objectFieldThumb.name + "Overlay2");

            gradientRect.xMax -= 4.0f;

            var colours = field.CalculateColours(0.0f, 1.0f, 256);
            var texture = SGT_ColourGradient.AllocateTexture(256);

            for (var x = 0; x < 256; x++)
            {
                texture.SetPixel(x, 0, colours[x]);
            }

            texture.Apply();

            GUI.Box(borderRect, string.Empty, borderStyle);
            DrawTiledTexture(gradientRect, SGT_Helper.CheckerTexture);
            GUI.DrawTexture(gradientRect, texture);

            SGT_Helper.DestroyObject(texture);

            if (GUI.Button(borderRect, "Edit", overlayStyle) == true)
            {
                SGT_AuxWindow_ColourGradient.Create(field, isField);
            }
        }

        return(field);
    }
Exemple #5
0
    private void UpdateMaterial()
    {
        var targetAtmosphereTechnique = "Variant";

        if (gasGiantObserver != null)
        {
            if (InsideGasGiant(gasGiantObserver.transform.position) == false)
            {
                targetAtmosphereTechnique += "Outer";
            }
        }

        if (shadow == true)
        {
            switch (shadowType)
            {
            case SGT_ShadowOccluder.Ring:   targetAtmosphereTechnique += "RingShadow";   break;

            case SGT_ShadowOccluder.Planet: targetAtmosphereTechnique += "PlanetShadow"; break;
            }
        }

        // Update surface?
        if (atmosphereMaterial == null || atmosphereTechnique != targetAtmosphereTechnique)
        {
            SGT_Helper.DestroyObject(atmosphereMaterial);

            atmosphereTechnique = targetAtmosphereTechnique;
            atmosphereMaterial  = SGT_Helper.CreateMaterial("Hidden/SGT/GasGiant/" + atmosphereTechnique, atmosphereRenderQueue);
        }
        else
        {
            SGT_Helper.SetRenderQueue(atmosphereMaterial, atmosphereRenderQueue);
        }
    }
Exemple #6
0
    private void UpdateTechnique()
    {
        var targetTechnique = "Variant";

        if (shadow == true)
        {
            targetTechnique += "Shadow";
        }

        if (spin == true)
        {
            targetTechnique += "Spin";
        }

        if (technique != targetTechnique || ringMaterial == null)
        {
            SGT_Helper.DestroyObject(ringMaterial);

            technique    = targetTechnique;
            ringMaterial = SGT_Helper.CreateMaterial("Hidden/SGT/AsteroidRing/" + technique, ringRenderQueue);
        }
        else
        {
            SGT_Helper.SetRenderQueue(ringMaterial, ringRenderQueue);
        }
    }
 public void DestroyMesh()
 {
     if (sharedMesh != null)
     {
         sharedMesh = SGT_Helper.DestroyObject(sharedMesh);
     }
 }
Exemple #8
0
    public new void OnDestroy()
    {
        base.OnDestroy();

        SGT_Helper.DestroyGameObject(skysphereGameObject);
        SGT_Helper.DestroyObject(skysphereMaterial);
    }
Exemple #9
0
    public new void OnDestroy()
    {
        base.OnDestroy();

        SGT_Helper.DestroyGameObject(dust);
        SGT_Helper.DestroyObject(dustMaterial);
        SGT_Helper.DestroyObject(generatedMesh);
    }
    public new void OnDestroy()
    {
        base.OnDestroy();

        SGT_Helper.DestroyObject(ringGameObject);
        SGT_Helper.DestroyObjects(generatedMeshes);
        SGT_Helper.DestroyObject(ringMaterial);
    }
    public new void OnDestroy()
    {
        base.OnDestroy();

        SGT_Helper.DestroyGameObject(starfieldGameObject);
        SGT_Helper.DestroyObject(starfieldMaterial);
        SGT_Helper.DestroyObjects(meshes);
    }
Exemple #12
0
    public void Start()
    {
        if (GetComponent <Rigidbody>() != null)
        {
            GetComponent <Rigidbody>().velocity = initialVelocity;
        }

        SGT_Helper.DestroyObject(this);
    }
Exemple #13
0
    public new void OnDestroy()
    {
        base.OnDestroy();

        SGT_Helper.DestroyGameObject(atmosphereGameObject);
        SGT_Helper.DestroyGameObject(oblatenessGameObject);
        SGT_Helper.DestroyObject(lightingTexture);
        SGT_Helper.DestroyObject(atmosphereMaterial);
    }
    public void Start()
    {
        if (rigidbody != null)
        {
            rigidbody.velocity = initialVelocity;
        }

        SGT_Helper.DestroyObject(this);
    }
Exemple #15
0
    public new void OnDestroy()
    {
        base.OnDestroy();

        SGT_Helper.DestroyGameObject(surfaceGameObject);
        SGT_Helper.DestroyGameObject(oblatenessGameObject);
        SGT_Helper.DestroyGameObject(atmosphereGameObject);
        SGT_Helper.DestroyObjects(surfaceMaterials);
        SGT_Helper.DestroyObject(atmosphereMaterial);
        SGT_Helper.DestroyObject(atmosphereTexture);
        SGT_Helper.DestroyObject(atmosphereSurfaceTexture);
    }
    public SGT_Mesh Clear()
    {
        if (meshFilter != null)
        {
            meshFilter = SGT_Helper.DestroyObject(meshFilter);
        }
        if (meshRenderer != null)
        {
            meshRenderer = SGT_Helper.DestroyObject(meshRenderer);
        }
        if (meshCollider != null)
        {
            meshCollider = SGT_Helper.DestroyObject(meshCollider);
        }

        return(null);
    }
Exemple #17
0
    private void UpdateMaterial()
    {
        var targetSkysphereTechnique = "Variant";

        // Update surface?
        if (skysphereMaterial == null || skysphereTechnique != targetSkysphereTechnique)
        {
            SGT_Helper.DestroyObject(skysphereMaterial);

            skysphereTechnique = targetSkysphereTechnique;
            skysphereMaterial  = SGT_Helper.CreateMaterial("Hidden/SGT/Skysphere/" + skysphereTechnique, skysphereRenderQueue);
        }
        else
        {
            SGT_Helper.SetRenderQueue(skysphereMaterial, skysphereRenderQueue);
        }
    }
Exemple #18
0
    public new void OnDestroy()
    {
        base.OnDestroy();

        SGT_Helper.DestroyGameObject(surfaceGameObject);
        SGT_Helper.DestroyGameObject(atmosphereGameObject);
        SGT_Helper.DestroyGameObject(cloudsGameObject);

        SGT_Helper.DestroyObjects(surfaceMaterials);
        SGT_Helper.DestroyObject(atmosphereMaterial);
        SGT_Helper.DestroyObjects(cloudsMaterials);

        SGT_Helper.DestroyObject(surfaceLightingTexture);
        SGT_Helper.DestroyObject(atmosphereTexture);
        SGT_Helper.DestroyObject(atmosphereSurfaceTexture);
        SGT_Helper.DestroyObject(cloudsLightingTexture);
    }
    private void UpdateMaterial()
    {
        var targetSurfaceTechnique    = "Variant";
        var targetAtmosphereTechnique = "Variant";

        if (starObserver != null)
        {
            if (InsideAtmosphere(starObserver.transform.position) == false)
            {
                targetSurfaceTechnique    += "Outer";
                targetAtmosphereTechnique += "Outer";
            }
        }

        if (atmosphereSurfacePerPixel == true)
        {
            targetSurfaceTechnique += "PerPixel";
        }

        // Update surface?
        if (surfaceMaterials == null || (surfaceTechnique != targetSurfaceTechnique || SGT_ArrayHelper.ContainsSomething(surfaceMaterials) == false || surfaceMaterials.Length != SGT_SurfaceConfiguration_.SurfaceCount(SurfaceConfiguration)))
        {
            SGT_Helper.DestroyObjects(surfaceMaterials);

            surfaceTechnique = targetSurfaceTechnique;
            surfaceMaterials = SGT_SurfaceConfiguration_.CreateMaterials(surfaceMultiMesh.Configuration, "Hidden/SGT/StarSurface/" + surfaceTechnique, surfaceRenderQueue);
        }
        else
        {
            SGT_Helper.SetRenderQueues(surfaceMaterials, surfaceRenderQueue);
        }

        // Update atmosphere?
        if (atmosphereTechnique != targetAtmosphereTechnique || atmosphereMaterial == null)
        {
            SGT_Helper.DestroyObject(atmosphereMaterial);

            atmosphereTechnique = targetAtmosphereTechnique;
            atmosphereMaterial  = SGT_Helper.CreateMaterial("Hidden/SGT/StarAtmosphere/" + atmosphereTechnique, atmosphereRenderQueue);
        }
        else
        {
            SGT_Helper.SetRenderQueue(atmosphereMaterial, atmosphereRenderQueue);
        }
    }
Exemple #20
0
    private void UpdateMaterial()
    {
        var targetStarfieldTechnique = "Variant";

        if (starfieldMaterial != null && starfieldTechnique != targetStarfieldTechnique)
        {
            starfieldMaterial = SGT_Helper.DestroyObject(starfieldMaterial);
        }

        // New material?
        if (starfieldMaterial == null)
        {
            starfieldTechnique = targetStarfieldTechnique;
            starfieldMaterial  = SGT_Helper.CreateMaterial("Hidden/SGT/Starfield/" + starfieldTechnique, starfieldRenderQueue);
        }
        else
        {
            SGT_Helper.SetRenderQueue(starfieldMaterial, starfieldRenderQueue);
        }
    }
    public void Awake()
    {
        var instances = SGT_Helper.FindAll <T>();

        if (instances.Length > 1)
        {
            Debug.LogWarning("An instance of " + typeof(T).Name + " already exists!");
            Debug.Log("Removing other " + (instances.Length - 1) + " instance(s) of " + typeof(T).Name);

            // Destroy other instances
            foreach (var i in instances)
            {
                if (i != this)
                {
                    SGT_Helper.DestroyObject(i);
                }
            }
        }

        instance = (T)this;
    }
Exemple #22
0
    private void UpdateGradient()
    {
        if (atmosphereLightingColour.Modified == true || atmosphereTwilightColour.Modified == true || atmosphereLimbColour.Modified == true)
        {
            lightingTexture = SGT_Helper.DestroyObject(lightingTexture);
        }

        atmosphereLightingColour.Modified = false;
        atmosphereTwilightColour.Modified = false;
        atmosphereLimbColour.Modified     = false;

        if (lightingTexture == null)
        {
            var lightingColours = atmosphereLightingColour.CalculateColours(0.0f, 1.0f, (int)lutSize);
            var twilightColours = atmosphereTwilightColour.CalculateColours(0.0f, 1.0f, (int)lutSize);
            var limbColours     = atmosphereLimbColour.CalculateColours(0.0f, 1.0f, (int)lutSize);

            lightingTexture = SGT_ColourGradient.AllocateTexture((int)lutSize, (int)lutSize);

            for (var y = 0; y < (int)lutSize; y++)
            {
                var limbPixel = limbColours[y];

                for (var x = 0; x < (int)lutSize; x++)
                {
                    var lightingPixel = lightingColours[x];
                    var twilightPixel = twilightColours[x];
                    var colour        = Color.white;

                    colour = SGT_Helper.AlphaBlend(colour, twilightPixel);
                    colour = SGT_Helper.AlphaBlend(colour, limbPixel);
                    colour = colour * lightingPixel;

                    lightingTexture.SetPixel(x, y, colour);
                }
            }

            lightingTexture.Apply();
        }
    }
    private void UpdateMaterial()
    {
        var targetTechnique = "Variant";

        if (tiled == false)
        {
            targetTechnique += "Stretched";
        }

        if (shadow == true)
        {
            targetTechnique += "Shadow";
        }

        if (lit == true)
        {
            targetTechnique += "Lit";
        }

        if (scattering == true)
        {
            targetTechnique += "Scattering";
        }

        if (ringMaterial == null || technique != targetTechnique)
        {
            SGT_Helper.DestroyObject(ringMaterial);

            technique    = targetTechnique;
            ringMaterial = SGT_Helper.CreateMaterial("Hidden/SGT/Ring/" + technique, renderQueue);

            ringMesh.SharedMaterial = ringMaterial;
        }
        else
        {
            SGT_Helper.SetRenderQueue(ringMaterial, renderQueue);
        }
    }
    private void UpdateGradient()
    {
        if (atmosphereDensityColour.Modified == true)
        {
            atmosphereTexture = SGT_Helper.DestroyObject(atmosphereTexture);
        }

        atmosphereDensityColour.Modified = false;

        if (atmosphereTexture == null)
        {
            atmosphereDensityColour.Modified = false;

            SGT_Helper.DestroyObject(atmosphereTexture);
            SGT_Helper.DestroyObject(atmosphereSurfaceTexture);

            var density        = atmosphereDensityColour.CalculateColours(1.0f, 0.5f, (int)lutSize);
            var surfaceDensity = atmosphereDensityColour.CalculateColours(0.0f, 0.5f, (int)lutSize);

            atmosphereTexture        = SGT_ColourGradient.AllocateTexture((int)lutSize);
            atmosphereSurfaceTexture = SGT_ColourGradient.AllocateTexture((int)lutSize);

            for (var x = 0; x < (int)lutSize; x++)
            {
                atmosphereTexture.SetPixel(x, 0, density[x]);
            }

            for (var x = 0; x < (int)lutSize; x++)
            {
                atmosphereSurfaceTexture.SetPixel(x, 0, surfaceDensity[x]);
            }

            atmosphereTexture.Apply();
            atmosphereSurfaceTexture.Apply();
        }
    }
    private void MoveShaders(bool sync)
    {
        var dummyMaterial = new Material(Shader.Find("Diffuse"));

        UnityEditorInternal.InternalEditorUtility.SetupShaderMenu(dummyMaterial);

        var shaders = (Shader[])Resources.FindObjectsOfTypeAll(typeof(Shader));

        dummyMaterial = SGT_Helper.DestroyObject(dummyMaterial);

        var includedShaders = sync ? IncludedShaders() : null;

        foreach (var shader in shaders)
        {
            if (shader.name.Contains("Hidden/SGT/") == true)
            {
                var include = true;

                if (sync == true)
                {
                    var index = includedShaders.IndexOf(shader);

                    if (index != -1)
                    {
                        includedShaders.RemoveAt(index);
                    }
                    else
                    {
                        include = false;
                    }
                }

                MoveShader(shader, include);
            }
        }
    }
Exemple #26
0
    private void CreateMesh(ParticleList particles)
    {
        SGT_Helper.DestroyObject(generatedMesh);

        particleCount = particles.Count;
        generatedMesh = new Mesh();

        var positions = new Vector3[particleCount * 4];
        var indices   = new int[particleCount * 6];
        var uv0s      = new Vector2[particleCount * 4];
        var uv1s      = new Vector2[particleCount * 4];
        var normals   = new Vector3[particleCount * 4];
        var colours   = new Color[particleCount * 4];

        for (var i = 0; i < particleCount; i++)
        {
            var particle = particles[i];

            var i0 = i * 6;
            var i1 = i0 + 1;
            var i2 = i1 + 1;
            var i3 = i2 + 1;
            var i4 = i3 + 1;
            var i5 = i4 + 1;

            var v0 = i * 4;
            var v1 = v0 + 1;
            var v2 = v1 + 1;
            var v3 = v2 + 1;

            // Index data
            indices[i0] = v0;
            indices[i1] = v1;
            indices[i2] = v2;
            indices[i3] = v3;
            indices[i4] = v2;
            indices[i5] = v1;

            var right = SGT_Helper.Rotate(Vector2.right * SGT_Helper.InscribedBox, particle.Angle);
            var up    = SGT_Helper.Rotate(Vector2.up * SGT_Helper.InscribedBox, particle.Angle);
            var uv1   = new Vector2(particle.Size * 0.5f, 0.0f);

            // Write star values into vertex data
            positions[v0] = particle.Position;
            positions[v1] = particle.Position;
            positions[v2] = particle.Position;
            positions[v3] = particle.Position;

            normals[v0] = SGT_Helper.NewVector3(-right + up, 0.0f);
            normals[v1] = SGT_Helper.NewVector3(right + up, 0.0f);
            normals[v2] = SGT_Helper.NewVector3(-right - up, 0.0f);
            normals[v3] = SGT_Helper.NewVector3(right - up, 0.0f);

            colours[v0] = particle.Colour;
            colours[v1] = particle.Colour;
            colours[v2] = particle.Colour;
            colours[v3] = particle.Colour;

            uv0s[v0] = new Vector2(0.0f, 1.0f);
            uv0s[v1] = new Vector2(1.0f, 1.0f);
            uv0s[v2] = new Vector2(0.0f, 0.0f);
            uv0s[v3] = new Vector2(1.0f, 0.0f);

            uv1s[v0] = uv1;
            uv1s[v1] = uv1;
            uv1s[v2] = uv1;
            uv1s[v3] = uv1;
        }

        generatedMesh.name      = "Dust";
        generatedMesh.vertices  = positions;
        generatedMesh.normals   = normals;
        generatedMesh.colors    = colours;
        generatedMesh.uv        = uv0s;
        generatedMesh.uv2       = uv1s;
        generatedMesh.triangles = indices;
        generatedMesh.bounds    = new Bounds(Vector3.zero, new Vector3(100000000.0f, 100000000.0f, 100000000.0f));         // NOTE: using infinity here causes an error

        dustMesh.SharedMesh = generatedMesh;
        dustMesh.Update();
    }
    public void Regenerate()
    {
        if (modified == false)
        {
            CheckForModifications();
        }

        if (modified == true)
        {
            modified = false;

            SGT_Helper.BeginRandomSeed(meshSeed);
            {
                Quaternion[] rotations = null;

                switch (meshAlignment)
                {
                case Alignment.Billboard:
                {
                    rotations    = new Quaternion[1];
                    rotations[0] = Quaternion.identity;
                }
                break;

                case Alignment.AxisAlined:
                {
                    coronaGameObject.transform.localRotation = Quaternion.identity;

                    rotations    = new Quaternion[3];
                    rotations[0] = Quaternion.LookRotation(Vector3.right);
                    rotations[1] = Quaternion.LookRotation(Vector3.up);
                    rotations[2] = Quaternion.LookRotation(Vector3.forward);
                }
                break;

                case Alignment.Random:
                {
                    coronaGameObject.transform.localRotation = Quaternion.identity;

                    rotations = new Quaternion[meshPlaneCount];

                    for (var i = 0; i < rotations.Length; i++)
                    {
                        rotations[i] = Random.rotation;
                    }
                }
                break;
                }

                // Replace mesh
                SGT_Helper.DestroyObject(generatedMesh);

                switch (meshType)
                {
                case Type.Plane:
                {
                    GeneratePlane(rotations);
                }
                break;

                case Type.Ring:
                {
                    GenerateRing(rotations);
                }
                break;
                }

                if (coronaMesh != null)
                {
                    coronaMesh.SharedMesh = generatedMesh;
                }
            }
            SGT_Helper.EndRandomSeed();

            UpdateCoronaOffset();
        }
    }
    public new void OnDestroy()
    {
        base.OnDestroy();

        SGT_Helper.DestroyObject(probeMaterial);
    }
    private void UpdateTechnique()
    {
        var targetSurfaceTechnique    = "Variant";
        var targetAtmosphereTechnique = string.Empty;
        var tagetCloudsTechnique      = string.Empty;

        if (atmosphere == true)
        {
            targetSurfaceTechnique   += "Atmosphere";
            targetAtmosphereTechnique = "Variant";

            if (planetObserver != null)
            {
                if (InsideAtmosphere(planetObserver.transform.position) == false)
                {
                    targetSurfaceTechnique    += "Outer";
                    targetAtmosphereTechnique += "Outer";
                }
            }

            if (atmosphereScattering == true)
            {
                //targetSurfaceTechnique    += "Scattering";
                targetAtmosphereTechnique += "Scattering";
            }
        }

        if (clouds == true)
        {
            tagetCloudsTechnique = "Variant";
        }

        if (surfaceTextureNormal.ContainsSomething == true)
        {
            targetSurfaceTechnique += "Normal";
        }

        if (surfaceTextureSpecular.ContainsSomething == true)
        {
            targetSurfaceTechnique += "Specular";
        }

        if (shadow == true)
        {
            switch (shadowCasterType)
            {
            case SGT_ShadowOccluder.Ring:
            {
                targetSurfaceTechnique += "RingShadow";

                if (atmosphere == true)
                {
                    targetAtmosphereTechnique += "RingShadow";
                }

                if (clouds == true)
                {
                    tagetCloudsTechnique += "RingShadow";
                }
            }
            break;

            case SGT_ShadowOccluder.Planet:
            {
                targetSurfaceTechnique += "PlanetShadow";

                if (atmosphere == true)
                {
                    targetAtmosphereTechnique += "PlanetShadow";
                }

                if (clouds == true)
                {
                    tagetCloudsTechnique += "PlanetShadow";
                }
            }
            break;
            }
        }

        if (surfaceTextureDetail != null)
        {
            targetSurfaceTechnique += "Detail";
        }

        if (surfaceMaterials != null && (surfaceTechnique != targetSurfaceTechnique || SGT_ArrayHelper.ContainsSomething(surfaceMaterials) == false || surfaceMaterials.Length != SGT_SurfaceConfiguration_.SurfaceCount(SurfaceConfiguration)))
        {
            surfaceMaterials = SGT_Helper.DestroyObjects(surfaceMaterials);
        }

        if (atmosphereMaterial != null && (atmosphere == false || atmosphereTechnique != targetAtmosphereTechnique))
        {
            atmosphereMaterial = SGT_Helper.DestroyObject(atmosphereMaterial);
        }

        if (cloudsMaterials != null && (clouds == false || cloudsTechnique != tagetCloudsTechnique || SGT_ArrayHelper.ContainsSomething(cloudsMaterials) == false || cloudsMaterials.Length != SGT_SurfaceConfiguration_.SurfaceCount(CloudsConfiguration)))
        {
            cloudsMaterials = SGT_Helper.DestroyObjects(cloudsMaterials);
        }

        // Create planet surface shaders?
        if (surfaceMaterials == null)
        {
            updateShader    |= ShaderFlags.Surface;
            surfaceTechnique = targetSurfaceTechnique;
            surfaceMaterials = SGT_SurfaceConfiguration_.CreateMaterials(SurfaceConfiguration, "Hidden/SGT/PlanetSurface/" + surfaceTechnique, surfaceRenderQueue);
        }
        else
        {
            SGT_Helper.SetRenderQueues(surfaceMaterials, surfaceRenderQueue);
        }

        // Create planet atmosphere shaders?
        if (atmosphere == true)
        {
            if (atmosphereMaterial == null)
            {
                updateShader       |= ShaderFlags.Atmosphere;
                atmosphereTechnique = targetAtmosphereTechnique;
                atmosphereMaterial  = SGT_Helper.CreateMaterial("Hidden/SGT/PlanetAtmosphere/" + atmosphereTechnique, atmosphereRenderQueue);
            }
            else
            {
                SGT_Helper.SetRenderQueue(atmosphereMaterial, atmosphereRenderQueue);
            }
        }

        // Create planet cloud shaders?
        if (clouds == true)
        {
            if (cloudsMaterials == null)
            {
                updateShader   |= ShaderFlags.Clouds;
                cloudsTechnique = tagetCloudsTechnique;
                cloudsMaterials = SGT_SurfaceConfiguration_.CreateMaterials(CloudsConfiguration, "Hidden/SGT/PlanetClouds/" + cloudsTechnique, atmosphereRenderQueue);
            }
            else
            {
                SGT_Helper.SetRenderQueues(cloudsMaterials, atmosphereRenderQueue);
            }
        }
        else
        {
            if (cloudsMaterials != null)
            {
                cloudsMaterials = SGT_Helper.DestroyObjects(cloudsMaterials);
            }
        }
    }
    private void UpdateGradient()
    {
        // See if any gradient has been modified
        if (planetLighting.Modified == true)
        {
            planetLighting.Modified = false;

            surfaceLightingTexture   = SGT_Helper.DestroyObject(surfaceLightingTexture);
            atmosphereTexture        = SGT_Helper.DestroyObject(atmosphereTexture);
            atmosphereSurfaceTexture = SGT_Helper.DestroyObject(atmosphereSurfaceTexture);
            cloudsLightingTexture    = SGT_Helper.DestroyObject(cloudsLightingTexture);
        }

        if (atmosphereTwilightColour.Modified == true)
        {
            atmosphereTwilightColour.Modified = false;

            atmosphereTexture        = SGT_Helper.DestroyObject(atmosphereTexture);
            atmosphereSurfaceTexture = SGT_Helper.DestroyObject(atmosphereSurfaceTexture);
            cloudsLightingTexture    = SGT_Helper.DestroyObject(cloudsLightingTexture);
        }

        if (atmosphereDensityColour.Modified == true)
        {
            atmosphereDensityColour.Modified = false;

            atmosphereTexture        = SGT_Helper.DestroyObject(atmosphereTexture);
            atmosphereSurfaceTexture = SGT_Helper.DestroyObject(atmosphereSurfaceTexture);
        }

        if (cloudsLimbColour.Modified == true)
        {
            cloudsLimbColour.Modified = false;

            cloudsLightingTexture = SGT_Helper.DestroyObject(cloudsLightingTexture);
        }

        // Build colour arrays
        var lighting = surfaceLightingTexture == null || atmosphereTexture == null || atmosphereSurfaceTexture == null || cloudsLightingTexture == null?planetLighting.CalculateColours(0.0f, 1.0f, (int)planetLutSize) : null;

        var twilight = atmosphereTexture == null || atmosphereSurfaceTexture == null?atmosphereTwilightColour.CalculateColours(0.0f, 1.0f, (int)planetLutSize) : null;

        var cloudsTwilight = cloudsLightingTexture == null?atmosphereTwilightColour.CalculateColours(cloudsTwilightOffset, cloudsTwilightOffset + 1.0f, (int)planetLutSize) : null;

        var density = atmosphereTexture == null?atmosphereDensityColour.CalculateColours(1.0f, 0.5f, (int)planetLutSize) : null;

        var surfaceDensity = atmosphereSurfaceTexture == null?atmosphereDensityColour.CalculateColours(0.0f, 0.5f, (int)planetLutSize) : null;

        var cloudsLimb = cloudsLightingTexture == null?cloudsLimbColour.CalculateColours(0.0f, 1.0f, (int)planetLutSize) : null;

        // Rebuild textures
        if (surfaceLightingTexture == null)
        {
            updateShader          |= ShaderFlags.SurfaceTextureLighting;
            surfaceLightingTexture = SGT_ColourGradient.AllocateTexture((int)planetLutSize);

            for (var x = 0; x < (int)planetLutSize; x++)
            {
                surfaceLightingTexture.SetPixel(x, 0, lighting[x]);
            }

            surfaceLightingTexture.anisoLevel = 8;
            surfaceLightingTexture.filterMode = FilterMode.Trilinear;
            surfaceLightingTexture.Apply();
        }

        if (atmosphereTexture == null)
        {
            updateShader     |= ShaderFlags.AtmosphereTexture;
            atmosphereTexture = SGT_ColourGradient.AllocateTexture((int)planetLutSize, (int)planetLutSize);

            for (var y = 0; y < (int)planetLutSize; y++)
            {
                var densityColour = density[y];

                for (var x = 0; x < (int)planetLutSize; x++)
                {
                    var lightingColour = lighting[x];
                    //var twilightColour   = twilight[x];
                    lightingColour.a = Mathf.Lerp(atmosphereNightOpacity, 1.0f, lightingColour.grayscale);
                    //var colour           = SGT_Helper.AlphaBlend(densityColour, twilightColour) * lightingColour;

                    var twilightColour = SGT_Helper.AlphaBlend(Color.white, twilight[x]);
                    var colour         = SGT_Helper.BlendRGB(densityColour * lightingColour, twilightColour, SGT_Helper.ChannelBlendMode.Multiply);

                    atmosphereTexture.SetPixel(x, y, SGT_Helper.PreventZeroRGB(colour));
                    atmosphereTexture.filterMode = FilterMode.Trilinear;
                }
            }

            atmosphereTexture.Apply();
        }

        if (atmosphereSurfaceTexture == null)
        {
            updateShader            |= ShaderFlags.SurfaceTextureAtmosphere;
            atmosphereSurfaceTexture = SGT_ColourGradient.AllocateTexture((int)planetLutSize, (int)planetLutSize);

            for (var y = 0; y < (int)planetLutSize; y++)
            {
                var densityColour = surfaceDensity[y];

                for (var x = 0; x < (int)planetLutSize; x++)
                {
                    var lightingColour = lighting[x];
                    var twilightColour = twilight[x];
                    lightingColour.a = Mathf.Lerp(atmosphereNightOpacity, 1.0f, lightingColour.grayscale);
                    var colour = SGT_Helper.AlphaBlend(densityColour, twilightColour) * lightingColour;

                    atmosphereSurfaceTexture.SetPixel(x, y, SGT_Helper.PreventZeroRGB(colour));
                    atmosphereSurfaceTexture.filterMode = FilterMode.Trilinear;
                }
            }

            atmosphereSurfaceTexture.Apply();
        }

        if (cloudsLightingTexture == null)
        {
            updateShader         |= ShaderFlags.CloudsTextureLighting;
            cloudsLightingTexture = SGT_ColourGradient.AllocateTexture((int)planetLutSize, (int)planetLutSize);

            for (var y = 0; y < (int)planetLutSize; y++)
            {
                var limb = cloudsLimb[y];

                for (var x = 0; x < (int)planetLutSize; x++)
                {
                    var colour = lighting[x];

                    if (atmosphere == true)
                    {
                        colour *= SGT_Helper.AlphaBlend(limb, cloudsTwilight[x]);
                    }
                    else
                    {
                        colour *= limb;
                    }

                    cloudsLightingTexture.SetPixel(x, y, colour);
                    cloudsLightingTexture.filterMode = FilterMode.Trilinear;
                }
            }

            cloudsLightingTexture.Apply();
        }
    }