private void DrawButtton(float posx, float posy, ShaderMat s, string name, int pass)
 {
     if (GUI.Button(new Rect(posx, posy, 60, 20), new GUIContent(name)))
     {
         if (!tex2)
         {
             tex2           = new RenderTexture(tex.width, tex.height, 16);
             tex2.hideFlags = HideFlags.HideAndDontSave;
         }
         s.ApplyShader(tex, tex2, pass);
     }
 }
 private void CheckShader(ShaderMat s, int pass, Texture2D src, bool forceUpdate = false)
 {
     if (s.CheckChange() || forceUpdate)
     {
         if (!tex2 || tex2.width != tex.width)
         {
             tex2           = new RenderTexture(tex.width, tex.height, 16);
             tex2.hideFlags = HideFlags.HideAndDontSave;
         }
         s.ApplyShader(src, tex2, pass);
     }
 }
    private void DrawSliders(float posx, float posy, ShaderMat s)
    {
        float dy = 12f;
        int   j  = 0;

        for (int i = 0; i < s.names.Count; i++)
        {
            GUI.Label(new Rect(posx, posy + j * dy, 120, 20), s.names[i]);
            j++;
            s.vars[i] = EditorGUI.Slider(new Rect(posx, posy + j * dy, 120, 20), "", s.vars[i], s.mins[i], s.maxs[i]);
            j++;
        }
    }
    void OnEnable()
    {
        hideFlags = HideFlags.HideAndDontSave;

        Undo.undoRedoPerformed += OnUndo;

        state         = States.Load;
        previousState = States.Diffuse;

        outputDir = "";

        LoadSeamLessMask();

        periodize = ScriptableObject.CreateInstance <ShaderMat>();
        periodize.Setup(
            "Hidden/Periodize",
            new List <string> {
            "x", "y"
        },
            minimum: new float[] { 0f, 0f },
            maximum: new float[] { 1f, 1f },
            defaultValues: new float[] { 0f, 0.0f }
            );

        contrast = ScriptableObject.CreateInstance <ShaderMat>();
        contrast.Setup(
            "Hidden/Contrast",
            new List <string> {
            "Contrast", "Center"
        },
            minimum: new float[] { -2.0f, 0.0f },
            maximum: new float[] { 2.0f, 1.0f },
            defaultValues: new float[] { 0f, 0.5f }
            );

        heightmap = ScriptableObject.CreateInstance <ShaderMat>();
        heightmap.Setup(
            "Hidden/Heightmap",
            new List <string> {
            "Coef", "Center", "Min", "Max"
        },
            new float[] { -3f, 0f, 0f, 0f },
            new float[] { 3f, 1f, 1f, 1f },
            new float[] { 0f, 0.5f, 0f, 1f }
            );
        occlusion = ScriptableObject.CreateInstance <ShaderMat>();
        occlusion.Setup(
            "Hidden/Heightmap",
            new List <string> {
            "Coef", "Center", "Min", "Max"
        },
            new float[] { -3f, 0f, 0f, 0f },
            new float[] { 3f, 1f, 1f, 1f },
            new float[] { 0f, 0.5f, 0f, 1f }
            );

        specular = ScriptableObject.CreateInstance <ShaderMat>();
        specular.Setup(
            "Hidden/Heightmap",
            new List <string> {
            "Coef", "Center", "Min", "Max"
        },
            new float[] { -3f, 0f, 0f, 0f },
            new float[] { 3f, 1f, 1f, 1f },
            new float[] { 0f, 0.5f, 0.05f, 0.5f }
            );

        blurHeight = ScriptableObject.CreateInstance <ShaderMat>();
        blurHeight.Setup(
            "Hidden/GaussianBlur",
            new List <string> {
            "BlurRadius"
        },
            new float[] { 0.0f }, new float[] { 0.5f }, new float[] { 0.0f }
            );

        blurNormal = ScriptableObject.CreateInstance <ShaderMat>();
        blurNormal.Setup(
            "Hidden/GaussianBlur",
            new List <string> {
            "BlurRadius"
        },
            new float[] { 0.0f }, new float[] { 0.3f }, new float[] { 0.05f }
            );
        blurOcclusion = ScriptableObject.CreateInstance <ShaderMat>();
        blurOcclusion.Setup(
            "Hidden/GaussianBlur",
            new List <string> {
            "BlurRadius"
        },
            new float[] { 0.0f }, new float[] { 0.5f }, new float[] { 0.05f }
            );

        specShadows = ScriptableObject.CreateInstance <ShaderMat>();
        specShadows.Setup(
            "Hidden/SpecShadows",
            new List <string> {
            "Specular", "Shadows"
        },
            new float[] { -0.1f, -0.1f },
            new float[] { 1f, 1f },
            new float[] { 1f, 1f }
            );

        downSample = ScriptableObject.CreateInstance <ShaderMat>();
        downSample.Setup("Hidden/DownSample", new List <string>(), new float[0], new float[0], new float[0]);

        HSV = ScriptableObject.CreateInstance <ShaderMat>();
        HSV.Setup("Hidden/HSV", new List <string> {
            "Saturation", "Value"
        }, new float[] { 0f, 0f }, new float[] { 1f, 1f }, new float[] { 1f, 1f });

        HSV_diffuse = ScriptableObject.CreateInstance <ShaderMat>();
        HSV_diffuse.Setup(
            "Hidden/HSV",
            new List <string> {
            "Hue", "Saturation", "Value"
        },
            new float[] { 0f, -1f, -1f },
            new float[] { 1f, 1f, 1f },
            new float[] { 0f, 0f, 0f }
            );

        normal = ScriptableObject.CreateInstance <ShaderMat>();
        normal.Setup(
            "Hidden/Normal",
            new List <string> {
            "NormalCoef", "Offset"
        },
            new float[] { 0.0f, -1.0f },
            new float[] { 1.0f, 1f },
            new float[] { 1.0f, 0f }
            );

        //load parameters if saved file exists
        LoadAllData();
    }
 private void DrawButtton(float posx, float posy, ShaderMat s, string name)
 {
     DrawButtton(posx, posy, s, name, 0);
 }
 private void CheckShader(ShaderMat s, int pass)
 {
     CheckShader(s, pass, tex);
 }
 private void CheckShader(ShaderMat s)
 {
     CheckShader(s, 0, tex);
 }
 private void DoBlur(Texture2D src, RenderTexture dest, ShaderMat blurShader)
 {
     blurShader.ApplyShader(src, dest, 1); //horizontal pass
     ToTexture2D(dest, ref src);
     blurShader.ApplyShader(src, dest, 2); //verical pass
 }