Пример #1
0
        public void Distort(TextureParam _input, TextureParam _inputB, TextureParam _output)
        {
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            timer.Start();

            Material mat = GetMaterial("TextureOps");

            mat.SetInt("_MainIsGrey", _input.IsGrey() ? 1 : 0);
            mat.SetInt("_TextureBIsGrey", _inputB.IsGrey() ? 1 : 0);
            mat.SetTexture("_GradientTex", _inputB.GetHWSourceTexture());
            mat.SetVector("_TexSizeRecip", new Vector4(1.0f / (float)_inputB.m_Width, 1.0f / (float)_inputB.m_Height, m_Value, m_Value2));
            mat.SetVector("_Multiply", new Vector4(m_Value, m_Value1, m_Value2, 0.0f));
            SetCommonVars(mat);

            //Texture2D tex = input.CreateTexture(TextureParam.ms_TexFormat);
            //input.FillInTexture(tex);

            //RenderTexture destination = RenderTexture.GetTemporary((int)input.m_Width, (int)input.m_Height, 24, TextureParam.ms_RTexFormat);
            RenderTexture destination = CreateRenderDestination(_input, _output);

            Graphics.Blit(_input.GetHWSourceTexture(), destination, mat, (int)ShaderOp.Distort);

            //output.TexFromRenderTarget();

            //RenderTexture.ReleaseTemporary(destination);
//        Debug.LogError(" Distort in Final" + timer.ElapsedMilliseconds + " ms");
        }
Пример #2
0
        private bool CreateOutputTexture()
        {
//Get RGB
            TextureParam input = null;
            //Get Alpha
            TextureParam input2 = null;

            if (!GetInput(0, out input))
            {
                return(false);
            }
            if (!GetInput(1, out input2))
            {
                return(false);
            }

            if (m_Param == null)
            {
                m_Param = new TextureParam(m_TexWidth, m_TexHeight);
            }
            m_TexMode = TexMode.ColorRGB;

            Material m = GetMaterial("TextureOps");

            m.SetInt("_MainIsGrey", input.IsGrey() ? 1 : 0);
            m.SetInt("_TextureBIsGrey", input2.IsGrey() ? 1 : 0);
            m.SetTexture("_GradientTex", input2.GetHWSourceTexture());
            Graphics.Blit(input.GetHWSourceTexture(), CreateRenderDestination(input, m_Param), m,
                          (int)ShaderOp.CopyColorAndAlpha);
            return(true);
        }
        public override bool Calculate()
        {
            if (!allInputsReady())
            {
                return(false);
            }

            if (m_Output == null)
            {
                return(false);
            }
            TextureParam input = null;

            if (Inputs[0].connection != null)
            {
                input = Inputs[0].connection.GetValue <TextureParam>();
            }

            TextureParam input2 = null;

            if (Inputs[1].connection != null)
            {
                input2 = Inputs[1].connection.GetValue <TextureParam>();
            }


            //input.DestinationToTexture(m_Output);



            if (m_Output.width != input.m_Width)
            {
                Texture2D texture = new Texture2D(input.m_Width, input.m_Height, TextureFormat.ARGB32, false);
                EditorUtility.CopySerialized(texture, m_Output);
                AssetDatabase.SaveAssets();
            }
            if (m_Output.format != TextureFormat.ARGB32 && m_Output.format != TextureFormat.RGBA32 && m_Output.format != TextureFormat.RGB24)
            {
                Debug.LogError(" Ouput Texture " + m_Output + "wrong Format " + m_Output.format);
            }
            else
            {
                RenderTexture rt = new RenderTexture(m_Output.width, m_Output.height, 0, RenderTextureFormat.ARGB32);

                Material m = GetMaterial("TextureOps");
                m.SetInt("_MainIsGrey", input.IsGrey() ? 1 : 0);
                m.SetInt("_TextureBIsGrey", input2.IsGrey() ? 1 : 0);
                m.SetTexture("_GradientTex", input2.GetHWSourceTexture());
                Graphics.Blit(input.GetHWSourceTexture(), rt, m, (int)ShaderOp.CopyRandA);

                RenderTexture.active = rt;
                m_Output.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
                //input.DestinationToTexture(m_Output);
                m_Output.Apply();
            }


            //Outputs[0].SetValue<TextureParam> (m_Param);
            return(true);
        }
        public override bool Calculate()
        {
            if (!allInputsReady())
            {
                return(false);
            }

            TextureParam input = null;

            if (Inputs[0].connection != null)
            {
                input = Inputs[0].connection.GetValue <TextureParam>();
            }
            if (input == null)
            {
                return(false);
            }
            TextureParam input2 = null;
            int          index2 = 1;

            if (Inputs.Count < 2)
            {
                index2 = 0;
            }

            if (Inputs[index2].connection != null)
            {
                input2 = Inputs[index2].connection.GetValue <TextureParam>();
            }
            if (input2 == null)
            {
                return(false);
            }

            if (m_Param == null)
            {
                m_Param = new TextureParam(m_TexWidth, m_TexHeight);
            }
            m_TexMode = TexMode.ColorRGB;

            Material m = GetMaterial("TextureOps");

            m.SetInt("_MainIsGrey", input.IsGrey() ? 1 : 0);
            m.SetInt("_TextureBIsGrey", input2.IsGrey() ? 1 : 0);
            m.SetTexture("_GradientTex", input2.GetHWSourceTexture());
            Graphics.Blit(input.GetHWSourceTexture(), CreateRenderDestination(input, m_Param), m, (int)ShaderOp.CopyColorAndAlpha);

            CreateCachedTextureIcon();



            return(true);
        }
Пример #5
0
        public void General(TextureParam _input, TextureParam _inputB, TextureParam _output, ShaderOp _shaderOp)
        {
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            timer.Start();
            Material mat = GetMaterial("TextureOps");

            SetCommonVars(mat);

            mat.SetInt("_MainIsGrey", _input.IsGrey() ? 1 : 0);
            mat.SetInt("_TextureBIsGrey", _inputB.IsGrey() ? 1 : 0);
            mat.SetTexture("_GradientTex", _inputB.GetHWSourceTexture());
            mat.SetVector("_TexSizeRecip", new Vector4(1.0f / (float)_input.m_Width, 1.0f / (float)_input.m_Height, m_Value, 0));
            RenderTexture destination = CreateRenderDestination(_input, _output);

            Graphics.Blit(_input.GetHWSourceTexture(), destination, mat, (int)_shaderOp);
//        Debug.LogError(""+ _shaderOp+"  in Final" + timer.ElapsedMilliseconds + " ms");
        }
Пример #6
0
        public Texture CreateTextureIcon(int _size)
        {
            if (m_Param == null)
            {
                return(null);
            }
            return(m_Param.m_Destination);//GetHWSourceTexture();

#if OUTPUT_SCALED_GREY
            //this is just for display as a label on the node
            RenderTexture destination = new RenderTexture(_size, _size, 24, RenderTextureFormat.ARGB32);
            Material      m           = GetMaterial("TextureOps");
            m.SetVector("_Multiply", new Vector4(m_ScalePreview, 0, 0, 0));
            Graphics.Blit(m_Param.GetHWSourceTexture(), destination, m, m_Param.IsGrey() ? (int)ShaderOp.CopyGrey : (int)ShaderOp.CopyColor);

            return(destination);
#endif
        }
Пример #7
0
        public void CalcNormals(float _size, TextureParam _input, TextureParam _output)
        {
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            timer.Start();
            Material mat = GetMaterial("TextureOps");

            mat.SetInt("_MainIsGrey", _input.IsGrey() ? 1 : 0);


            mat.SetVector("_TexSizeRecip", new Vector4(1.0f / (float)_input.m_Width, 1.0f / (float)_input.m_Height, _size, 0));
            m_TexMode = TexMode.ColorRGB;
            RenderTexture destination = CreateRenderDestination(_input, _output);

            SetCommonVars(mat);
            Graphics.Blit(_input.GetHWSourceTexture(), destination, mat, (int)ShaderOp.Normal);


//        Debug.LogError(" multiply in Final" + timer.ElapsedMilliseconds + " ms");
        }
Пример #8
0
        public void General(float _r, float _g, float _b, TextureParam _input, TextureParam _output, ShaderOp _shaderOp)
        {
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            timer.Start();
            Material mat = GetMaterial("TextureOps");

//        if (Inputs.Count>1 && Inputs[1].connection != null)
//            _r=Inputs[1].connection.GetValue<float>();
            mat.SetVector("_TexSizeRecip", new Vector4(1.0f / (float)_input.m_Width, 1.0f / (float)_input.m_Height, _input.m_Width, 0));
            mat.SetVector("_Multiply", new Vector4(_r, _g, _b, 1));
            mat.SetInt("_MainIsGrey", _input.IsGrey() ? 1 : 0);
            SetCommonVars(mat);

            CalcOutputFormat(_input);
            RenderTexture destination = CreateRenderDestination(_input, _output);


            Graphics.Blit(_input.GetHWSourceTexture(), destination, mat, (int)_shaderOp);
        }
Пример #9
0
        public void Blend(TextureParam _input, TextureParam _inputB, TextureParam _inputC, TextureParam _inputD, TextureParam _output)
        {
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            timer.Start();

            Material mat = GetMaterial("TextureOps");

            mat.SetInt("_MainIsGrey", _input.IsGrey() ? 1 : 0);
            mat.SetInt("_TextureBIsGrey", _inputB.IsGrey() ? 1 : 0);
            mat.SetTexture("_GradientTex", _inputB.GetHWSourceTexture());
            mat.SetTexture("_GradientTex2", _inputC.GetHWSourceTexture());
            mat.SetTexture("_GradientTex3", _inputD.GetHWSourceTexture());
            mat.SetVector("_TexSizeRecip", new Vector4(1.0f / (float)_inputB.m_Width, 1.0f / (float)_inputB.m_Height, m_Value, m_Value2));
            mat.SetVector("_Multiply", new Vector4(m_Value, m_Value1, m_Value2, 0.0f));
            SetCommonVars(mat);
            CalcOutputFormat(_input);
            RenderTexture destination = CreateRenderDestination(_input, _output);

            Graphics.Blit(_input.GetHWSourceTexture(), destination, mat, (int)ShaderOp.Quadify);
        }
Пример #10
0
        public void ExecuteRemapCurve(float _size, TextureParam _input, TextureParam _output)
        {
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            timer.Start();
            Material mat = GetMaterial("TextureOps");

            mat.SetInt("_MainIsGrey", _input.IsGrey() ? 1 : 0);

            if (gradient == null)
            {
                gradient = new Texture2D(1024, 1, TextureFormat.RFloat, false); //1024 possible levels
            }
            Color c = Color.white;

            for (float x = 0.0f; x < (float)gradient.width; x += 1.0f)
            {
                c.g = c.b = c.r = m_RemapCurve.Evaluate(x / (float)gradient.width);

                gradient.SetPixel((int)x, 0, c);
            }
            gradient.wrapMode = TextureWrapMode.Clamp;
            gradient.Apply();



            mat.SetTexture("_GradientTex", gradient);
            mat.SetVector("_TexSizeRecip", new Vector4(1.0f / (float)_input.m_Width, 1.0f / (float)_input.m_Height, _size, 0));
            SetCommonVars(mat);
//        m_TexMode =TexMode.ColorRGB;
            RenderTexture destination = CreateRenderDestination(_input, _output);

            Graphics.Blit(_input.GetHWSourceTexture(), destination, mat, (int)ShaderOp.Gradient);


//        Debug.LogError(" multiply in Final" + timer.ElapsedMilliseconds + " ms");
        }
Пример #11
0
        public void UVOffset(TextureParam _inputU, TextureParam _inputV, TextureParam _inputSrc, TextureParam _output)
        {
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            timer.Start();

            Material mat = GetMaterial("TextureOps");

            mat.SetInt("_MainIsGrey", _inputSrc.IsGrey() ? 1 : 0);
            mat.SetInt("_TextureBIsGrey", _inputU.IsGrey() ? 1 : 0);
            mat.SetTexture("_GradientTex", _inputU.GetHWSourceTexture());
            mat.SetTexture("_GradientTex2", _inputV.GetHWSourceTexture());
            mat.SetVector("_TexSizeRecip", new Vector4(1.0f / (float)_inputU.m_Width, 1.0f / (float)_inputSrc.m_Height, m_Value, m_Value2));
            mat.SetVector("_Multiply", new Vector4(m_Value, m_Value1, m_Value2, 0.0f));
            SetCommonVars(mat);
            CalcOutputFormat(_inputSrc);
            RenderTexture destination = CreateRenderDestination(_inputSrc, _output);

            Graphics.Blit(_inputSrc.GetHWSourceTexture(), destination, mat, (int)ShaderOp.UVOffset);

            //output.TexFromRenderTarget();

            //RenderTexture.ReleaseTemporary(destination);
            //        Debug.LogError(" Distort in Final" + timer.ElapsedMilliseconds + " ms");
        }
Пример #12
0
        public override bool Calculate()
        {
            if (!allInputsReady())
            {
                return(false);
            }

            if (m_Output == null)
            {
                return(false);
            }
            TextureParam input = null;

            if (Inputs[0].connection != null)
            {
                input = Inputs[0].connection.GetValue <TextureParam>();
            }
            if (input == null)
            {
                return(false);
            }
            TextureParam input2 = null;
            int          index2 = 1;

            if (Inputs.Count < 2)
            {
                index2 = 0;
            }

            if (Inputs[index2].connection != null)
            {
                input2 = Inputs[index2].connection.GetValue <TextureParam>();
            }
            if (input2 == null)
            {
                return(false);
            }
            //input.DestinationToTexture(m_Output);



            if (m_Output.width != input.m_Width)
            {
                Texture2D texture = new Texture2D(input.m_Width, input.m_Height, TextureFormat.ARGB32, false);
                EditorUtility.CopySerialized(texture, m_Output);
                AssetDatabase.SaveAssets();
            }

            //m_Output.width = 256;
            //m_Output.height = 256;
            //int x = 0, y = 0;
            if (m_Output.format != TextureFormat.ARGB32 && m_Output.format != TextureFormat.RGBA32 && m_Output.format != TextureFormat.RGB24)
            {
                Debug.LogError(" Ouput Texture " + m_Output + "wrong Format " + m_Output.format);
            }
            else
            {
                System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
                timer.Start();

                /*
                 *      float minred=float.MaxValue, maxred=float.MinValue;
                 *      float minalpha = float.MaxValue, maxalpha = float.MinValue;
                 *      for (int x = 0; x < input.m_Width; x++)
                 *      {
                 *          for (int y = 0; y < input.m_Height; y++)
                 *          {
                 *              Color col = input.GetCol(x, y);
                 *              col.a = col.r;
                 *              minred = Mathf.Min(minred, col.r);
                 *              maxred = Mathf.Max(maxred, col.r);
                 *              minalpha = Mathf.Min(minalpha, col.a);
                 *              maxalpha = Mathf.Max(maxalpha, col.a);
                 *              m_Output.SetPixel((int)(((float)x / (float)input.m_Width) * m_Output.width), (int)(((float)y / (float)input.m_Height) * m_Output.height), col);
                 *              //m_Param.Set(x, y, col.r, col.g, col.b, 1.0f);
                 *          }
                 *      }
                 */
                RenderTexture rt = new RenderTexture(m_Output.width, m_Output.height, 0, RenderTextureFormat.ARGB32);

                Material m = GetMaterial("TextureOps");
                m.SetInt("_MainIsGrey", input.IsGrey() ? 1 : 0);
                m.SetInt("_TextureBIsGrey", input2.IsGrey() ? 1 : 0);
                m.SetTexture("_GradientTex", input2.GetHWSourceTexture());
                string          path     = AssetDatabase.GetAssetPath(m_Output);
                TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(path);
                if (importer.textureType == TextureImporterType.NormalMap)
                {
                    Graphics.Blit(input.GetHWSourceTexture(), rt, m, (int)ShaderOp.CopyNormalMap);

                    RenderTexture.active = rt;
                    m_Output.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
                    //input.DestinationToTexture(m_Output);
                    m_Output.Apply();
                    RenderTexture.active = null;
                    rt.DiscardContents();
                    rt.Release();
                    rt = null;

                    /*
                     *          //unity appears to have changed their internal format
                     *          //so instead save asset as typical normal map png and have unity reimport
                     *
                     *          input.SavePNG(path);
                     *          importer.compressionQuality = importer.compressionQuality + 1; //try and force the import
                     *          importer.crunchedCompression = false;
                     *          importer.SaveAndReimport();
                     *          AssetDatabase.Refresh();
                     */
                }
                else
                {
                    Graphics.Blit(input.GetHWSourceTexture(), rt, m, (int)ShaderOp.CopyColorAndAlpha);

                    RenderTexture.active = rt;
                    m_Output.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
                    //input.DestinationToTexture(m_Output);
                    m_Output.Apply();
                    RenderTexture.active = null;
                    rt.DiscardContents();
                    rt.Release();
                    rt = null;
                }


                if (ms_ExportPNG)
                {
                    SavePNG(m_Output, path);
                    importer.compressionQuality = importer.compressionQuality + 1; //try and force the import
                    importer.SaveAndReimport();
                }



                //            Debug.Log("applied output to "+ m_Output+" time: "+timer.ElapsedMilliseconds+" ms res: "+input.m_Width+" minred "+minred+" max red "+maxred + " minalpha " + minalpha + " max alpha " + maxalpha);
            }


            //Outputs[0].SetValue<TextureParam> (m_Param);
            return(true);
        }
Пример #13
0
        public override bool Calculate()
        {
            if (m_Output == null)
            {
                return(false);
            }
            TextureParam input  = null;
            TextureParam input2 = null;

            if (!GetInput(0, out input))
            {
                return(false);
            }
            if (!GetInput(1, out input2))
            {
                return(false);
            }


            if (m_Output.width != input.m_Width)
            {
                Texture2D texture = new Texture2D(input.m_Width, input.m_Height, TextureFormat.ARGB32, false);
                EditorUtility.CopySerialized(texture, m_Output);
                AssetDatabase.SaveAssets();
            }

            //m_Output.width = 256;
            //m_Output.height = 256;
            //int x = 0, y = 0;
            if (m_Output.format != TextureFormat.ARGB32 && m_Output.format != TextureFormat.RGBA32 && m_Output.format != TextureFormat.RGB24)
            {
                Debug.LogError(" Ouput Texture " + m_Output + "wrong Format " + m_Output.format);
            }
            else
            {
                System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
                timer.Start();

                RenderTexture rt = new RenderTexture(m_Output.width, m_Output.height, 0, RenderTextureFormat.ARGB32);

                Material m = GetMaterial("TextureOps");
                m.SetInt("_MainIsGrey", input.IsGrey() ? 1 : 0);
                m.SetInt("_TextureBIsGrey", input2.IsGrey() ? 1 : 0);
                m.SetTexture("_GradientTex", input2.GetHWSourceTexture());
                string          path     = AssetDatabase.GetAssetPath(m_Output);
                TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(path);
                if (importer.textureType == TextureImporterType.NormalMap)
                {
                    Graphics.Blit(input.GetHWSourceTexture(), rt, m, (int)ShaderOp.CopyNormalMap);

                    RenderTexture.active = rt;
                    m_Output.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
                    //input.DestinationToTexture(m_Output);
                    m_Output.Apply();
                    RenderTexture.active = null;
                    rt.DiscardContents();
                    rt.Release();
                    rt = null;

                    /*
                     *          //unity appears to have changed their internal format
                     *          //so instead save asset as typical normal map png and have unity reimport
                     *
                     *          input.SavePNG(path);
                     *          importer.compressionQuality = importer.compressionQuality + 1; //try and force the import
                     *          importer.crunchedCompression = false;
                     *          importer.SaveAndReimport();
                     *          AssetDatabase.Refresh();
                     */
                }
                else
                {
                    Graphics.Blit(input.GetHWSourceTexture(), rt, m, (int)ShaderOp.CopyColorAndAlpha);

                    RenderTexture.active = rt;
                    m_Output.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
                    //input.DestinationToTexture(m_Output);
                    m_Output.Apply();
                    RenderTexture.active = null;
                    rt.DiscardContents();
                    rt.Release();
                    rt = null;
                }


                if (ms_ExportPNG)
                {
                    if (m_ExportAnimatedAsSingleSpriteSheet)
                    {
                        if (input != null && ms_ExportPNGFrame == 0)
                        {
                            texSpriteSheet = new Texture2D(input.m_Width * (ms_ExportPNGFrameCount + 1), input.m_Height,
                                                           TextureFormat.ARGB32, false);
                        }

                        texSpriteSheet.SetPixels(ms_ExportPNGFrame * input.m_Width, 0, input.m_Width, input.m_Height,
                                                 m_Output.GetPixels(0, 0, input.m_Width, input.m_Height));

                        if (ms_ExportPNGFrame == ms_ExportPNGFrameCount)
                        {
                            path = path.Replace(".png", "Sheet.png");
                            if (UnityTextureOutput.ms_ExportExternal)
                            {
                                Debug.Log("filename is " + Path.GetFileName(path));
                                path = UnityTextureOutput.ms_ExportExternalPath + Path.DirectorySeparatorChar +
                                       Path.GetFileName(path);
                                Debug.Log("new path is " + path);
                            }
                            SavePNG(texSpriteSheet, path, !UnityTextureOutput.ms_ExportExternal);
                        }
                    }
                    else
                    {
                        if (ms_ExportPNGAnimated)
                        {
                            path = path.Replace(".png", "" + ms_ExportPNGFrame + ".png");
                        }
                        if (UnityTextureOutput.ms_ExportExternal)
                        {
                            Debug.Log("filename is " + Path.GetFileName(path));
                            path = UnityTextureOutput.ms_ExportExternalPath + Path.DirectorySeparatorChar +
                                   Path.GetFileName(path);
                            Debug.Log("new path is " + path);
                        }
                        SavePNG(m_Output, path, !UnityTextureOutput.ms_ExportExternal);
                        if (!ms_ExportExternal)
                        {
                            importer.compressionQuality = importer.compressionQuality + 1; //try and force the import
                            importer.SaveAndReimport();
                        }
                    }
                }



                //            Debug.Log("applied output to "+ m_Output+" time: "+timer.ElapsedMilliseconds+" ms res: "+input.m_Width+" minred "+minred+" max red "+maxred + " minalpha " + minalpha + " max alpha " + maxalpha);
            }


            //Outputs[0].SetValue<TextureParam> (m_Param);
            return(true);
        }
        public override bool Calculate()
        {
            if (m_Output == null)
            {
                return(false);
            }
            TextureParam input  = null;
            TextureParam input2 = null;
            TextureParam input3 = null;
            TextureParam input4 = null;

            if (!GetInput(0, out input))
            {
                return(false);
            }
            if (!GetInput(1, out input2))
            {
                return(false);
            }
            if (!GetInput(2, out input3))
            {
                return(false);
            }
            if (!GetInput(3, out input4))
            {
                return(false);
            }


            if (m_Output.width != input.m_Width)
            {
                Texture2D texture = new Texture2D(input.m_Width, input.m_Height, TextureFormat.ARGB32, false);
                EditorUtility.CopySerialized(texture, m_Output);
                AssetDatabase.SaveAssets();
            }

            //m_Output.width = 256;
            //m_Output.height = 256;
            //int x = 0, y = 0;
            if (m_Output.format != TextureFormat.ARGB32 && m_Output.format != TextureFormat.RGBA32 && m_Output.format != TextureFormat.RGB24)
            {
                Debug.LogError(" Ouput Texture " + m_Output + "wrong Format " + m_Output.format);
            }
            else
            {
                System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
                timer.Start();

                RenderTexture rt = new RenderTexture(m_Output.width, m_Output.height, 0, RenderTextureFormat.ARGB32);

                Material m = GetMaterial("TextureOps");
                m.SetInt("_MainIsGrey", input.IsGrey() ? 1 : 0);
                m.SetInt("_TextureBIsGrey", input2.IsGrey() ? 1 : 0);
                m.SetTexture("_GradientTex", input2.GetHWSourceTexture());
                m.SetTexture("_GradientTex2", input3.GetHWSourceTexture());
                m.SetTexture("_GradientTex3", input4.GetHWSourceTexture());
                string          path     = AssetDatabase.GetAssetPath(m_Output);
                TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(path);

                Graphics.Blit(input.GetHWSourceTexture(), rt, m, (int)ShaderOp.CopyRGBAChannels);

                RenderTexture.active = rt;
                m_Output.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
                //input.DestinationToTexture(m_Output);
                m_Output.Apply();
                RenderTexture.active = null;
                rt.DiscardContents();
                rt.Release();

                if (ms_ExportPNG)
                {
                    SavePNG(m_Output, path);
                    importer.compressionQuality = importer.compressionQuality + 1; //try and force the import
                    importer.SaveAndReimport();
                }
            }


            //Outputs[0].SetValue<TextureParam> (m_Param);
            return(true);
        }
        public override bool Calculate()
        {
            if (m_Output == null)
            {
                return(false);
            }
            TextureParam input  = null;
            TextureParam input2 = null;

            if (!GetInput(0, out input))
            {
                return(false);
            }
            if (!GetInput(1, out input2))
            {
                return(false);
            }

            //input.DestinationToTexture(m_Output);

            if (m_Output.width != input.m_Width)
            {
                Texture2D texture = new Texture2D(input.m_Width, input.m_Height, TextureFormat.ARGB32, false);
                EditorUtility.CopySerialized(texture, m_Output);
                AssetDatabase.SaveAssets();
            }
            if (m_Output.format != TextureFormat.ARGB32 && m_Output.format != TextureFormat.RGBA32 && m_Output.format != TextureFormat.RGB24)
            {
                Debug.LogError(" Ouput Texture " + m_Output + "wrong Format " + m_Output.format);
            }
            else
            {
                RenderTexture rt = new RenderTexture(m_Output.width, m_Output.height, 0, RenderTextureFormat.ARGB32);

                Material m = GetMaterial("TextureOps");
                m.SetInt("_MainIsGrey", input.IsGrey() ? 1 : 0);
                m.SetInt("_TextureBIsGrey", input2.IsGrey() ? 1 : 0);
                m.SetTexture("_GradientTex", input2.GetHWSourceTexture());
                Graphics.Blit(input.GetHWSourceTexture(), rt, m, (int)ShaderOp.CopyRandA);

                RenderTexture.active = rt;
                m_Output.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
                //input.DestinationToTexture(m_Output);
                m_Output.Apply();
            }
            string          path     = AssetDatabase.GetAssetPath(m_Output);
            TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(path);

            if (UnityTextureOutput.ms_ExportPNG)
            {
                if (UnityTextureOutput.ms_ExportPNGAnimated)
                {
                    path = path.Replace(".png", "" + UnityTextureOutput.ms_ExportPNGFrame + ".png");
                }
                if (UnityTextureOutput.ms_ExportExternal)
                {
                    Debug.Log("filename is " + Path.GetFileName(path));
                    path = UnityTextureOutput.ms_ExportExternalPath + Path.DirectorySeparatorChar + Path.GetFileName(path);
                    Debug.Log("new path is " + path);
                }
                UnityTextureOutput.SavePNG(m_Output, path, !UnityTextureOutput.ms_ExportExternal);

                importer.compressionQuality = importer.compressionQuality + 1; //try and force the import
                importer.SaveAndReimport();
            }

            //Outputs[0].SetValue<TextureParam> (m_Param);
            return(true);
        }