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);
    }
示例#2
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();
        }
    }
示例#3
0
    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 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();
        }
    }