public static void SendMaterialValues(Vector4 mod1, Vector4 tex1OffsetScale, Vector4 mod2, Vector4 tex2OffsetScale, float colMulVal, float colPowVal)
 {
     timeToUpdate = true;
     tex1Mod      = mod1;
     tex1Offset   = new Vector2(tex1OffsetScale.z, tex1OffsetScale.w);
     tex1Scale    = new Vector2(tex1OffsetScale.x, tex1OffsetScale.y);
     tex2Mod      = mod2;
     tex2Offset   = new Vector2(tex2OffsetScale.z, tex2OffsetScale.w);
     tex2Scale    = new Vector2(tex2OffsetScale.x, tex2OffsetScale.y);
     colMul       = colMulVal;
     colPow       = colPowVal;
     currentTex   = ActiveTex.Noise;
 }
    public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] prop)
    {
        blendMode = ShaderGUI.FindProperty("_BlendMode", prop);
        srcBlend  = ShaderGUI.FindProperty("_SrcBlend", prop);
        dstBlend  = ShaderGUI.FindProperty("_DstBlend", prop);
        invCol    = ShaderGUI.FindProperty("_InvertCol", prop);

        noiseTex     = ShaderGUI.FindProperty("_NoiseTex", prop);
        secondTex    = ShaderGUI.FindProperty("_SecondTex", prop);
        noiseTexMod  = ShaderGUI.FindProperty("_TexMod", prop);
        secondTexMod = ShaderGUI.FindProperty("_TexMod2", prop);

        customDataSpeed = ShaderGUI.FindProperty("_UseCustomData", prop);
        texMul          = ShaderGUI.FindProperty("_TexMul", prop);
        texPow          = ShaderGUI.FindProperty("_TexPow", prop);

        maskTex     = ShaderGUI.FindProperty("_MaskTexture", prop);
        maskTex2    = ShaderGUI.FindProperty("_MaskTexture2", prop);
        maskTexMod  = ShaderGUI.FindProperty("_MaskMod", prop);
        maskTex2Mod = ShaderGUI.FindProperty("_MaskMod2", prop);

        rampAsAlpha = ShaderGUI.FindProperty("_NoiseRampAsAlpha", prop);
        maskPow     = ShaderGUI.FindProperty("_MaskThreshold", prop);
        maskMul     = ShaderGUI.FindProperty("_MaskMultiplier", prop);

        edgeSoft = ShaderGUI.FindProperty("_EdgeFallOff", prop);
        edgeMul  = ShaderGUI.FindProperty("_EdgeIntensity", prop);
        edgePow  = ShaderGUI.FindProperty("_EdgePow", prop);

        color1    = ShaderGUI.FindProperty("_Color1", prop);
        color2    = ShaderGUI.FindProperty("_Color2", prop);
        colorMode = ShaderGUI.FindProperty("_ColorMode", prop);

        partColMul1 = ShaderGUI.FindProperty("_PartColMul1", prop);
        partColMul2 = ShaderGUI.FindProperty("_PartColMul2", prop);

        rampOffset = ShaderGUI.FindProperty("_RampOffset", prop);

        finAlphaMul = ShaderGUI.FindProperty("_FinalAlphaMul", prop);

        noiseTexOffsetScale  = ShaderGUI.FindProperty("_NoiseTexOffsetScale", prop);
        secondTexOffsetScale = ShaderGUI.FindProperty("_SecondTexOffsetScale", prop);
        maskTexOffsetScale   = ShaderGUI.FindProperty("_MaskTextureOffsetScale", prop);
        maskTex2OffsetScale  = ShaderGUI.FindProperty("_MaskTexture2OffsetScale", prop);
        rgbaChannelCheck     = ShaderGUI.FindProperty("_RGBAChecks", prop);

        Material material = materialEditor.target as Material;


        //Blend Options
        EditorGUI.BeginChangeCheck();
        BlendMode bMode = (BlendMode)blendMode.floatValue;

        bMode = (BlendMode)EditorGUILayout.EnumPopup("Blend Mode", bMode);

        switch (bMode)
        {
        case BlendMode.Advanced:
            materialEditor.ShaderProperty(srcBlend, "Src", 2);
            materialEditor.ShaderProperty(dstBlend, "Dst", 2);
            materialEditor.ShaderProperty(invCol, "Invert Ramp", 2);
            break;

        default:
            break;
        }
        if (EditorGUI.EndChangeCheck())
        {
            materialEditor.RegisterPropertyChangeUndo("Blend Mode");
            blendMode.floatValue = (int)bMode;

            foreach (Material mat in invCol.targets)
            {
                SetUpBlendMode(mat, bMode, srcBlend, dstBlend);
            }
        }
        GUILayout.Space(20);


        //Change Check for preview Update
        EditorGUI.BeginChangeCheck();


        //Texture Options
        //Texture 1 block
        EditorGUI.BeginChangeCheck();
        materialEditor.TexturePropertySingleLine(new GUIContent("Noise Texture 1", "Offsets X Y controls scroll speed"), noiseTex);
        if (EditorGUI.EndChangeCheck())
        {
            foreach (Material mat in noiseTex.targets)
            {
                if (noiseTex.textureValue == null)
                {
                    mat.DisableKeyword("USING_NOISE_TEX1");
                }
                else
                {
                    mat.EnableKeyword("USING_NOISE_TEX1");
                }
            }
        }
        //Texture 1 Properties
        SetUpProperties(noiseTex, noiseTexMod, materialEditor);

        //Texture 2 Block
        EditorGUI.BeginChangeCheck();
        materialEditor.TexturePropertySingleLine(new GUIContent("Noise Texture 2", "Offsets X Y controls scroll speed"), secondTex);
        if (EditorGUI.EndChangeCheck())
        {
            foreach (Material mat in secondTex.targets)
            {
                if (secondTex.textureValue == null)
                {
                    mat.DisableKeyword("USING_NOISE_TEX2");
                }
                else
                {
                    mat.EnableKeyword("USING_NOISE_TEX2");
                }
            }
        }
        //Texture 2 Properties
        SetUpProperties(secondTex, secondTexMod, materialEditor);


        //Custom Data Speed Option
        materialEditor.ShaderProperty(customDataSpeed, new GUIContent("Custom Data 1 speed mod", "Allows use of custom data 1 to modify speed offset speed, X -> Noise 1 | Y -> Noise 2 | Z -> Mask"));


        //Noise/Ramp Options
        materialEditor.FloatProperty(texMul, "Noise Multiplier");
        materialEditor.FloatProperty(texPow, "Noise Power");
        if (GUILayout.Button("Show Preview Window"))
        {
            NoiseTexturePreview.GetWindow <NoiseTexturePreview>("Texture Preview");
            NoiseTexturePreview.SendMaterialTextures((Texture2D)noiseTex.textureValue, (Texture2D)secondTex.textureValue);
            activeTex = ActiveTex.Noise;
        }


        //Texture Mask
        GUILayout.Space(20);
        EditorGUI.BeginChangeCheck();
        materialEditor.TexturePropertySingleLine(new GUIContent("Mask Texture", ""), maskTex);
        //Using Texturemask
        if (EditorGUI.EndChangeCheck())
        {
            foreach (Material mat in maskTex.targets)
            {
                if (maskTex.textureValue == null)
                {
                    mat.DisableKeyword("USING_TEX_MASK");
                }
                else
                {
                    mat.EnableKeyword("USING_TEX_MASK");
                }
            }
        }
        //Mask Tex 1 Properties
        SetUpProperties(maskTex, maskTexMod, materialEditor);

        //Mask Tex 2
        EditorGUI.BeginChangeCheck();
        materialEditor.TexturePropertySingleLine(new GUIContent("Mask Texture 2", ""), maskTex2);
        if (EditorGUI.EndChangeCheck())
        {
            foreach (Material mat in maskTex2.targets)
            {
                if (maskTex2.textureValue == null)
                {
                    mat.DisableKeyword("USING_TEX_MASK2");
                }
                else
                {
                    mat.EnableKeyword("USING_TEX_MASK2");
                }
            }
        }
        //Mask Tex 2 Properties
        SetUpProperties(maskTex2, maskTex2Mod, materialEditor);


        materialEditor.FloatProperty(maskMul, "Mask Intensity");
        materialEditor.FloatProperty(maskPow, "Mask Power");
        GUILayout.Space(20);

        materialEditor.ShaderProperty(rampAsAlpha, "Noise Times Alpha");
        materialEditor.ShaderProperty(edgeMul, "Mask Edge Intensity (Multiply)");
        materialEditor.ShaderProperty(edgePow, "Mask Edge Exponent (Power)");
        materialEditor.ShaderProperty(edgeSoft, "Mask Edge Brightness (Add)");

        if (GUILayout.Button("Show Preview Window"))
        {
            NoiseTexturePreview.GetWindow <NoiseTexturePreview>("Texture Preview");
            NoiseTexturePreview.SendMaterialTextures((Texture2D)maskTex.textureValue, (Texture2D)maskTex2.textureValue);
            activeTex = ActiveTex.Mask;
        }

        //Color Mode Option
        GUILayout.Space(20);
        materialEditor.RangeProperty(rampOffset, "Color Ramp Offset");
        EditorGUI.BeginChangeCheck();
        ColorMode cMode = (ColorMode)colorMode.floatValue;

        cMode = (ColorMode)EditorGUILayout.EnumPopup("Color Mode", cMode);

        if (EditorGUI.EndChangeCheck())
        {
            materialEditor.RegisterPropertyChangeUndo("Color Mode");
            colorMode.floatValue = (int)cMode;
        }
        switch (cMode)
        {
        case ColorMode.Particle:                 //Use Color from particles
            materialEditor.ShaderProperty(partColMul1, "Color 1 Multiplier", 2);
            materialEditor.ShaderProperty(partColMul2, "Color 2 Multiplier", 2);
            break;

        case ColorMode.Shader:                 //Use color from shader
        default:
            materialEditor.ShaderProperty(color1, "Color 1", 2);
            materialEditor.ShaderProperty(color2, "Color 2", 2);
            //Swap Colors Button
            if (GUILayout.Button("Swap Colors"))
            {
                Color tempCol = color1.colorValue;
                foreach (Material mat in color1.targets)
                {
                    mat.SetColor(color1.name, color2.colorValue);
                }
                foreach (Material mat in color2.targets)
                {
                    mat.SetColor(color2.name, tempCol);
                }
            }
            break;
        }
        materialEditor.ShaderProperty(finAlphaMul, "Final Multiplier");

        //End Check for all values
        if (EditorGUI.EndChangeCheck() && NoiseTexturePreview.IsActive())
        {
            switch (activeTex)
            {
            case ActiveTex.Noise:
                NoiseTexturePreview.SendMaterialTextures((Texture2D)noiseTex.textureValue, (Texture2D)secondTex.textureValue);
                NoiseTexturePreview.SendMaterialValues(noiseTexMod.vectorValue, noiseTex.textureScaleAndOffset, secondTexMod.vectorValue, secondTex.textureScaleAndOffset, texMul.floatValue, texPow.floatValue);
                break;

            case ActiveTex.Mask:
                NoiseTexturePreview.SendMaterialTextures((Texture2D)maskTex.textureValue, (Texture2D)maskTex2.textureValue);
                NoiseTexturePreview.SendMaterialValues(maskTexMod.vectorValue, maskTex.textureScaleAndOffset, maskTex2Mod.vectorValue, maskTex2.textureScaleAndOffset, maskMul.floatValue, maskPow.floatValue, edgeSoft.floatValue, edgeMul.floatValue, edgePow.floatValue);
                break;

            default:
                break;
            }
        }


        GUILayout.Space(20);
        int widthTarget = combinedTexWidth;

        combinedTexWidth  = EditorGUILayout.IntField("Combined Texture Width", combinedTexWidth);
        combinedTexHeight = EditorGUILayout.IntField("Combined Texture Height", combinedTexHeight);

        combinedTexWidth  = combinedTexWidth > 4096 ? 4096 : combinedTexWidth <= 0 ? 1 : combinedTexWidth;
        combinedTexHeight = combinedTexHeight > 4096 ? 4096 : combinedTexHeight <= 0 ? 1 : combinedTexHeight;

        if (GUILayout.Button("Combine Textures and Switch Shaders"))
        {
            if (EditorUtility.DisplayDialog("Are you sure?", "This option will create a new texture and change certain values; this cannot be undone.\nThis is recommeneded to be done after setting up all texture properties. \nMake sure that ALL textures have read/write enabled in the texture's import settings.", "Yes", "Cancel"))
            {
                bool   readable;
                string path = EditorUtility.SaveFilePanelInProject("Save Texture", "Combined RGBA.png", "png", "Please enter a filename");

                if (path.Length == 0)
                {
                    Debug.Log("Cancelled");
                }
                else
                {
                    //Jank method of checking if texture is readable
                    try{
                        Texture2D check;
                        if (noiseTex.textureValue != null)
                        {
                            check = (Texture2D)noiseTex.textureValue;
                            check.GetPixel(0, 0);
                        }
                        if (secondTex.textureValue != null)
                        {
                            check = (Texture2D)secondTex.textureValue;
                            check.GetPixel(0, 0);
                        }
                        if (maskTex.textureValue != null)
                        {
                            check = (Texture2D)maskTex.textureValue;
                            check.GetPixel(0, 0);
                        }
                        if (maskTex2.textureValue != null)
                        {
                            check = (Texture2D)maskTex2.textureValue;
                            check.GetPixel(0, 0);
                        }
                        readable = true;
                    }catch {
                        EditorUtility.DisplayDialog("Failed to read textures!", "Did you enable Read/Write in the import settings for all textures?", "Ok");
                        readable = false;
                    }

                    if (readable)
                    {
                        Texture2D noiseTexCombine    = SetTex((Texture2D)noiseTex.textureValue);
                        Texture2D noiseTexTwoCombine = SetTex((Texture2D)secondTex.textureValue);
                        Texture2D maskTexCombine     = SetTex((Texture2D)maskTex.textureValue);
                        Texture2D maskTexTwoCombine  = SetTex((Texture2D)maskTex2.textureValue);

                        Texture2D finalTex = CombineImages(noiseTexCombine, noiseTexTwoCombine, maskTexCombine, maskTexTwoCombine, combinedTexWidth, combinedTexHeight);
                        byte[]    pngData  = finalTex.EncodeToPNG();
                        if (pngData != null)
                        {
                            System.IO.File.WriteAllBytes(path, pngData);
                            AssetDatabase.Refresh();
                        }

                        //Use Tex Channel
                        Vector4 setTexActive = new Vector4(
                            BoolToFloat(noiseTex.textureValue != null),
                            BoolToFloat(secondTex.textureValue != null),
                            BoolToFloat(maskTex.textureValue != null),
                            BoolToFloat(maskTex2.textureValue != null)
                            );
                        foreach (Material mat in rgbaChannelCheck.targets)
                        {
                            mat.SetVector("_RGBAChecks", setTexActive);
                        }

                        //Texture OffsetScale
                        foreach (Material mat in noiseTexOffsetScale.targets)
                        {
                            mat.SetVector("_NoiseTexOffsetScale", noiseTex.textureScaleAndOffset);
                        }
                        foreach (Material mat in secondTexOffsetScale.targets)
                        {
                            mat.SetVector("_SecondTexOffsetScale", secondTex.textureScaleAndOffset);
                        }
                        foreach (Material mat in maskTexOffsetScale.targets)
                        {
                            mat.SetVector("_MaskTextureOffsetScale", maskTex.textureScaleAndOffset);
                        }
                        foreach (Material mat in maskTex2OffsetScale.targets)
                        {
                            mat.SetVector("_MaskTexture2OffsetScale", maskTex2.textureScaleAndOffset);
                        }

                        //Set Texture
                        Texture2D       finalTextureTex    = (Texture2D)AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D));
                        TextureImporter finalTextureImport = (TextureImporter)TextureImporter.GetAtPath(path);
                        finalTextureImport.alphaIsTransparency = true;
                        AssetDatabase.Refresh();
                        foreach (Material mat in noiseTex.targets)
                        {
                            mat.SetTexture("_NoiseTex", finalTextureTex);
                        }
                        //Finally Switch Shaders
                        material.shader = Shader.Find("Dafirex/Particles/NoiseParticles RGBA Tex");
                    }
                }
            }
        }
    }
    public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] prop)
    {
        blendMode = ShaderGUI.FindProperty("_BlendMode", prop);
        srcBlend  = ShaderGUI.FindProperty("_SrcBlend", prop);
        dstBlend  = ShaderGUI.FindProperty("_DstBlend", prop);
        invCol    = ShaderGUI.FindProperty("_InvertCol", prop);

        noiseTex     = ShaderGUI.FindProperty("_NoiseTex", prop);
        noiseTexMod  = ShaderGUI.FindProperty("_TexMod", prop);
        secondTexMod = ShaderGUI.FindProperty("_TexMod2", prop);

        noiseTexOffsetScale  = ShaderGUI.FindProperty("_NoiseTexOffsetScale", prop);
        secondTexOffsetScale = ShaderGUI.FindProperty("_SecondTexOffsetScale", prop);

        customDataSpeed = ShaderGUI.FindProperty("_UseCustomData", prop);
        texMul          = ShaderGUI.FindProperty("_TexMul", prop);
        texPow          = ShaderGUI.FindProperty("_TexPow", prop);

        maskTexMod          = ShaderGUI.FindProperty("_MaskMod", prop);
        maskTex2Mod         = ShaderGUI.FindProperty("_MaskMod2", prop);
        maskTexOffsetScale  = ShaderGUI.FindProperty("_MaskTextureOffsetScale", prop);
        maskTex2OffsetScale = ShaderGUI.FindProperty("_MaskTexture2OffsetScale", prop);

        rampAsAlpha = ShaderGUI.FindProperty("_NoiseRampAsAlpha", prop);
        maskPow     = ShaderGUI.FindProperty("_MaskThreshold", prop);
        maskMul     = ShaderGUI.FindProperty("_MaskMultiplier", prop);

        edgeSoft = ShaderGUI.FindProperty("_EdgeFallOff", prop);
        edgeMul  = ShaderGUI.FindProperty("_EdgeIntensity", prop);
        edgePow  = ShaderGUI.FindProperty("_EdgePow", prop);

        color1    = ShaderGUI.FindProperty("_Color1", prop);
        color2    = ShaderGUI.FindProperty("_Color2", prop);
        colorMode = ShaderGUI.FindProperty("_ColorMode", prop);

        partColMul1 = ShaderGUI.FindProperty("_PartColMul1", prop);
        partColMul2 = ShaderGUI.FindProperty("_PartColMul2", prop);

        rampOffset = ShaderGUI.FindProperty("_RampOffset", prop);

        finAlphaMul = ShaderGUI.FindProperty("_FinalAlphaMul", prop);

        rgbaChannelCheck = ShaderGUI.FindProperty("_RGBAChecks", prop);

        Material material = materialEditor.target as Material;

        //Blend Options
        EditorGUI.BeginChangeCheck();
        BlendMode bMode = (BlendMode)blendMode.floatValue;

        bMode = (BlendMode)EditorGUILayout.EnumPopup("Blend Mode", bMode);

        switch (bMode)
        {
        case BlendMode.Advanced:
            materialEditor.ShaderProperty(srcBlend, "Src", 2);
            materialEditor.ShaderProperty(dstBlend, "Dst", 2);
            materialEditor.ShaderProperty(invCol, "Invert Ramp", 2);
            break;

        default:
            break;
        }
        if (EditorGUI.EndChangeCheck())
        {
            materialEditor.RegisterPropertyChangeUndo("Blend Mode");
            blendMode.floatValue = (int)bMode;

            foreach (Material mat in invCol.targets)
            {
                SetUpBlendMode(mat, bMode, srcBlend, dstBlend);
            }
        }
        GUILayout.Space(20);



        //Change Check for preview Update
        EditorGUI.BeginChangeCheck();

        //Main Tex
        materialEditor.TexturePropertySingleLine(new GUIContent("Main Texture", "Offsets X Y controls scroll speed"), noiseTex);
        GUILayout.Space(20);

        //Red Channel (Noise Tex)
        EditorGUI.BeginChangeCheck();
        bool useRed = FloatToBool(rgbaChannelCheck.vectorValue.x);

        useRed = EditorGUILayout.Toggle("Use Red Channel (Noise 1)", useRed);
        if (EditorGUI.EndChangeCheck())
        {
            materialEditor.RegisterPropertyChangeUndo("Red Channel");
            foreach (Material mat in rgbaChannelCheck.targets)
            {
                mat.SetVector("_RGBAChecks", new Vector4(BoolToFloat(useRed), rgbaChannelCheck.vectorValue.y, rgbaChannelCheck.vectorValue.z, rgbaChannelCheck.vectorValue.w));
                if (useRed)
                {
                    mat.EnableKeyword("USING_NOISE_TEX1");
                }
                else
                {
                    mat.DisableKeyword("USING_NOISE_TEX1");
                }
            }
        }

        //Texture 1 Properties
        SetUpProperties("Red", noiseTexOffsetScale, noiseTexMod, materialEditor);


        //Green Channel (Noise Tex 2)
        EditorGUI.BeginChangeCheck();
        bool useGreen = FloatToBool(rgbaChannelCheck.vectorValue.y);

        useGreen = EditorGUILayout.Toggle("Use Green Channel (Noise 2)", useGreen);
        if (EditorGUI.EndChangeCheck())
        {
            materialEditor.RegisterPropertyChangeUndo("Green Channel");
            foreach (Material mat in rgbaChannelCheck.targets)
            {
                mat.SetVector("_RGBAChecks", new Vector4(rgbaChannelCheck.vectorValue.x, BoolToFloat(useGreen), rgbaChannelCheck.vectorValue.z, rgbaChannelCheck.vectorValue.w));
                if (useGreen)
                {
                    mat.EnableKeyword("USING_NOISE_TEX2");
                }
                else
                {
                    mat.DisableKeyword("USING_NOISE_TEX2");
                }
            }
        }
        //Texture 2 Properties
        SetUpProperties("Green", secondTexOffsetScale, secondTexMod, materialEditor);


        //Custom Data Speed Option
        GUILayout.Space(20);
        materialEditor.ShaderProperty(customDataSpeed, new GUIContent("Custom Data 1 speed mod", "Allows use of custom data 1 to modify speed offset speed, X -> Noise 1 | Y -> Noise 2 | Z -> Mask"));


        //Noise/Ramp Options
        materialEditor.FloatProperty(texMul, "Noise Multiplier");
        materialEditor.FloatProperty(texPow, "Noise Power");

        //Preview Window
        if (GUILayout.Button("Show Preview Window"))
        {
            NoiseTexturePreviewRGBA.GetWindow <NoiseTexturePreviewRGBA>("Texture Preview");
            NoiseTexturePreviewRGBA.SetTex((Texture2D)noiseTex.textureValue, useRed, useGreen);
            activeTex = ActiveTex.Noise;
        }

        GUILayout.Space(20);
        //Blue Channel (Alpha Mask)
        EditorGUI.BeginChangeCheck();
        bool useBlue = FloatToBool(rgbaChannelCheck.vectorValue.z);

        useBlue = EditorGUILayout.Toggle("Use Blue Channel (Alpha Mask)", useBlue);
        if (EditorGUI.EndChangeCheck())
        {
            materialEditor.RegisterPropertyChangeUndo("Blue Channel");
            foreach (Material mat in rgbaChannelCheck.targets)
            {
                mat.SetVector("_RGBAChecks", new Vector4(rgbaChannelCheck.vectorValue.x, rgbaChannelCheck.vectorValue.y, BoolToFloat(useBlue), rgbaChannelCheck.vectorValue.w));
                if (useBlue)
                {
                    mat.EnableKeyword("USING_TEX_MASK");
                }
                else
                {
                    mat.DisableKeyword("USING_TEX_MASK");
                }
            }
        }
        //Mask Tex 1 Properties
        SetUpProperties("Blue", maskTexOffsetScale, maskTexMod, materialEditor);

        //Alpha Channel (Alpha Mask 2)
        EditorGUI.BeginChangeCheck();
        bool useAlpha = FloatToBool(rgbaChannelCheck.vectorValue.w);

        useAlpha = EditorGUILayout.Toggle("Use Alpha Channel (Alpha Mask 2)", useAlpha);
        if (EditorGUI.EndChangeCheck())
        {
            materialEditor.RegisterPropertyChangeUndo("Alpha Channel");
            foreach (Material mat in rgbaChannelCheck.targets)
            {
                mat.SetVector("_RGBAChecks", new Vector4(rgbaChannelCheck.vectorValue.x, rgbaChannelCheck.vectorValue.y, rgbaChannelCheck.vectorValue.z, BoolToFloat(useAlpha)));
                if (useAlpha)
                {
                    mat.EnableKeyword("USING_TEX_MASK2");
                }
                else
                {
                    mat.DisableKeyword("USING_TEX_MASK2");
                }
            }
        }
        //Mask Tex 2 Properties
        SetUpProperties("Alpha", maskTex2OffsetScale, maskTex2Mod, materialEditor);

        GUILayout.Space(20);
        materialEditor.FloatProperty(maskMul, "Mask Intensity");
        materialEditor.FloatProperty(maskPow, "Mask Power");
        GUILayout.Space(20);

        materialEditor.ShaderProperty(rampAsAlpha, "Noise Times Alpha");
        materialEditor.ShaderProperty(edgeMul, "Mask Edge Intensity (Multiply)");
        materialEditor.ShaderProperty(edgePow, "Mask Edge Exponent (Power)");
        materialEditor.ShaderProperty(edgeSoft, "Mask Edge Brightness (Add)");

        //Preview Window
        if (GUILayout.Button("Show Preview Window"))
        {
            NoiseTexturePreviewRGBA.GetWindow <NoiseTexturePreviewRGBA>("Texture Preview");
            NoiseTexturePreviewRGBA.SetTex((Texture2D)noiseTex.textureValue, useBlue, useAlpha);
            activeTex = ActiveTex.Mask;
        }

        //Color Mode Option
        GUILayout.Space(20);
        materialEditor.RangeProperty(rampOffset, "Color Ramp Offset");
        EditorGUI.BeginChangeCheck();
        ColorMode cMode = (ColorMode)colorMode.floatValue;

        cMode = (ColorMode)EditorGUILayout.EnumPopup("Color Mode", cMode);

        if (EditorGUI.EndChangeCheck())
        {
            materialEditor.RegisterPropertyChangeUndo("Color Mode");
            colorMode.floatValue = (int)cMode;
        }
        switch (cMode)
        {
        case ColorMode.Particle:                 //Use Color from particles
            materialEditor.ShaderProperty(partColMul1, "Color 1 Multiplier", 2);
            materialEditor.ShaderProperty(partColMul2, "Color 2 Multiplier", 2);
            break;

        case ColorMode.Shader:                 //Use color from shader
        default:
            materialEditor.ShaderProperty(color1, "Color 1", 2);
            materialEditor.ShaderProperty(color2, "Color 2", 2);
            //Swap Colors Button
            if (GUILayout.Button("Swap Colors"))
            {
                Color tempCol = color1.colorValue;
                foreach (Material mat in color1.targets)
                {
                    mat.SetColor(color1.name, color2.colorValue);
                }
                foreach (Material mat in color2.targets)
                {
                    mat.SetColor(color2.name, tempCol);
                }
            }
            break;
        }
        materialEditor.ShaderProperty(finAlphaMul, "Final Multiplier");


        if (EditorGUI.EndChangeCheck() && NoiseTexturePreviewRGBA.IsActive())
        {
            switch (activeTex)
            {
            case ActiveTex.Noise:
                NoiseTexturePreviewRGBA.SetTex((Texture2D)noiseTex.textureValue, useRed, useGreen);
                NoiseTexturePreviewRGBA.SendMaterialValues(noiseTexMod.vectorValue, noiseTexOffsetScale.vectorValue, secondTexMod.vectorValue, secondTexOffsetScale.vectorValue, texMul.floatValue, texPow.floatValue);
                break;

            case ActiveTex.Mask:
                NoiseTexturePreviewRGBA.SetTex((Texture2D)noiseTex.textureValue, useBlue, useAlpha);
                NoiseTexturePreviewRGBA.SendMaterialValues(maskTexMod.vectorValue, maskTexOffsetScale.vectorValue, maskTex2Mod.vectorValue, maskTex2OffsetScale.vectorValue, maskMul.floatValue, maskPow.floatValue, edgeSoft.floatValue, edgeMul.floatValue, edgePow.floatValue);
                break;

            default:
                break;
            }
        }
    }