Ejemplo n.º 1
0
        private Texture2D DecyleTexture(int t_TextureIndex, Texture2D t_CurrentTexture, Vector2 t_DecylePosition, Color t_ColorOfDecyle)
        {
            DecyleTextureInfo t_CurrentDecyleTextureInfo = decyleTextureContainer.decyleTextureInfo[t_TextureIndex];

            int t_PixelInfoX = (int)(t_CurrentDecyleTextureInfo.numberOfHorizontalPixelGroup * t_DecylePosition.x);
            int t_PixelInfoY = (int)(t_CurrentDecyleTextureInfo.numberOfVerticalPixelGroup * t_DecylePosition.y);
            int t_PixelInfo  = t_PixelInfoX + (t_PixelInfoY * t_CurrentDecyleTextureInfo.numberOfHorizontalPixelGroup);

            PixelGroupInfo t_SelectedPixelGroupInfo = t_CurrentDecyleTextureInfo.pixelGroupInfo[t_PixelInfo];

            int t_NumberOfPixelToBeModified = t_SelectedPixelGroupInfo.numberOfPixelsInThisGroup;

            Color t_ColorStartPointOfDecyle = new Color(
                t_ColorOfDecyle.r + ((1f - t_ColorOfDecyle.r) * colorSaturation),
                t_ColorOfDecyle.g + ((1f - t_ColorOfDecyle.g) * colorSaturation),
                t_ColorOfDecyle.b + ((1f - t_ColorOfDecyle.b) * colorSaturation),
                t_ColorOfDecyle.a
                );

            for (int i = 0; i < t_NumberOfPixelToBeModified; i++)
            {
                t_CurrentTexture.SetPixel(
                    t_SelectedPixelGroupInfo.pixelInfo[i].pixelPosition.x,
                    t_SelectedPixelGroupInfo.pixelInfo[i].pixelPosition.y,
                    Color.Lerp(t_ColorOfDecyle, t_ColorStartPointOfDecyle, t_SelectedPixelGroupInfo.pixelInfo[i].colorSaturation));
            }

            t_CurrentTexture.Apply();

            return(t_CurrentTexture);
        }
        public void AddDecyleTextureInfo(Texture2D t_OriginalTexture, DecyleTextureInfo t_DecyleTextureInfo, bool IsOverrideAllow = false)
        {
            bool t_IsDuplicate = false;
            int  t_NumberOfStoredTextureInfoOfDecyle = decyleTextureInfo.Count;

            for (int i = 0; i < t_NumberOfStoredTextureInfoOfDecyle; i++)
            {
                if (decyleTextureInfo[i].texture2D == t_OriginalTexture)
                {
                    if (IsOverrideAllow)
                    {
                        decyleTextureInfo[i] = t_DecyleTextureInfo;
                    }

                    t_IsDuplicate = true;
                    break;
                }
            }

            if (!t_IsDuplicate)
            {
                decyleTextureInfo.Add(t_DecyleTextureInfo);
            }
        }
Ejemplo n.º 3
0
        private void DecyleProcessor(Texture2D t_Texture, bool t_StoreToDatabase = true)
        {
            //Considering

            //m_PixelGroupArea = 0.1f

            //t_Texture                                 = 16x16px
            //t_Height                                  = 16
            //t_Width                                   = 16;

            //t_NumberOfVerticalPixelGroup              = Mathf.CeilToInt(16 * 0.1) = Mathf.CeilTonInt(1.6) = 2
            //t_NumberOfHorizontalPixelGroup            = Mathf.CeilToInt(16 * 0.1) = Mathf.CeilTonInt(1.6) = 2
            //t_TotalNumberOfPixelGroup                 = 2 + 2 = 4

            //t_NumberOfPixelsPerVerticalPixelGroup     = 16 / 2 = 8
            //t_NumberOfPixelsPerHorizontalPixelGroup   = 16 / 2 = 8


            int t_Height = t_Texture.height;
            int t_Width  = t_Texture.width;

            int t_NumberOfVerticalPixelGroup   = Mathf.CeilToInt(t_Height / (t_Height * m_PixelGroupArea * 1f));
            int t_NumberOfHorizontalPixelGroup = Mathf.CeilToInt(t_Width / (t_Width * m_PixelGroupArea * 1f));

            int t_TotalNumberOfPixelGroup = t_NumberOfVerticalPixelGroup * t_NumberOfHorizontalPixelGroup;

            int t_NumberOfPixelsPerVerticalPixelGroup   = Mathf.CeilToInt(t_Height / t_NumberOfVerticalPixelGroup);
            int t_NumberOfPixelsPerHorizontalPixelGroup = Mathf.CeilToInt(t_Width / t_NumberOfHorizontalPixelGroup);

            Debug.Log("(Width, Height) : (" + t_Width + "," + t_Height + ")");
            Debug.Log("(Horizontal, Vertical) : (" + t_NumberOfHorizontalPixelGroup + "," + t_NumberOfVerticalPixelGroup + ")");
            Debug.Log("(PixelOnHorizontal, PixelOnVertical) : (" + t_NumberOfPixelsPerHorizontalPixelGroup + "," + t_NumberOfPixelsPerVerticalPixelGroup + ")");

            float t_RadiusOfCirclePixel         = Mathf.Sqrt(Mathf.Pow(t_NumberOfPixelsPerHorizontalPixelGroup / 2f, 2) + Mathf.Pow(t_NumberOfPixelsPerVerticalPixelGroup / 2f, 2));
            float t_ExtendedRadiusOfCirclePixel = t_RadiusOfCirclePixel * defaultPixelSpreadArea;
            float t_CurrentDistance;
            float t_ValueMiltiplier;

            int t_PixelGroupPositionX;
            int t_PixelGroupPositionY;
            int t_PixelGroupIndex;

            DecyleTextureInfo t_NewDecyleTexture = new DecyleTextureInfo(t_Texture);

            t_NewDecyleTexture.CretatePixelGroup(
                t_NumberOfVerticalPixelGroup,
                t_NumberOfHorizontalPixelGroup,
                t_NumberOfPixelsPerVerticalPixelGroup,
                t_NumberOfPixelsPerHorizontalPixelGroup);

            for (int i = 0; i < t_Width; i++)
            {
                for (int j = 0; j < t_Height; j++)
                {
                    switch (m_DecyleShape)
                    {
                    case DecyleShape.circle:

                        for (int k = 0; k < t_NewDecyleTexture.numberOfPixelGroupInfo; k++)
                        {
                            Vector2Int t_PixelGroupPosition = t_NewDecyleTexture.pixelGroupInfo[k].pixelGroupPosition;
                            Vector2Int t_PixelPosition      = new Vector2Int(i, j);

                            t_CurrentDistance = Vector2Int.Distance(t_PixelGroupPosition, t_PixelPosition);

                            if (t_CurrentDistance <= t_RadiusOfCirclePixel)
                            {
                                t_ValueMiltiplier = t_CurrentDistance / t_RadiusOfCirclePixel;

                                t_NewDecyleTexture.pixelGroupInfo[k].pixelInfo.Add(new PixelInfo(
                                                                                       1f,
                                                                                       t_ValueMiltiplier * 0.5f,
                                                                                       new Vector2Int(i, j)
                                                                                       ));
                            }
                            else if ((Random.Range(0f, 1f) <= defaultPixelDensityOnSpreadingArea) && (t_CurrentDistance <= t_ExtendedRadiusOfCirclePixel))
                            {
                                t_ValueMiltiplier = t_CurrentDistance / t_ExtendedRadiusOfCirclePixel;

                                t_NewDecyleTexture.pixelGroupInfo[k].pixelInfo.Add(new PixelInfo(
                                                                                       1f,
                                                                                       t_ValueMiltiplier,
                                                                                       new Vector2Int(i, j)
                                                                                       ));
                            }
                        }

                        break;

                    case DecyleShape.square:

                        t_PixelGroupPositionX = i / (t_NumberOfPixelsPerHorizontalPixelGroup * 1);
                        t_PixelGroupPositionY = j / (t_NumberOfPixelsPerVerticalPixelGroup * 1);

                        t_PixelGroupIndex = t_PixelGroupPositionX + (t_PixelGroupPositionY * t_NumberOfHorizontalPixelGroup);

                        t_NewDecyleTexture.pixelGroupInfo[t_PixelGroupIndex].pixelInfo.Add(new PixelInfo(
                                                                                               1f,
                                                                                               1f,
                                                                                               new Vector2Int(i, j)
                                                                                               ));
                        break;
                    }
                }
            }

            for (int pixelGroupIndex = 0; pixelGroupIndex < t_TotalNumberOfPixelGroup; pixelGroupIndex++)
            {
                t_NewDecyleTexture.pixelGroupInfo[pixelGroupIndex].CountTheNumberOfPixelInThisGroup();
            }

            decyleTextureContainer.AddDecyleTextureInfo(t_Texture, t_NewDecyleTexture, IsOverrideAllow);
        }