예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
0
 protected RenderTexture CreateRenderDestination(TextureParam _output)
 {
     return(_output.CreateRenderDestination(m_TexWidth, m_TexHeight, TextureParam.GetRTFormat(m_TexMode == TexMode.Greyscale, m_PixelDepth), m_Filter));
 }
        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);
        }
예제 #5
0
        public override bool Calculate()
        {
            TextureParam input  = null;
            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);
            }
            if (input == null || input2 == null)
            {
                return(false);
            }

            if (m_Param != null)
            {
                //TODO get rid of this crap now each enum has its own class
                switch (m_OpType)
                {
                case TexOp.SmoothDirection:
                    General(input, input2, m_Param, ShaderOp.SmoothedDirection);
                    break;

                case TexOp.Distort:
                    Distort(input, input2, m_Param);
                    break;

                case TexOp.Blend:
                {
                    Material mat = GetMaterial("TextureOps");
                    mat.SetVector("_Multiply", new Vector4(m_Value, m_Value, m_Value, 0));
                    General(input, input2, m_Param, ShaderOp.Blend2);
                }


                break;

                case TexOp.EdgeDistDir:
                {
                    Material mat = GetMaterial("TextureOps");
                    mat.SetVector("_Multiply", new Vector4(m_Value, m_Value2, m_Value, 0));
                    General(input, input2, m_Param, ShaderOp.EdgeDistDir);
                }
                break;

                case TexOp.Gradient:
                    Gradient(input, input2, m_Param);
                    break;

                case TexOp.Add:
                    General(input, input2, m_Param, ShaderOp.Add2);
                    break;

                case TexOp.Min:
                    General(input, input2, m_Param, ShaderOp.Min);
                    //Add(input, input2, m_Param);
                    break;

                case TexOp.Max:
                    General(input, input2, m_Param, ShaderOp.Max);
                    //Add(input, input2, m_Param);
                    break;

                case TexOp.Multiply:
                    General(input, input2, m_Param, ShaderOp.Mult2);
                    break;

                case TexOp.Power:
                    General(input, input2, m_Param, ShaderOp.Pow2);
                    break;

                case TexOp.Sub:
                    General(input, input2, m_Param, ShaderOp.Sub2);
                    //Add(input, input2, m_Param);
                    break;

                case TexOp.DirectionalWarp:
                {
                    Material mat = GetMaterial("TextureOps");
                    mat.SetVector("_Multiply", new Vector4(m_Value, 0, m_Value2, 0));
                    General(input, input2, m_Param, ShaderOp.DirectionWarp);
                }
                break;

                case TexOp.AngleWarp:
                {
                    Material mat = GetMaterial("TextureOps");
                    mat.SetVector("_Multiply", new Vector4(m_Value * Mathf.Deg2Rad, 0, m_Value2, 0));
                    General(input, input2, m_Param, ShaderOp.AngleWarp);
                }
                break;

                case TexOp.SrcBlend:
                {
                    Material mat = GetMaterial("TextureOps");
                    mat.SetVector("_Multiply", new Vector4(m_Value, m_Value, m_Value, 0));
                    General(input, input2, m_Param, ShaderOp.SrcBlend);
                }
                break;

                case TexOp.GridSplatterProb:
                    General(input, input2, m_Param, ShaderOp.SplatterGridProb);
                    break;

                default:
                    Debug.LogError(" un defined texture 2 base op");
                    break;
                }
                //m_Cached = m_Param.GetHWSourceTexture();
                CreateCachedTextureIcon();
            }

            //m_Cached = m_Param.CreateTexture();
            Outputs[0].SetValue <TextureParam> (m_Param);
            return(true);
        }
예제 #6
0
        public void Blend(TextureParam _input, TextureParam _inputB, TextureParam _inputC, 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.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.ProbabilityBlend);

            //output.TexFromRenderTarget();

            //RenderTexture.ReleaseTemporary(destination);
            //        Debug.LogError(" Distort in Final" + timer.ElapsedMilliseconds + " ms");
        }
예제 #7
0
        protected Texture2D gradientY; // = new Texture2D(256, 1, TextureFormat.ARGB32, false);
        public void ExecuteRemapCurve(float _size, TextureParam _output)
        {
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            timer.Start();
            Material mat = GetMaterial("TextureOps");

            mat.SetInt("_MainIsGrey", 1);//_input.IsGrey() ? 1 : 0);
            mat.SetInt("_TextureBIsGrey", 1);
            mat.SetVector("_Multiply", new Vector4(m_RepeatX, m_RepeatY, 0, 0));

            AnimCurveToTexture(ref gradientX, m_RemapCurve);
            AnimCurveToTexture(ref gradientY, m_RemapCurveY);


            mat.SetTexture("_GradientTex", gradientY);
//        mat.SetVector("_TexSizeRecip", new Vector4(1.0f / (float)_input.m_Width, 1.0f / (float)_input.m_Height, _size, 0));
            m_TexMode = TexMode.Greyscale;
            RenderTexture destination = _output.CreateRenderDestination(m_TexWidth, m_TexHeight, TextureParam.GetRTFormat(m_TexMode == TexMode.Greyscale, m_PixelDepth));

            SetCommonVars(mat);
            Graphics.Blit(gradientX, destination, mat, (int)ShaderOp.GenCurve);


//        Debug.LogError(" multiply in Final" + timer.ElapsedMilliseconds + " ms");
        }
예제 #8
0
        public void Generate(TextureParam _output)
        {
            int seed = (int)m_MaterialIndex;

            Random.InitState(seed);
            RenderTexture destination = CreateRenderDestination(null, _output);

            TriangleDraw.GPUStart(destination, GL.LINES);
            List <Vector2> uvs   = new List <Vector2>();
            List <Vector3> norms = new List <Vector3>();
            List <Vector3> pos   = new List <Vector3>();

            if ((int)m_MaterialIndex.m_Value >= m_Mesh.subMeshCount)
            {
                m_MaterialIndex.Set(m_Mesh.subMeshCount - 1);
            }
            int[] indicies = m_Mesh.GetIndices((int)m_MaterialIndex.m_Value);

            m_Mesh.GetUVs(0, uvs);
            m_Mesh.GetNormals(norms);
            m_Mesh.GetVertices(pos);
            Vector3[] averageTri = new Vector3[indicies.Length / 3];
            Dictionary <double, Int64> edgeToTri    = new Dictionary <double, long>();
            Dictionary <Int64, int>    TriTriToEdge = new Dictionary <Int64, int>();

            for (int i = 0; i < indicies.Length; i += 3)
            {
                int     i0 = indicies[i];
                int     i1 = indicies[i + 1];
                int     i2 = indicies[i + 2];
                Vector3 n0 = norms[i0];
                Vector3 n1 = norms[i1];
                Vector3 n2 = norms[i2];

                Vector3 p0 = pos[i0];
                Vector3 p1 = pos[i1];
                Vector3 p2 = pos[i2];

                Vector3 average = (n0 + n1 + n2) * .3333333333f;

                averageTri[i / 3] = average;

                double key         = GetEdgeKey(i0, i1);
                long   triIndex    = (i / 3) + 1;
                long   existingTri = 0;
                edgeToTri.TryGetValue(key, out existingTri);
                Debug.Log(" key " + key + " ia " + i0 + " ib " + i1 + " tri: " + (i / 3) + "existing from dict " + existingTri);

                if (edgeToTri.ContainsKey(key))
                {
                    Int64 tris = edgeToTri[key];
                    if (tris < (1 << 30))
                    {//allready done
                        tris |= triIndex << 32;

                        edgeToTri[key]     = tris;
                        TriTriToEdge[tris] = 0;
                    }
                    else
                    {
                        Debug.LogError("e0 third attempt at tri " + (i / 3));
                    }
                }
                else
                {
                    edgeToTri[key]         = triIndex;
                    TriTriToEdge[triIndex] = 0;
                }

                key = GetEdgeKey(i1, i2);
                edgeToTri.TryGetValue(key, out existingTri);

                Debug.Log(" key " + key + " ia " + i1 + " ib " + i2 + " tri: " + (i / 3) + "existing from dict " + existingTri);
                if (edgeToTri.ContainsKey(key))
                {
                    Int64 tris = edgeToTri[key];
                    if (tris < (1 << 30))
                    {//allready done
                        tris |= triIndex << 32;

                        edgeToTri[key]     = tris;
                        TriTriToEdge[tris] = 1;
                    }
                    else
                    {
                        Debug.LogError("e1 third attempt at tri " + (i / 3));
                    }
                }
                else
                {
                    edgeToTri[key]         = triIndex;
                    TriTriToEdge[triIndex] = 1;
                }
                key = GetEdgeKey(i2, i0);
                edgeToTri.TryGetValue(key, out existingTri);

                Debug.Log(" key " + key + " ia " + i2 + " ib " + i0 + " tri: " + (i / 3) + "existing from dict " + existingTri);
                if (edgeToTri.ContainsKey(key))
                {
                    Int64 tris = edgeToTri[key];
                    if (tris < (1 << 30))
                    {//allready done
                        tris |= triIndex << 32;

                        edgeToTri[key]     = tris;
                        TriTriToEdge[tris] = 2;
                    }
                    else
                    {
                        Debug.LogError("e2 third attempt at tri " + (i / 3));
                    }
                }
                else
                {
                    edgeToTri[key]         = triIndex;
                    TriTriToEdge[triIndex] = 2;
                }
            }


            TriangleDraw.AddCol(Color.white);
            foreach (double key in edgeToTri.Keys)
            {
                long index    = edgeToTri[key];
                int  left     = (int)(index & 0xfffffff) - 1;
                int  right    = (int)((index >> 32) & 0xfffffffff) - 1;
                bool drawEdge = false;
                if (right < 0)
                {
                    drawEdge = false;
                    int     offset = TriTriToEdge[index];
                    int     v0     = left * 3 + offset;
                    int     v1     = left * 3 + ((offset + 1) % 3);
                    Vector3 uv0    = uvs[indicies[v0]];
                    Vector3 uv1    = uvs[indicies[v1]];
                    TriangleDraw.AddVert(new Vector3(uv0.x, uv0.y, 0));
                    TriangleDraw.AddVert(new Vector3(uv1.x, uv1.y, 0));
                }
                else
                {
                    float dot = Vector3.Dot(averageTri[left], averageTri[right]);
                    if (dot < m_EdgeAngleDif && right >= 0)
                    {
                        drawEdge = true;
                    }
                }
                if (drawEdge)
                {
                    int     offset = TriTriToEdge[index];
                    int     v0     = right * 3 + offset;
                    int     v1     = right * 3 + (offset + 1) % 3;
                    Vector3 uv0    = uvs[indicies[v0]];
                    Vector3 uv1    = uvs[indicies[v1]];
                    TriangleDraw.AddVert(new Vector3(uv0.x, uv0.y, 0));
                    TriangleDraw.AddVert(new Vector3(uv1.x, uv1.y, 0));
                }
            }

/*
 *          for (int i = 0; i < indicies.Length; i +=3)
 *          {
 *              Vector3 uv0 = uvs[indicies[i]];
 *              Vector3 uv1 = uvs[indicies[i+1]];
 *              Vector3 uv2 = uvs[indicies[i+2]];
 *              TriangleDraw.AddVert(new Vector3(uv0.x,uv0.y,0));
 *              TriangleDraw.AddVert(new Vector3(uv1.x, uv1.y, 0));
 *
 *              TriangleDraw.AddVert(new Vector3(uv1.x, uv1.y, 0));
 *              TriangleDraw.AddVert(new Vector3(uv2.x, uv2.y, 0));
 *
 *              TriangleDraw.AddVert(new Vector3(uv2.x, uv2.y, 0));
 *              TriangleDraw.AddVert(new Vector3(uv0.x, uv0.y, 0));
 *          }
 */
            TriangleDraw.GPUEnd();
        }
예제 #9
0
        public void Generate(TextureParam _output)
        {
            int seed = (int)m_Seed;

            Random.InitState(seed);
            RenderTexture destination = CreateRenderDestination(null, _output);

            TriangleDraw.GPUStart(destination);
            float angle = 0;;

            Color prevCol = Color.white * (m_OuterBrightness + m_RandomizeOuterBrightness * Random.value);

            prevCol.a = 1;

            Vector3 prev = new Vector3(m_X + Mathf.Cos(angle + m_Angle * Mathf.Deg2Rad) * Radius, m_Y + Mathf.Sin(angle + m_Angle * Mathf.Deg2Rad) * Radius, 0);

            prev += new Vector3((Random.value - 0.5f) * m_RandomizeVertPos, (Random.value - 0.5f) * m_RandomizeVertPos, 0);

            Color midCol = Color.white * (m_InnerBrightness + m_RandomizeInnerBrightness * Random.value);

            midCol.a = 1;

            Vector3 mid = new Vector3(m_X, m_Y, 0);

            mid += new Vector3(Random.value * m_RandomizeVertPos, Random.value * m_RandomizeVertPos, 0);


            Vector3 firstPos = prev;
            Color   firstCol = prevCol;

            int sides = (int)m_Sides;

            float step  = Mathf.PI * 2 / sides;
            float count = 1;

            for (angle = step; angle < Mathf.PI * 2 - step * 0.5f; angle += step, count += 1.0f)
            {
                Vector3 pos = new Vector3(m_X + Mathf.Cos(angle + m_Angle * Mathf.Deg2Rad) * Radius, m_Y + Mathf.Sin(angle + m_Angle * Mathf.Deg2Rad) * Radius, 0);
                pos += new Vector3((Random.value - 0.5f) * m_RandomizeVertPos, (Random.value - 0.5f) * m_RandomizeVertPos, 0);

                Color col       = Color.white * (m_OuterBrightness + m_RandomizeOuterBrightness * Random.value + m_IncrementBrightnessPerVert * count);
                Color midColUse = midCol + Color.white * (m_IncrementBrightnessPerVertMid * count);
                col.a = 1;

                TriangleDraw.AddVertsForTri(
                    prev,
                    mid,
                    pos,
                    prevCol, midColUse, col);
                prev    = pos;
                prevCol = col;
            }

            TriangleDraw.AddVertsForTri(
                prev,
                mid,
                firstPos,
                prevCol, midCol, firstCol);

            TriangleDraw.GPUEnd();
        }
예제 #10
0
        public override bool Calculate()
        {
            allInputsReady();



            if (m_Loops == 0 && (Inputs[0].connection == null || Inputs[0].connection.IsValueNull))//!allInputsReady())
            {
//            Debug.LogError(" m_LoopCount set to 0 input 0 is null");
                m_Loops = 0;
                return(true);
            }
            if (m_Loops > 0 && (Inputs[1].connection == null || Inputs[1].connection.IsValueNull))//!allInputsReady())
            {
//            Debug.LogError(" m_LoopCount set to 1 input 1 is null");
                m_Loops = 1;
                return(true);
            }
            if (m_LoopCount == 0)
            {
                Outputs[1].SetValue <TextureParam>(Inputs[0].GetValue <TextureParam>());
                return(true);
            }
            while (m_Loops < m_LoopCount)
            {
                if (m_Loops == 0)
                {
                    //First iteration set output to the first inteartion input
                    Outputs[0].SetValue <TextureParam>(Inputs[0].GetValue <TextureParam>());
                }
                else
                {
                    //check if any of our connects to Output Looped, output straight back to us
                    //if so that creates a render case where the same renderTexture is the input and the output, so make a copy
                    bool inputIsOutput = false;
                    foreach (var c in Outputs[0].connections)
                    {
                        foreach (var o in c.body.Outputs)
                        {
                            foreach (var c2 in o.connections)
                            {
                                if (c2.body == this)
                                {
                                    inputIsOutput = true;
//                                Debug.LogError("found an in out is the same from " + o.body);
                                }
                            }
                        }
                    }
                    if (inputIsOutput)
                    {
                        Texture rt = Inputs[1].GetValue <TextureParam>().GetHWSourceTexture();
                        if (m_Temp == null || m_Temp.m_Destination == null || m_Temp.m_Destination.width != rt.width || m_Temp.m_Destination.height != rt.height || m_Temp.m_Destination.filterMode != rt.filterMode)
                        {
                            m_Temp = new TextureParam(Inputs[1].GetValue <TextureParam>());
                        }
                        Material m = TextureNode.GetMaterial("TextureOps");
                        Graphics.Blit(rt, m_Temp.m_Destination, m, (int)ShaderOp.CopyColorAndAlpha);

                        Outputs[0].SetValue <TextureParam>(m_Temp);
                    }
                    else
                    {
                        //general loop case set OutLoop to Loop Input
                        Outputs[0].SetValue <TextureParam>(Inputs[1].GetValue <TextureParam>());
                    }
                }

                Outputs[2].SetValue <float>((float)m_Loops / ((float)m_LoopCount - 1.0f));
#if DEBUG_LOOPBASIC
                Debug.LogError("Loop Count Inc" + m_Loops + " / " + m_LoopCount + " percentage " +
                               ((float)m_Loops / (float)m_LoopCount));
#endif
                m_Loops++;

                {
                    Node.ms_GlobalDirtyID++;
                    SetDirty(this);
                    var workList = new List <Node>();
                    if (Outputs[2] != null) //percentage
                    {
                        foreach (var c in Outputs[2].connections)
                        {
                            if (c != null)
                            {
                                if (!workList.Contains(c.body))
                                {
                                    workList.Add(c.body);
                                }
                            }
                        }
                    }
                    if (Outputs[0] != null) //out loop
                    {
                        foreach (var c in Outputs[0].connections)
                        {
                            if (c != null)
                            {
                                if (!workList.Contains(c.body))
                                {
                                    workList.Add(c.body);
                                }
                            }
                        }
                        calculated = false;
                    }
                    if (workList.Count > 0)
                    {
                        calculated = true;                     //so the descendant can calculate that uses output 0
//                    Debug.LogError(NodeEditor.GetPad() + " LoopBasic Executes Worklist");
                        NodeEditor.StartCalculation(workList); //go finish this worklist
//                    Debug.LogError(NodeEditor.GetPad() + " LoopBasic Finished Execute Worklist " + workList.Count);
                        calculated = false;
                    }

                    if (workList.Count != 0)
                    {
/*
 *                  Debug.LogError(NodeEditor.GetPad() + "workList had work left dec loop ");
 *                  foreach (var x in workList)
 *                      Debug.LogError(NodeEditor.GetPad() + "workList had work left " + x);
 */
                        m_Loops--; //we didnt execute
                        return(false);
                    }
                }
            }
            if (m_Loops >= m_LoopCount)
            {
                //Finished set final output
                Outputs[1].SetValue <TextureParam>(Inputs[1].GetValue <TextureParam>());
            }

            bool ret = m_Loops >= m_LoopCount;
//        Debug.Log(NodeEditor.GetPad() +"LoopBasic iterates:  "+m_Loops+"/"+m_LoopCount+" return "+ret);

            return(ret);
        }
        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);
        }