public override UnityEngine.Color GetColour(double x, double y)
        {
            // Read colour:
            UnityEngine.Color col1 = SourceModule1.GetColour(x, y);

            // Read colour:
            UnityEngine.Color col2 = SourceModule2.GetColour(x, y);

            // Pick biggest:
            if (col2.r > col1.r)
            {
                col1.r = col2.r;
            }

            if (col2.g > col1.g)
            {
                col1.g = col2.g;
            }

            if (col2.b > col1.b)
            {
                col1.b = col2.b;
            }

            return(col1);
        }
示例#2
0
        public override UnityEngine.Color GetColour(double x, double y)
        {
            // Read colour:
            UnityEngine.Color col1 = SourceModule1.GetColour(x, y);

            // Read colour:
            UnityEngine.Color col2 = SourceModule2.GetColour(x, y);

            // T:
            UnityEngine.Color t = IfTrue.GetColour(x, y);

            // False:
            UnityEngine.Color f = IfFalse.GetColour(x, y);

            // Pick:
            if (col1.r != col2.r)
            {
                col1.r = t.r;
            }
            else
            {
                col1.r = f.r;
            }

            if (col1.g != col2.g)
            {
                col1.g = t.g;
            }
            else
            {
                col1.g = f.g;
            }

            if (col1.b != col2.b)
            {
                col1.b = t.b;
            }
            else
            {
                col1.b = f.b;
            }

            if (col1.a != col2.a)
            {
                col1.a = t.a;
            }
            else
            {
                col1.a = f.a;
            }

            return(col1);
        }
示例#3
0
        public override UnityEngine.Color GetColour(double x, double y)
        {
            // Read colour:
            UnityEngine.Color col1 = SourceModule1.GetColour(x, y);

            // Read colour:
            UnityEngine.Color col2 = SourceModule2.GetColour(x, y);

            col1.r = (float)System.Math.Atan2(col1.r, col2.r);
            col1.g = (float)System.Math.Atan2(col1.g, col2.g);
            col1.b = (float)System.Math.Atan2(col1.b, col2.b);

            return(col1);
        }
示例#4
0
        public override UnityEngine.Color GetColour(double x, double y)
        {
            // Read colour:
            UnityEngine.Color col1 = SourceModule1.GetColour(x, y);

            // Read colour:
            UnityEngine.Color col2 = SourceModule2.GetColour(x, y);

            // Multiply away! Ignore alpha though - it comes from col1:
            col1.r *= col2.r;
            col1.g *= col2.g;
            col1.b *= col2.b;

            return(col1);
        }
示例#5
0
        public override UnityEngine.Color GetColour(double x, double y)
        {
            // Read colour:
            UnityEngine.Color col1 = SourceModule1.GetColour(x, y);

            // Read colour:
            UnityEngine.Color col2 = SourceModule2.GetColour(x, y);

            // Middle (ignoring alpha):
            col1.r = col1.r + ((col2.r - col1.r) * 0.5f);
            col1.g = col1.g + ((col2.g - col1.g) * 0.5f);
            col1.b = col1.b + ((col2.b - col1.b) * 0.5f);

            return(col1);
        }
示例#6
0
        public override UnityEngine.Color GetColour(double x, double y)
        {
            // Stretch out t by times to repeat:
            double rep    = SourceModule2.GetValue(x, y);
            bool   mirror = (SourceModule3.GetValue(x, y) > 0.5);

            x *= rep;
            y *= rep;

            // Get the current repetition:
            int baseRepetition = (int)x;

            // Shift:
            x -= baseRepetition;

            // X is now in the 0-1 range.

            if (mirror && (baseRepetition & 1) == 1)
            {
                // "odd" repetition - flip t:
                x = 1.0 - x;
            }

            // Get the current repetition:
            baseRepetition = (int)y;

            // Shift:
            y -= baseRepetition;

            // Y is now in the 0-1 range.

            if (mirror && (baseRepetition & 1) == 1)
            {
                // "odd" repetition - flip t:
                y = 1.0 - y;
            }

            // Read source:
            return(SourceModule1.GetColour(x, y));
        }
示例#7
0
        public override UnityEngine.Color GetColour(double x, double y)
        {
            // Read colour:
            UnityEngine.Color col1 = SourceModule1.GetColour(x, y);

            // Read colour:
            UnityEngine.Color col2 = SourceModule2.GetColour(x, y);

            // Divide away! Ignore alpha though - it comes from col1:
            if (col2.r == 0f)
            {
                col1.r = 1f;
            }
            else
            {
                col1.r /= col2.r;
            }

            if (col2.g == 0f)
            {
                col1.g = 1f;
            }
            else
            {
                col1.g /= col2.g;
            }

            if (col2.b == 0f)
            {
                col1.b = 1f;
            }
            else
            {
                col1.b /= col2.b;
            }

            return(col1);
        }
        public override UnityEngine.Color GetColour(double x, double y)
        {
            float threshold  = (float)Threshold.GetValue(x, y);
            float nThreshold = -threshold;
            float a          = 4f * (float)Gain.GetValue(x, y);

            a += 1f;

            // Read the two colours:
            UnityEngine.Color pix2 = SourceModule1.GetColour(x, y);
            UnityEngine.Color pix1 = SourceModule2.GetColour(x, y);


            // Get deltas:
            float rDelta = pix1.r - pix2.r;
            float gDelta = pix1.g - pix2.g;
            float bDelta = pix1.b - pix2.b;

            // Threshold test:
            if (rDelta <= nThreshold || rDelta >= threshold)
            {
                pix1.r = (a * rDelta + pix2.r);
            }

            if (gDelta <= nThreshold || gDelta >= threshold)
            {
                pix1.g = (a * gDelta + pix2.g);
            }

            if (bDelta <= nThreshold || bDelta >= threshold)
            {
                pix1.b = (a * bDelta + pix2.b);
            }

            return(pix1);
        }
示例#9
0
        public override UnityEngine.Color GetColour(double x, double y)
        {
            // Read colour:
            UnityEngine.Color col1 = SourceModule1.GetColour(x, y);

            // Read colour:
            UnityEngine.Color col2 = SourceModule2.GetColour(x, y);

            // Blend factor is..
            float dstA = col1.a;
            float srcA = (float)WeightModule.GetColour(x, y).r *col2.a;

            switch (Mode)
            {
            case BlendingMode.Normal:

                // Do nothing here - we just alpha blend.

                break;

            case BlendingMode.Darken:

                // Pick the smallest of the two and set col2:
                if (col1.r < col2.r)
                {
                    col2.r = col1.r;
                }

                if (col1.g < col2.g)
                {
                    col2.g = col1.g;
                }

                if (col1.b < col2.b)
                {
                    col2.b = col1.b;
                }

                break;

            case BlendingMode.Multiply:

                col2.r *= col1.r;
                col2.g *= col1.g;
                col2.b *= col1.b;

                break;

            case BlendingMode.ColourBurn:

                col2.r = 1f - ((1f - col1.r) / col2.r);
                col2.g = 1f - ((1f - col1.g) / col2.g);
                col2.b = 1f - ((1f - col1.b) / col2.b);

                break;

            case BlendingMode.LinearBurn:

                col2.r += col1.r - 1f;
                col2.g += col1.g - 1f;
                col2.b += col1.b - 1f;

                break;

            case BlendingMode.Lighten:

                // Pick the biggest of the two and set col2:
                if (col1.r > col2.r)
                {
                    col2.r = col1.r;
                }

                if (col1.g > col2.g)
                {
                    col2.g = col1.g;
                }

                if (col1.b > col2.b)
                {
                    col2.b = col1.b;
                }

                break;

            case BlendingMode.Screen:

                col2.r = 1f - (1f - col1.r) * (1f - col2.r);
                col2.g = 1f - (1f - col1.g) * (1f - col2.g);
                col2.b = 1f - (1f - col1.b) * (1f - col2.b);

                break;

            case BlendingMode.ColourDodge:

                // Bottom layer / (inverted Top layer)
                if (col2.r != 1f)
                {
                    col2.r = col1.r / (1f - col2.r);
                }

                if (col2.g != 1f)
                {
                    col2.g = col1.g / (1f - col2.g);
                }

                if (col2.b != 1f)
                {
                    col2.b = col1.b / (1f - col2.b);
                }

                break;

            case BlendingMode.LinearDodge:

                // Sum the two layers:
                col2.r += col1.r;
                col2.g += col1.g;
                col2.b += col1.b;

                break;

            case BlendingMode.Overlay:

                if (col1.r < 0.5f)
                {
                    col2.r = 2f * col1.r * col2.r;
                }
                else
                {
                    col2.r = 1f - 2f * (1f - col1.r) * (1f - col2.r);
                }

                if (col1.g < 0.5f)
                {
                    col2.g = 2f * col1.g * col2.g;
                }
                else
                {
                    col2.g = 1f - 2f * (1f - col1.g) * (1f - col2.g);
                }

                if (col1.b < 0.5f)
                {
                    col2.b = 2f * col1.b * col2.b;
                }
                else
                {
                    col2.b = 1f - 2f * (1f - col1.b) * (1f - col2.b);
                }

                break;

            case BlendingMode.SoftLight:

                // W3C soft light blend here.
                float g;
                float a;
                float b;

                a = col1.r;
                b = col2.r;

                if (b <= 0.5f)
                {
                    col2.r = a - (1f - 2f * b) * a * (1f - a);
                }
                else
                {
                    if (a <= 0.25f)
                    {
                        g = ((16f * a - 12f) * a + 4f) * a;
                    }
                    else
                    {
                        g = (float)System.Math.Sqrt(a);
                    }

                    col2.r = a + (2f * b - 1f) * (g - a);
                }

                a = col1.g;
                b = col2.g;

                if (b <= 0.5f)
                {
                    col2.g = a - (1f - 2f * b) * a * (1f - a);
                }
                else
                {
                    if (a <= 0.25f)
                    {
                        g = ((16f * a - 12f) * a + 4f) * a;
                    }
                    else
                    {
                        g = (float)System.Math.Sqrt(a);
                    }

                    col2.g = a + (2f * b - 1f) * (g - a);
                }

                a = col1.b;
                b = col2.b;

                if (b <= 0.5f)
                {
                    col2.b = a - (1f - 2f * b) * a * (1f - a);
                }
                else
                {
                    if (a <= 0.25f)
                    {
                        g = ((16f * a - 12f) * a + 4f) * a;
                    }
                    else
                    {
                        g = (float)System.Math.Sqrt(a);
                    }

                    col2.b = a + (2f * b - 1f) * (g - a);
                }

                break;

            case BlendingMode.HardLight:

                if (col2.r < 0.5f)
                {
                    col2.r = 2f * col2.r * col1.r;
                }
                else
                {
                    col2.r = 1f - 2f * (1f - col2.r) * (1f - col1.r);
                }

                if (col2.g < 0.5f)
                {
                    col2.g = 2f * col2.g * col1.g;
                }
                else
                {
                    col2.g = 1f - 2f * (1f - col2.g) * (1f - col1.g);
                }

                if (col2.b < 0.5f)
                {
                    col2.b = 2f * col2.b * col1.b;
                }
                else
                {
                    col2.b = 1f - 2f * (1f - col2.b) * (1f - col1.b);
                }

                break;

            case BlendingMode.VividLight:

                if (col2.r < 0.5f)
                {
                    // Colour Burn
                    col2.r = 1f - ((1f - col1.r) / col2.r);
                }
                else
                {
                    // Colour Dodge
                    col2.r = col1.r / (1f - col2.r);
                }

                if (col2.g < 0.5f)
                {
                    // Colour Burn
                    col2.g = 1f - ((1f - col1.g) / col2.g);
                }
                else
                {
                    // Colour Dodge
                    col2.g = col1.g / (1f - col2.g);
                }

                if (col2.b < 0.5f)
                {
                    // Colour Burn
                    col2.b = 1f - ((1f - col1.b) / col2.b);
                }
                else
                {
                    // Colour Dodge
                    col2.b = col1.b / (1f - col2.b);
                }

                break;

            case BlendingMode.LinearLight:

                if (col2.r < 0.5f)
                {
                    // Linear Burn
                    col2.r += col1.r - 1f;
                }
                else
                {
                    // Linear Dodge
                    col2.r += col1.r;
                }

                if (col2.g < 0.5f)
                {
                    // Linear Burn
                    col2.g += col1.g - 1f;
                }
                else
                {
                    // Linear Dodge
                    col2.g += col1.g;
                }

                if (col2.b < 0.5f)
                {
                    // Linear Burn
                    col2.b += col1.b - 1f;
                }
                else
                {
                    // Linear Dodge
                    col2.b += col1.b;
                }

                break;

            case BlendingMode.Hue:

                // Top layers hue and the sat/lum from bottom layer.

                float s = col1.r;
                float l = col1.g;
                HsyRgb.ToSatLum(ref s, ref l, col1.b);

                // Top hue:
                float h = HsyRgb.Hue(col2.r, col2.g, col2.b);

                // Recombine to RGB.
                HsyRgb.ToRgb(ref h, ref s, ref l);

                // They're now RGB.
                col2.r = h;
                col2.g = s;
                col2.b = l;

                break;

            case BlendingMode.Saturation:

                // Top layers saturation and the hue/lum from bottom layer.

                h = col1.r;
                l = col1.g;
                HsyRgb.ToHueLum(ref h, ref l, col1.b);

                // Top saturation:
                s = HsyRgb.Saturation(col2.r, col2.g, col2.b);

                // Recombine to RGB.
                HsyRgb.ToRgb(ref h, ref s, ref l);

                // They're now RGB.
                col2.r = h;
                col2.g = s;
                col2.b = l;

                break;

            case BlendingMode.Colour:

                // Top layers hue/sat and the luminosity from bottom layer.

                h = col2.r;
                s = col2.g;
                HsyRgb.ToHueSat(ref h, ref s, col2.b);

                // Bottom luminosity:
                l = HsyRgb.Luminance(col1.r, col1.g, col1.b);

                // Recombine to RGB.
                HsyRgb.ToRgb(ref h, ref s, ref l);

                // They're now RGB.
                col2.r = h;
                col2.g = s;
                col2.b = l;

                break;

            case BlendingMode.Luminosity:

                // Top layers luminosity and the hue/sat from bottom layer.

                h = col1.r;
                s = col1.g;
                HsyRgb.ToHueSat(ref h, ref s, col1.b);

                // Top luminosity:
                l = HsyRgb.Luminance(col2.r, col2.g, col2.b);

                // Recombine to RGB.
                HsyRgb.ToRgb(ref h, ref s, ref l);

                // They're now RGB.
                col2.r = h;
                col2.g = s;
                col2.b = l;

                break;

            case BlendingMode.Divide:

                // Bottom layer / Top layer
                if (col2.r != 0f)
                {
                    col2.r = col1.r / col2.r;
                }

                if (col2.g != 0f)
                {
                    col2.g = col1.g / col2.g;
                }

                if (col2.b != 0f)
                {
                    col2.b = col1.b / col2.b;
                }

                break;

            case BlendingMode.Subtract:

                // Subtract:
                col2.r = (col1.r - col2.r);
                col2.g = (col1.g - col2.g);
                col2.b = (col1.b - col2.b);

                break;

            case BlendingMode.Difference:
            case BlendingMode.Exclusion:

                // Subtract:
                g = (col1.r - col2.r);

                if (g < 0f)
                {
                    col2.r = -g;
                }
                else
                {
                    col2.r = g;
                }

                g = (col1.g - col2.g);

                if (g < 0f)
                {
                    col2.g = -g;
                }
                else
                {
                    col2.g = g;
                }

                g = (col1.b - col2.b);

                if (g < 0f)
                {
                    col2.b = -g;
                }
                else
                {
                    col2.b = g;
                }

                break;

            case BlendingMode.HardMix:

                // Linear light first:

                if (col2.r < 0.5f)
                {
                    // Linear Burn
                    col2.r += col1.r - 1f;
                }
                else
                {
                    // Linear Dodge
                    col2.r += col1.r;
                }

                if (col2.g < 0.5f)
                {
                    // Linear Burn
                    col2.g += col1.g - 1f;
                }
                else
                {
                    // Linear Dodge
                    col2.g += col1.g;
                }

                if (col2.b < 0.5f)
                {
                    // Linear Burn
                    col2.b += col1.b - 1f;
                }
                else
                {
                    // Linear Dodge
                    col2.b += col1.b;
                }

                // Threshold:
                if (col2.r < 0.5f)
                {
                    col2.r = 0f;
                }
                else
                {
                    col2.r = 1f;
                }

                if (col2.g < 0.5f)
                {
                    col2.g = 0f;
                }
                else
                {
                    col2.g = 1f;
                }

                if (col2.b < 0.5f)
                {
                    col2.b = 0f;
                }
                else
                {
                    col2.b = 1f;
                }

                break;

            case BlendingMode.PinLight:

                if (col2.r < 0.5f)
                {
                    // Darken
                    if (col1.r < col2.r)
                    {
                        col2.r = col1.r;
                    }
                }
                else
                {
                    // Lighten
                    if (col1.r > col2.r)
                    {
                        col2.r = col1.r;
                    }
                }

                if (col2.g < 0.5f)
                {
                    // Darken
                    if (col1.g < col2.g)
                    {
                        col2.g = col1.g;
                    }
                }
                else
                {
                    // Lighten
                    if (col1.g > col2.g)
                    {
                        col2.g = col1.g;
                    }
                }

                if (col2.b < 0.5f)
                {
                    // Darken
                    if (col1.b < col2.b)
                    {
                        col2.b = col1.b;
                    }
                }
                else
                {
                    // Lighten
                    if (col1.b > col2.b)
                    {
                        col2.b = col1.b;
                    }
                }

                break;

            case BlendingMode.LighterColor:

                // Like lighten but applies to the composite channel.
                float total1 = col1.r + col1.g + col1.b;
                float total2 = col2.r + col2.g + col2.b;

                if (total1 > total2)
                {
                    // Blend will do nothing:
                    col1.a = srcA + dstA * (1f - srcA);
                    return(col1);
                }

                break;

            case BlendingMode.DarkerColor:

                // Like darken but applies to the composite channel.
                total1 = col1.r + col1.g + col1.b;
                total2 = col2.r + col2.g + col2.b;

                if (total1 < total2)
                {
                    // Blend will do nothing:
                    col1.a = srcA + dstA * (1f - srcA);
                    return(col1);
                }

                break;
            }

            // Time to alpha blend!

            if (srcA == 1f)
            {
                // Just foreground:

                col2.a = 1f;
                return(col2);
            }

            float dstAinvSrc = dstA * (1f - srcA);
            float outA       = srcA + dstAinvSrc;

            if (outA == 0f)
            {
                col1.r = 0f;
                col1.g = 0f;
                col1.b = 0f;
            }
            else
            {
                col1.r = ((col2.r * srcA) + (col1.r * dstAinvSrc)) / outA;
                col1.g = ((col2.g * srcA) + (col1.g * dstAinvSrc)) / outA;
                col1.b = ((col2.b * srcA) + (col1.b * dstAinvSrc)) / outA;
            }

            col1.a = outA;

            return(col1);
        }
        public override UnityEngine.Color GetColour(double x, double y)
        {
            double controlValue = ControlModule.GetValue(x, y);
            float  alpha;

            double lowerBound  = LowerBound.GetValue(x, y);
            double upperBound  = UpperBound.GetValue(x, y);
            double edgeFalloff = EdgeFalloff.GetValue(x, y);

            if (edgeFalloff > 0.0)
            {
                if (controlValue < (lowerBound - edgeFalloff))
                {
                    // The output value from the control module is below the selector
                    // threshold; return the output value from the first source module.
                    return(SourceModule1.GetColour(x, y));
                }
                else if (controlValue < (lowerBound + edgeFalloff))
                {
                    // The output value from the control module is near the lower end of the
                    // selector threshold and within the smooth curve. Interpolate between
                    // the output values from the first and second source modules.
                    double lowerCurve = (lowerBound - edgeFalloff);
                    double upperCurve = (lowerBound + edgeFalloff);
                    alpha = (float)Loonim.Math.SCurve3((controlValue - lowerCurve) / (upperCurve - lowerCurve));
                    return(Loonim.Math.LinearInterpolate(SourceModule1.GetColour(x, y),
                                                         SourceModule2.GetColour(x, y), alpha));
                }
                else if (controlValue < (upperBound - edgeFalloff))
                {
                    // The output value from the control module is within the selector
                    // threshold; return the output value from the second source module.
                    return(SourceModule2.GetColour(x, y));
                }
                else if (controlValue < (upperBound + edgeFalloff))
                {
                    // The output value from the control module is near the upper end of the
                    // selector threshold and within the smooth curve. Interpolate between
                    // the output values from the first and second source modules.
                    double lowerCurve = (upperBound - edgeFalloff);
                    double upperCurve = (upperBound + edgeFalloff);
                    alpha = (float)Loonim.Math.SCurve3(
                        (controlValue - lowerCurve) / (upperCurve - lowerCurve));
                    return(Loonim.Math.LinearInterpolate(SourceModule2.GetColour(x, y),
                                                         SourceModule1.GetColour(x, y),
                                                         alpha));
                }
                else
                {
                    // Output value from the control module is above the selector threshold;
                    // return the output value from the first source module.
                    return(SourceModule1.GetColour(x, y));
                }
            }
            else
            {
                if (controlValue < lowerBound || controlValue > upperBound)
                {
                    return(SourceModule1.GetColour(x, y));
                }
                else
                {
                    return(SourceModule2.GetColour(x, y));
                }
            }
        }