void TerrainDeform(Vector3 position, float craterSizeInMeters)
    {
        Vector3 terrainPosition = GetRelativeTerrainPositionFromPosition(position, heightmapSize);
        TextureSize heightmapCrater = new TextureSize(
            (int) (craterSizeInMeters * (heightmapSize.width / terrain.terrainData.size.x)),
            (int) (craterSizeInMeters * (heightmapSize.height / terrain.terrainData.size.z)));
        int heightmapStartPositionX = (int) (terrainPosition.x - (heightmapCrater.width/2));
        int heightmapStartPositionZ = (int) (terrainPosition.z - (heightmapCrater.height/2));

        float [,] heights = terrain.terrainData.GetHeights(heightmapStartPositionX, heightmapStartPositionZ, heightmapCrater.width, heightmapCrater.height);
        Vector2 circlePos;
        float distanceFromCenter;
        float depthMultiplier;

        float deformationDepth = (craterSizeInMeters / 3.0f) / terrain.terrainData.size.y;

        for (int i=0; i<heightmapCrater.height; i++){
            for (int j=0; j<heightmapCrater.width;j++){
                circlePos.x = (j - (heightmapCrater.width/2) /  (heightmapSize.width / terrain.terrainData.size.x));
                circlePos.y = (i - (heightmapCrater.height/2) /  (heightmapSize.height / terrain.terrainData.size.z));
                distanceFromCenter = Mathf.Abs(Mathf.Sqrt(circlePos.x * circlePos.x + circlePos.y * circlePos.y));

                if (distanceFromCenter < (craterSizeInMeters / 2.0f)){
                    depthMultiplier = ((craterSizeInMeters / 2.0f - distanceFromCenter) / craterSizeInMeters / 2.0f) + .1f;
                    depthMultiplier += Random.value * .1f;
                    depthMultiplier = Mathf.Clamp(depthMultiplier, 0, 1);
                    heights[i,j] = Mathf.Clamp(heights[i,j] - deformationDepth * depthMultiplier, 0, 1);
                }
            }
        }
        terrain.terrainData.SetHeights(heightmapStartPositionX, heightmapStartPositionZ, heights);
    }
Esempio n. 2
0
    //------------------------------------------
    public CircleObj GetCircle(TextureSize textureSize)
    {
        CircleObj obj;
        Color     color1 = new Color(0f, 0f, 0f, 0.6f);
        Color     color2 = new Color(0f, 0f, 0f, 0.6f);
        Color     color3 = new Color(0f, 0f, 0f, 0.6f);

        if (++numCircles >= PoolLength)
        {
            numCircles = 0;
        }
        obj = circlesPool[numCircles];
        obj.Model.renderer.material             = materialsPool[numCircles];
        obj.Model.renderer.material.mainTexture = texturesPool[textureSize][numCircles];
        GenerateTexture(textureSize, numCircles);

        color1.r = Random.Range(0f, 1f);
        color1.g = Random.Range(0f, 1f);
        color1.b = Random.Range(0f, 1f);

        color2.r = Random.Range(0f, 1f);
        color2.g = Random.Range(0f, 1f);
        color2.b = Random.Range(0f, 1f);

        color3.r = Random.Range(0f, 1f);
        color3.g = Random.Range(0f, 1f);
        color3.b = Random.Range(0f, 1f);

        obj.Model.renderer.material.SetColor("_Color1", color1);
        obj.Model.renderer.material.SetColor("_Color2", color2);
        obj.Model.renderer.material.SetColor("_Color3", color3);

        return(obj);
    }
Esempio n. 3
0
        public static string ChromaScaleDescription(TextureSize size)
        {
            var chromaConvolver = Renderer.ChromaOffset.IsZero ? null : Renderer.ChromaUpscaler;
            var chromastatus    = StatusHelpers.ScaleDescription(Renderer.ChromaSize, size, Renderer.ChromaUpscaler, Renderer.ChromaDownscaler, chromaConvolver);

            return(chromastatus.AddPrefixToDescription("Chroma: "));
        }
Esempio n. 4
0
 /// <summary>
 ///     Constructs a <see cref="BakeProbeOptions" /> with default values and returns it.
 /// </summary>
 /// <returns>A <see cref="BakeProbeOptions" /> with default values.</returns>
 public static BakeProbeOptions NewDefault()
 {
     return(new BakeProbeOptions
     {
         textureSize = TextureSize.NewDefault()
     });
 }
Esempio n. 5
0
        public override IEnumerator ReceivePayload(VisualPayload payload)
        {
            var textureSize = TextureSize.GetFirstValue(payload.Data);

            var newTexture = new Texture2D(textureSize, textureSize);

            var newPixels = new Color[textureSize * textureSize];

            var gradient = ColorGradient.GetFirstValue(payload.Data);

            for (int x = 0; x < textureSize; x++)
            {
                for (int y = 0; y < textureSize; y++)
                {
                    var proportion = x / (float)textureSize;
                    var color      = gradient.Evaluate(proportion);
                    newPixels[x + y * textureSize] = color;
                }
            }

            newTexture.SetPixels(newPixels);

            newTexture.Apply();

            TextureTarget.SetValue(newTexture, payload.Data);

            var iterator = Router.TransmitAll(payload);

            while (iterator.MoveNext())
            {
                yield return(null);
            }
        }
Esempio n. 6
0
 public TextureArraySettings(TextureSize s, Compression c, FilterMode f, int a = 1)
 {
     textureSize = s;
     compression = c;
     filterMode  = f;
     Aniso       = a;
 }
 public override int GetHashCode()
 {
     return(TextureSize.GetHashCode() ^
            Size.GetHashCode() ^
            Border.GetHashCode() ^
            BackgroundStyle.GetHashCode());
 }
 public override int GetHashCode()
 {
     return(base.GetHashCode() ^
            Layout.GetHashCode() ^
            Texture.GetHashCode() ^
            TextureSize.GetHashCode());
 }
            private void DownscaleAndCalcVar(ITextureFilter input, TextureSize targetSize, out ITextureFilter mean, out ITextureFilter var)
            {
                var HDownscaler = new Shader(FromFile(SoftDownscaling ? "SoftDownscaler.hlsl" : "./Scalers/Downscaler.hlsl", compilerOptions: "axis = 0;"))
                {
                    Transform = s => new TextureSize(targetSize.Width, s.Height), Format = input.Output.Format
                };
                var VDownscaler = new Shader(FromFile(SoftDownscaling ? "SoftDownscaler.hlsl" : "./Scalers/Downscaler.hlsl", compilerOptions: "axis = 1;"))
                {
                    Transform = s => new TextureSize(s.Width, targetSize.Height), Format = input.Output.Format
                };
                var HVar = new Shader(FromFile("DownscaledVarI.hlsl", compilerOptions: "axis = 0;"))
                {
                    Transform = s => new TextureSize(targetSize.Width, s.Height), Format = input.Output.Format
                };
                var VVar = new Shader(FromFile("DownscaledVarII.hlsl", compilerOptions: "axis = 1;"))
                {
                    Transform = s => new TextureSize(s.Width, targetSize.Height), Format = input.Output.Format
                };

                var hMean = HDownscaler.ApplyTo(input);

                mean = VDownscaler.ApplyTo(hMean);

                var hVariance = HVar.ApplyTo(input, hMean);

                var = VVar.ApplyTo(hVariance, hMean, mean);
            }
        public override IEnumerator ReceivePayload(VisualPayload payload)
        {
            foreach (var entry in Scope.GetEntries(payload.Data))
            {
                var textureSize = TextureSize.GetValue(entry);

                var newTexture = new Texture2D(textureSize, textureSize);

                var primaryColor = PrimaryColor.GetValue(entry);

                var newPixels = Enumerable.Repeat(primaryColor, textureSize * textureSize).ToArray();

                newTexture.SetPixels(newPixels);

                newTexture.Apply();

                TextureTarget.SetValue(newTexture, entry);
            }

            var iterator = Router.TransmitAll(payload);

            while (iterator.MoveNext())
            {
                yield return(null);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Get the size of the texture
        /// </summary>
        /// <param name="size">Texture size</param>
        /// <returns>Texture size or zero if invalid</returns>
        public static int GetTextureSize(TextureSize size)
        {
            switch (size)
            {
            case CTSConstants.TextureSize.Texture_64:
                return(64);

            case CTSConstants.TextureSize.Texture_128:
                return(128);

            case CTSConstants.TextureSize.Texture_256:
                return(256);

            case CTSConstants.TextureSize.Texture_512:
                return(512);

            case CTSConstants.TextureSize.Texture_1024:
                return(1024);

            case CTSConstants.TextureSize.Texture_2048:
                return(2048);

            case CTSConstants.TextureSize.Texture_4096:
                return(4096);

            case CTSConstants.TextureSize.Texture_8192:
                return(8192);
            }
            //Invalid setting passed in
            return(0);
        }
Esempio n. 12
0
 public NNedi3HKernelFilter(IShaderFilterSettings <IKernel> settings, IDisposable buffer, int neuronCount, TextureSize textureSize, int[] localWorkSizes,
                            ITextureFilter <IBaseTexture> inputFilter)
     : base(settings, GlobalWorkSizesHelper.Get(textureSize.Height, textureSize.Width, localWorkSizes), localWorkSizes, inputFilter)
 {
     m_Buffer      = buffer;
     m_NeuronCount = neuronCount;
     m_TextureSize = textureSize;
 }
Esempio n. 13
0
        public void ValidTest()
        {
            TextureSize textureSize = new TextureSize(16, 16);

            Size2 value = textureSize;

            Assert.AreEqual(value.Width, 16);
            Assert.AreEqual(value.Height, 16);
        }
        //------------------------------------------------------------------------------------------------------------------
        private void DrawTextureSizeSelector(ProTexMaterialBinder proTexMaterialBinder)
        {
            TextureSize textureSize    = GetTextureSize(proTexMaterialBinder);
            TextureSize newTextureSize = (TextureSize)EditorGUILayout.EnumPopup(textureSize);

            if (textureSize != newTextureSize)
            {
                proTexMaterialBinder.runtimeTextureSize = (int)newTextureSize;
            }
        }
Esempio n. 15
0
        public static IEnumerable <string> ScaleDescription(TextureSize size)
        {
            var chromaConvolver = Renderer.ChromaOffset.IsZero ? null : Renderer.ChromaUpscaler;
            var chromastatus    = StatusHelpers.ScaleDescription(Renderer.ChromaSize, size, Renderer.ChromaUpscaler, Renderer.ChromaDownscaler, chromaConvolver);
            var lumastatus      = StatusHelpers.ScaleDescription(Renderer.VideoSize, size, Renderer.LumaUpscaler, Renderer.LumaDownscaler);

            yield return(chromastatus.PrependToDescription("Chroma: "));

            yield return(lumastatus.PrependToDescription("Luma: "));
        }
Esempio n. 16
0
//	public  int fibonacy_binary (int value , int max){
//		if (value > max)
//			return max;
//		if (max / 2 < value)
//			return max;
//
//
//		return fibonacy_binary (value, max / 2);
//
//
//	}
    TextureSize GetTextureSize(TextureImporter textureImporter)
    {
        var method = typeof(TextureImporter).GetMethod("GetWidthAndHeight", BindingFlags.NonPublic | BindingFlags.Instance);

        textureSizeDelegate = System.Delegate.CreateDelegate(typeof(GetTextureSize), method) as GetTextureSize;
        TextureSize size = new TextureSize();

        textureSizeDelegate.Invoke(textureImporter, ref size.width, ref size.height);
        return(size);
    }
Esempio n. 17
0
        public ITextureFilter SetSize(TextureSize targetSize)
        {
            var result = new ResizeFilter(InputFilter, targetSize, m_Channels, m_Offset, m_Upscaler, m_Downscaler, m_Convolver, Output.Format);

            if (m_Tagged)
            {
                result.EnableTag();
            }
            return(result);
        }
Esempio n. 18
0
 private void LoadSizeConstant(string identifier, TextureSize size)
 {
     if (size.Is3D)
     {
         SetConstant(string.Format("size3d{0}", identifier), new Vector4(size.Width, size.Height, size.Depth, 0));
     }
     else
     {
         SetConstant(string.Format("size{0}", identifier), new Vector4(size.Width, size.Height, 1.0f / size.Width, 1.0f / size.Height));
     }
 }
    Vector3 GetRelativeTerrainPositionFromPosition(Vector3 position, TextureSize map)
    {
        Vector3 tmpCoord = (position - terrain.gameObject.transform.position);
        Vector3 coord;

        coord.x = tmpCoord.x / terrain.terrainData.size.x;
        coord.y = tmpCoord.y / terrain.terrainData.size.y;
        coord.z = tmpCoord.z / terrain.terrainData.size.z;

        return new Vector3((coord.x * map.width), 0, (coord.z * map.height));
    }
Esempio n. 20
0
            protected override ITextureFilter CreateFilter(ITextureFilter input)
            {
                if (Renderer.InputFormat.IsRgb())
                {
                    return(input);
                }

                int bits = Renderer.InputFormat.GetBitDepth();

                if (bits > MaxBitDepth)
                {
                    return(input);
                }

                float[] consts =
                {
                    (1 << bits) - 1,
                    Power
                };

                var Deband = new Shader(FromFile("Deband.hlsl", compilerOptions: PreserveDetail ? "PRESERVE_DETAIL=1" : ""))
                {
                    Arguments = consts,
                    PerTextureLinearSampling = new[] { true, false }
                };

                ITextureFilter yuv       = input.ConvertToYuv();
                var            inputsize = yuv.Size();

                var    deband = yuv;
                double factor = 2.0;// 0.5 * Math.Sqrt(5) + 0.5;

                int maxWidth = Math.Min(Math.Min(inputsize.Width, inputsize.Height) / 3, 256);
                int max      = (int)Math.Floor(Math.Log(maxWidth, factor));

                for (int i = max; i >= 0; i--)
                {
                    double scale = Math.Pow(factor, i);
                    var    size  = new TextureSize((int)Math.Round(inputsize.Width / scale), (int)Math.Round(inputsize.Height / scale));
                    if (size.Width == 0 || size.Height == 0)
                    {
                        continue;
                    }
                    if (i == 0)
                    {
                        size = inputsize;
                    }

                    Deband.Transform = s => size;
                    deband           = Deband.ApplyTo(yuv, deband);
                }

                return(deband.ConvertToRgb());
            }
Esempio n. 21
0
        public ResizeFilter(IFilter <ITextureOutput <ITexture2D> > inputFilter, TextureSize outputSize, TextureChannels channels, Vector2 offset, IScaler upscaler = null, IScaler downscaler = null, IScaler convolver = null, TextureFormat?outputFormat = null)
            : base(outputSize, outputFormat ?? inputFilter.Output.Format, inputFilter)
        {
            m_OutputSize = outputSize;
            m_Channels   = channels;
            m_Offset     = offset;

            m_Upscaler   = upscaler ?? Renderer.LumaUpscaler;
            m_Downscaler = downscaler ?? Renderer.LumaDownscaler;
            m_Convolver  = convolver;
        }
Esempio n. 22
0
            public override IFilter CreateFilter(IFilter input)
            {
                if (Renderer.InputFormat.IsRgb())
                {
                    return(input);
                }

                int bits = Renderer.InputFormat.GetBitDepth();

                if (bits > maxbitdepth)
                {
                    return(input);
                }

                float[] consts =
                {
                    (1 << bits) - 1,
                    power
                };

                var Deband = CompileShader("Deband.hlsl", macroDefinitions: !grain ? "SkipDithering=1" : "")
                             .Configure(arguments: consts, perTextureLinearSampling: new[] { true, false });

                /*var Subtract = CompileShader("Subtract.hlsl")
                 *  .Configure(perTextureLinearSampling: new[] { false, true }, format: TextureFormat.Float16);
                 * var SubtractLimited = CompileShader("SubtractLimited.hlsl")
                 *  .Configure(perTextureLinearSampling: new[] { false, true }, arguments: Consts);*/

                IFilter yuv       = input.ConvertToYuv();
                var     inputsize = yuv.OutputSize;

                var    deband = yuv;
                double factor = 2.0;// 0.5 * Math.Sqrt(5) + 0.5;

                int max = (int)Math.Floor(Math.Log(Math.Min(inputsize.Width, inputsize.Height) / 3.0, factor));

                for (int i = max; i >= 0; i--)
                {
                    double scale = Math.Pow(factor, i);
                    var    size  = new TextureSize((int)Math.Round(inputsize.Width / scale), (int)Math.Round(inputsize.Height / scale));
                    if (size.Width == 0 || size.Height == 0)
                    {
                        continue;
                    }
                    if (i == 0)
                    {
                        size = inputsize;
                    }

                    deband = new ShaderFilter(Deband.Configure(transform: s => size), yuv, deband);
                }

                return(deband.ConvertToRgb());
            }
    static int GetTextureSize(TextureSize type)
    {
        switch (type)
        {
        case TextureSize.MAX_1024: return(1024);

        case TextureSize.MAX_2048: return(2048);

        case TextureSize.MAX_4096: return(4096);
        }
        return(1024);
    }
Esempio n. 24
0
            public Process(TextureSize outputSize, TextureChannels channels, Vector2 offset, IScaler upscaler = null, IScaler downscaler = null, IScaler convolver = null, TextureFormat?outputFormat = null)
            {
                m_OutputSize = outputSize;
                m_Channels   = channels;
                m_Offset     = offset;

                m_Format = outputFormat;

                m_Upscaler   = upscaler ?? Renderer.LumaUpscaler;
                m_Downscaler = downscaler ?? Renderer.LumaDownscaler;
                m_Convolver  = convolver;
            }
    void Start()
    {
        terrain=gameObject.GetComponent<Terrain>();
        heightmapSize = new TextureSize(terrain.terrainData.heightmapWidth,terrain.terrainData.heightmapHeight);
        alphamapSize = new TextureSize(terrain.terrainData.alphamapWidth,terrain.terrainData.alphamapHeight);
        numberOfAlphaLayers = terrain.terrainData.alphamapLayers;

        if (Debug.isDebugBuild){
            heightmapBackup = terrain.terrainData.GetHeights(0, 0, heightmapSize.width, heightmapSize.height);
            alphamapBackup = terrain.terrainData.GetAlphamaps(0, 0, alphamapSize.width, alphamapSize.height);
        }
    }
Esempio n. 26
0
        public VideoSourceFilter(TrueSourceFilter trueSource, TextureSize?outputSize = null, bool?wantYuv = null)
            : base(trueSource)
        {
            m_TrueSource = trueSource;
            m_OutputSize = outputSize ?? trueSource.OutputSize;
            m_WantYuv    = wantYuv ?? trueSource.WantYuv;

            if (m_WantYuv)
            {
                m_TrueSource.WantYuv = true;
            }
            m_TrueSource.OutputSize = m_OutputSize;
        }
        public override IEnumerator ReceivePayload(VisualPayload payload)
        {
            var textureSize = TextureSize.GetFirstValue(payload.Data);

            var entropy = Entropy.GetFirstValue(payload.Data);

            var entropySteps = (from step in EntropySteps.GetFirstValue(payload.Data).Split(',') select float.Parse(step.Trim())).ToArray();

            var minimumEntropyLevels = MinimumEntropyLevels.GetFirstValue(payload.Data);

            var colorOne = ColorOne.GetFirstValue(payload.Data);
            var colorTwo = ColorTwo.GetFirstValue(payload.Data);

            var entropyGridTexture = new Texture2D(textureSize, textureSize);

            var entropyLevel = 0;

            while (entropyLevel < entropySteps.Length && entropy > entropySteps[entropyLevel])
            {
                entropyLevel++;
            }

            entropyLevel += minimumEntropyLevels;

            var pixels = new Color[textureSize * textureSize];

            for (int x = 0; x < textureSize; x++)
            {
                for (int y = 0; y < textureSize; y++)
                {
                    var xImpact = Mathf.FloorToInt((x / (float)textureSize) * entropyLevel);
                    var yImpact = Mathf.FloorToInt((y / (float)textureSize) * entropyLevel);
                    pixels[x + y * textureSize] = ((xImpact + yImpact) % 2) == 1 ? colorOne : colorTwo;
                }
            }

            entropyGridTexture.SetPixels(pixels);

            entropyGridTexture.Apply();

            TextureTarget.SetValue(entropyGridTexture, payload.Data);

            var iterator = Router.TransmitAll(payload);

            while (iterator.MoveNext())
            {
                yield return(null);
            }
        }
Esempio n. 28
0
        public static string ScaleDescription(TextureSize inputSize, TextureSize outputSize, IScaler upscaler, IScaler downscaler, IScaler convolver = null)
        {
            var xDesc = ScaleDescription(inputSize.Width, outputSize.Width, upscaler, downscaler, convolver);
            var yDesc = ScaleDescription(inputSize.Height, outputSize.Height, upscaler, downscaler, convolver);

            if (xDesc == yDesc)
            {
                return(xDesc);
            }

            xDesc = xDesc.PrependToStatus("X:");
            yDesc = yDesc.PrependToStatus("Y:");

            return(xDesc.AppendStatus(yDesc));
        }
Esempio n. 29
0
 /// <summary>
 /// Builds resource description for a render target texture array
 /// </summary>
 /// <param name="size">Texture size</param>
 /// <param name="format">Texture format</param>
 /// <param name="arraySize">Texture array element count</param>
 /// <returns>Texture2D Description</returns>
 public static Texture2DDescription GetRenderTargetTextureArray(TextureSize size, Format format, int arraySize)
 {
     return(new Texture2DDescription()
     {
         ArraySize = arraySize,
         BindFlags = BindFlags.ShaderResource | BindFlags.RenderTarget,
         CpuAccessFlags = CpuAccessFlags.None,
         Format = format,
         Height = size.Height,
         MipLevels = 1,
         OptionFlags = ResourceOptionFlags.None,
         SampleDescription = new SampleDescription(1, 0),
         Usage = ResourceUsage.Default,
         Width = size.Width
     });
 }
Esempio n. 30
0
 /// <summary>
 /// Gets an immutable texture description, data can be uploaded thread free
 /// </summary>
 /// <param name="size">Texture size</param>
 /// <param name="format">Texture format</param>
 /// <returns>Direct3D11 Texture description</returns>
 public static Texture2DDescription GetImmutableTexture(TextureSize size, Format format)
 {
     return(new Texture2DDescription()
     {
         ArraySize = 1,
         BindFlags = BindFlags.ShaderResource,
         CpuAccessFlags = CpuAccessFlags.None,
         Format = format,
         Height = size.Height,
         MipLevels = 1,
         OptionFlags = ResourceOptionFlags.None,
         SampleDescription = new SampleDescription(1, 0),
         Usage = ResourceUsage.Immutable,
         Width = size.Width
     });
 }
Esempio n. 31
0
    void OnPreprocessTexture()
    {
        if (!setting.enableTextureImporter)
        {
            return;
        }

        TextureImporter textureImporter = (TextureImporter)assetImporter;

        textureImporter.sRGBTexture = true;
        TextureSize size = GetTextureSize(textureImporter);
        int         max  = size.width > size.height ? size.width : size.height;

        max = max.round_max(setting.textureMaxSize, 0x02);
        textureImporter.maxTextureSize     = max;
        textureImporter.textureCompression = TextureImporterCompression.Uncompressed;
    }
Esempio n. 32
0
    //-----------------------------------------
    private void GenerateTexture(TextureSize size, int num)
    {
        Color _color = new Color(0f, 0f, 0f, 1f);

        Color[] _pix = new Color[0];
        int     y    = 0;
        int     x    = 0;
        int     h    = texturesPool[size][num].height;
        int     w    = texturesPool[size][num].width;

        switch (size)
        {
        case TextureSize.s32:
            _pix = _pix32;
            break;

        case TextureSize.s64:
            _pix = _pix64;
            break;

        case TextureSize.s128:
            _pix = _pix128;
            break;

        case TextureSize.s256:
            _pix = _pix256;
            break;
        }

        while (y < h)
        {
            x = 0;
            while (x < w)
            {
                _color.r        = Random.Range(0f, 1f);
                _color.g        = Random.Range(0f, 1f);
                _color.b        = Random.Range(0f, 1f);
                _pix[y * w + x] = _color;
                x++;
            }
            y++;
        }
        texturesPool[size][num].SetPixels(_pix);
        texturesPool[size][num].Apply();
    }
Esempio n. 33
0
            private TextureSize CalculateSize(TextureSize sizeA, TextureSize sizeB, int k)
            {
                double w, h;
                var    MaxScale = 2.0;
                var    MinScale = Math.Sqrt(MaxScale);

                int minW = sizeA.Width; int minH = sizeA.Height;
                int maxW = sizeB.Width; int maxH = sizeB.Height;

                int maxSteps = (int)Math.Floor(Math.Log((double)(maxH * maxW) / (double)(minH * minW)) / (2 * Math.Log(MinScale)));
                int minSteps = (int)Math.Ceiling(Math.Log((double)(maxH * maxW) / (double)(minH * minW)) / (2 * Math.Log(MaxScale)));
                int steps    = Math.Max(Math.Max(1, minSteps), Math.Min(maxSteps, Passes - (k - 1)));

                w = minW * Math.Pow((double)maxW / (double)minW, (double)Math.Min(k, steps) / (double)steps);
                h = minW * Math.Pow((double)maxH / (double)minH, (double)Math.Min(k, steps) / (double)steps);

                return(new TextureSize(Math.Max(minW, Math.Min(maxW, (int)Math.Round(w))),
                                       Math.Max(minH, Math.Min(maxH, (int)Math.Round(h)))));
            }
    void TextureDeform(Vector3 position, float craterSizeInMeters)
    {
        Vector3 alphamapTerrainPosition = GetRelativeTerrainPositionFromPosition(position, alphamapSize);
        TextureSize alphamapCrater = new TextureSize(
            (int) (craterSizeInMeters * (alphamapSize.width / terrain.terrainData.size.x)),
            (int) (craterSizeInMeters * (alphamapSize.height / terrain.terrainData.size.z)));

        int alphamapStartPosX = (int)(alphamapTerrainPosition.x - (alphamapCrater.width / 2));
        int alphamapStartPosZ = (int)(alphamapTerrainPosition.z - (alphamapCrater.height/2));

        float[, ,] alphas = terrain.terrainData.GetAlphamaps(alphamapStartPosX, alphamapStartPosZ, alphamapCrater.width, alphamapCrater.height);
        float circlePosX;
        float circlePosY;
        float distanceFromCenter;

        for (int i=0;i<alphamapCrater.height;i++){
            for(int j=0;j<alphamapCrater.width;j++){
                circlePosX = (j - (alphamapCrater.width / 2)) / (alphamapSize.width / terrain.terrainData.size.x);
                circlePosY = (i - (alphamapCrater.height / 2)) / (alphamapSize.height / terrain.terrainData.size.z);

                distanceFromCenter = Mathf.Abs(Mathf.Sqrt(circlePosX * circlePosX + circlePosY * circlePosY));

            if (distanceFromCenter < (craterSizeInMeters / 2.0f)){
                for (int layerCounter=0;layerCounter<numberOfAlphaLayers;layerCounter++){
                    //if(layerCounter==deformationTextureIDs[0]){
                    //if(layerCounter==deformationTextureIDs[Random.Range(0, deformationTextureIDs.Length)]){
                    if(layerCounter==explosionTexIdx){
                        alphas[i,j,layerCounter]=1;
                    }
                    else{
                        alphas[i,j,layerCounter]=0;
                    }
                }
            }
        }
        }
        terrain.terrainData.SetAlphamaps(alphamapStartPosX, alphamapStartPosZ, alphas);
    }