private TerrainSidePixelChangesInfo CalculateSideChangedPixelsShaderRange(
     WeldTextureDrawingSideInfo orderFirstSideInfo, int samplingDistance)
 {
     return(new TerrainSidePixelChangesInfo()
     {
         IsVertical = (orderFirstSideInfo.SideType.GetOrientation() == WeldOrientation.Vertical ? 1 : 0),
         ConstantCoord = orderFirstSideInfo.ConstantCoord,
         SamplingDistance = samplingDistance,
         Range1 = orderFirstSideInfo.FullLodSidePixelsRange.X,
         Range2 = orderFirstSideInfo.FullLodSidePixelsRange.Y,
         Lod = orderFirstSideInfo.LodLevel
     });
 }
        private static WeldTextureDrawingSideInfo CreateDrawingSideInfo(StripSide leader,
                                                                        Vector2 normalizedMarginUvOfTerrain)
        {
            var texSize = new Vector2(leader.HeightTexture.Size.X - 1, leader.HeightTexture.Size.Y - 1);

            texSize = new Vector2(texSize.x / Mathf.Pow(2, leader.Lod), texSize.y / Mathf.Pow(2, leader.Lod));
            var texAreaUvd = RectangleUtils.CalculateSubPosition(new MyRectangle(0, 0, texSize.x, texSize.y),
                                                                 leader.HeightTextureUvs);

            var constantCoord = 0;

            if (leader.WeldSideType == WeldSideType.Right)
            {
                constantCoord = Mathf.RoundToInt(texAreaUvd.MaxX);
            }
            else if (leader.WeldSideType == WeldSideType.Left)
            {
                constantCoord = Mathf.RoundToInt(texAreaUvd.X);
            }
            else if (leader.WeldSideType == WeldSideType.Top)
            {
                constantCoord = Mathf.RoundToInt(texAreaUvd.MaxY);
            }
            else if (leader.WeldSideType == WeldSideType.Bottom)
            {
                constantCoord = Mathf.RoundToInt(texAreaUvd.Y);
            }

            Vector2 baseFullSideRange;

            if (leader.WeldSideType.GetOrientation() == WeldOrientation.Horizontal)
            {
                baseFullSideRange = new Vector2(texAreaUvd.X, texAreaUvd.MaxX);
            }
            else
            {
                baseFullSideRange = new Vector2(texAreaUvd.Y, texAreaUvd.MaxY);
            }
            baseFullSideRange = VectorUtils.CalculateSubPosition(baseFullSideRange, normalizedMarginUvOfTerrain);

            var leaderSideLength = Mathf.RoundToInt(texAreaUvd.Width);

            if (leaderSideLength % 5 == 1)
            {
                leaderSideLength--; //change 241 to 240 etc
            }
            //leaderSideLength /= Mathf.RoundToInt(Mathf.Pow(2, leader.Lod));

            int samplingDistance = 240 / leaderSideLength;


            WeldTextureDrawingSideInfo firstSideInfo = new WeldTextureDrawingSideInfo()
            {
                ConstantCoord          = constantCoord,
                FullLodSidePixelsRange = new IntVector2(Mathf.RoundToInt(baseFullSideRange.x),
                                                        Mathf.RoundToInt(baseFullSideRange.y + 1)),
                HeightTexture    = leader.HeightTexture,
                LodLevel         = leader.Lod,
                SamplingDistance = samplingDistance,
                SideType         = leader.WeldSideType
            };

            return(firstSideInfo);
        }