Example #1
0
        public void Start_Hydraulic()
        {
            var heightTexture1 =
                SavingFileManager.LoadPngTextureFromFile(@"C:\inz\cont\temp3.png", 240, 240, TextureFormat.RGBA32, true,
                                                         true);
            var heightmap1 = HeightmapUtils.CreateHeightmapArrayFromTexture(heightTexture1);

            //DiamondSquareCreator creator = new DiamondSquareCreator(new RandomProvider(22));
            //var heightmap2 = creator.CreateDiamondSquareNoiseArray(new IntVector2(240, 240), 64);
            //MyArrayUtils.Multiply(heightmap2.HeightmapAsArray, 0.1f);

            var tParam = EroderDebugObject.CalculateFromHillFactor(1, new ArrayExtremes(0, 5000), 24);

            var extents = MyArrayUtils.CalculateExtremes(heightmap1.HeightmapAsArray);

            MyArrayUtils.Normalize(heightmap1.HeightmapAsArray);

            var erodedArrays = GenerateHydraulicErodedArrays(heightmap1, new List <HydraulicEroderConfiguration>()
            {
                new HydraulicEroderConfiguration()
                {
                    StepCount                  = 40,
                    NeighbourFinder            = NeighbourFinders.Big9Finder,
                    kr_ConstantWaterAddition   = 0.001f,
                    ks_GroundToSedimentFactor  = 1f,
                    ke_WaterEvaporationFactor  = 0.05f,
                    kc_MaxSedimentationFactor  = 0.8f,
                    FinalSedimentationToGround = true,
                    WaterGenerator             = HydraulicEroderWaterGenerator.AllFrames,
                    DestinationFinder          = HydraulicEroderWaterDestinationFinder.OnlyBest
                },
            });

            CreateTestObject(heightmap1, erodedArrays);
        }
Example #2
0
        public void Start_Mai()
        {
            var heightTexture1 = SavingFileManager.LoadPngTextureFromFile(@"C:\inz\cont\smallCut.png", 240,
                                                                          240, TextureFormat.RGBA32, true, true);
            var heightmap1 = HeightmapUtils.CreateHeightmapArrayFromTexture(heightTexture1);

            //DiamondSquareCreator creator = new DiamondSquareCreator(new RandomProvider(22));
            //var heightmap2 = creator.CreateDiamondSquareNoiseArray(new IntVector2(240, 240), 64);
            //MyArrayUtils.Multiply(heightmap2.HeightmapAsArray, 0.1f);
            HeightmapArray workingHeightmap = LoadHeightmapFromTextureFile(@"C:\inz\cont\temp3.png");

            MyArrayUtils.Normalize(workingHeightmap.HeightmapAsArray);
            MyArrayUtils.InvertNormalized(workingHeightmap.HeightmapAsArray);

            var generatedArrays = GenerateErodedArrays(workingHeightmap, new List <MeiHydraulicEroderConfiguration>()
            {
                new MeiHydraulicEroderConfiguration()
                {
                    StepCount           = 10,
                    A_PipeCrossSection  = 0.00005f,
                    ConstantWaterAdding = 1 / 16f,
                    GravityAcceleration = 9.81f,
                    DeltaT                   = 1 / 60f,
                    DepositionConstant       = 0.0001f * 12 * 10f,
                    DissolvingConstant       = 0.0001f * 12 * 10f,
                    EvaporationConstant      = 0.00011f * 0.5f * 10,
                    GridSize                 = new Vector2(1, 1),
                    L_PipeLength             = 1,
                    SedimentCapacityConstant = 25000
                },
            });

            CreateTestObject(workingHeightmap, generatedArrays);
        }
        public ColorPaletteFile LoadColorPaletteFile()
        {
            var texSize = _configuration.TextureSize;
            var tex     = SavingFileManager.LoadPngTextureFromFile(_configuration.FilePath, texSize.X,
                                                                   texSize.Y, TextureFormat.ARGB32, true, false);

            var oneLineCount   = Mathf.Min(_configuration.MaxOneLineColorCount, texSize.X);
            var outColorArrays = new List <List <Color> >();

            for (int y = 0; y < texSize.Y; y++)
            {
                var oneLineList = new List <Color>();
                for (int x = 0; x < oneLineCount; x++)
                {
                    var color = tex.GetPixel(x, (texSize.Y - 1) - y);
                    if (!color.Equals(_configuration.EmptyColor))
                    {
                        oneLineList.Add(color);
                    }
                }
                outColorArrays.Add(oneLineList);
            }
            GameObject.Destroy(tex);
            return(new ColorPaletteFile(outColorArrays));
        }
Example #4
0
        public Grass2SingledBillboardClan Load(string rootPath, IntVector2 billboardImageSize)
        {
            var pathGenerator = new Grass2BillboardClanFilesManagerPathGenerator(rootPath);
            var infoFile      =
                JsonUtility.FromJson <Grass2BillboardInfoJson>(File.ReadAllText(pathGenerator.CreateInfoFilePath()));

            var billboardsList = new List <DetailedGrass2SingleBillboard>();

            int i = 0;

            foreach (var bladesCount in infoFile.BladesCountList)
            {
                var tex = SavingFileManager.LoadPngTextureFromFile(pathGenerator.CreateBillboardFilePath(i),
                                                                   billboardImageSize.X, billboardImageSize.Y, TextureFormat.ARGB32, true, true);
                tex.filterMode = FilterMode.Point;
                tex.wrapMode   = TextureWrapMode.Clamp;

                billboardsList.Add(new DetailedGrass2SingleBillboard()
                {
                    BladesCount = bladesCount,
                    Texture     = tex
                });
                i++;
            }

            return(new Grass2SingledBillboardClan()
            {
                BillboardsList = billboardsList
            });
        }
        public void Start()
        {
            TaskUtils.SetGlobalMultithreading(false);
            //DiamondSquareCreator creator = new DiamondSquareCreator(new RandomProvider(22));
            //_currentHeightmap = creator.CreateDiamondSquareNoiseArray(_sizeOfTexture, 64);
            //MyArrayUtils.Multiply(_currentHeightmap.HeightmapAsArray, 0.1f);
            var heightTex = SavingFileManager.LoadPngTextureFromFile(@"C:\inz\cont\smallCut.png", 240, 240,
                                                                     TextureFormat.RGBA32, true, true);

            _currentHeightmap = HeightmapUtils.CreateHeightmapArrayFromTexture(heightTex);

            MyArrayUtils.Normalize(_currentHeightmap.HeightmapAsArray);
            MyArrayUtils.InvertNormalized(_currentHeightmap.HeightmapAsArray);

            CreateComparisionObject();
            //MyArrayUtils.Multiply(_currentHeightmap.HeightmapAsArray, 400);

            //float[,] newHeightArray = new float[256,256];
            //for (int x = 0; x < 256; x++)
            //{
            //    for (int y = 0; y < 256; y++)
            //    {
            //        var distance = (new Vector2(x,y) - new Vector2(128, 128)).magnitude;
            //        newHeightArray[x, y] = distance;
            //    }
            //}
            //MyArrayUtils.Normalize(newHeightArray);
            //_currentHeightmap = new HeightmapArray(newHeightArray);

            //Hydraulic_RenderComputeShader();

            Thermal_RenderComputeShader();
            //Hydraulic_RenderComputeShader();
        }
        public void Start()
        {
            var heightmapTextureSize = new IntVector2(3600, 3600);
            var rgbaMainTexture      = SavingFileManager.LoadPngTextureFromFile(_filePathsConfiguration.HeightmapFilePath,
                                                                                heightmapTextureSize.X, heightmapTextureSize.Y, TextureFormat.ARGB32, true, false);

            TerrainTextureFormatTransformator transformator =
                new TerrainTextureFormatTransformator(_gameInitializationFields.Retrive <CommonExecutorUTProxy>());
            var globalHeightTexture = transformator.EncodedHeightTextureToPlain(new TextureWithSize()
            {
                Size    = heightmapTextureSize,
                Texture = rgbaMainTexture
            });

            if (true)
            {
                _gameInitializationFields.SetField(new TerrainDetailAlignmentCalculator(240));

                TerrainDetailGenerator terrainDetailGenerator =
                    CreateTerrainDetailGenerator(
                        globalHeightTexture,
                        _gameInitializationFields.Retrive <UTTextureRendererProxy>(),
                        _gameInitializationFields.Retrive <CommonExecutorUTProxy>(),
                        _gameInitializationFields.Retrive <UnityThreadComputeShaderExecutorObject>(),
                        _gameInitializationFields.Retrive <ComputeShaderContainerGameObject>());

                var commonExecutorUtProxy = _gameInitializationFields.Retrive <CommonExecutorUTProxy>();

                TerrainDetailProvider terrainDetailProvider =
                    CreateTerrainDetailProvider(terrainDetailGenerator, commonExecutorUtProxy);


                var terrainDetailFileManager =
                    new TerrainDetailFileManager(_configuration.TerrainDetailCachePath, commonExecutorUtProxy);
                var terrainShapeDb = CreateTerrainShapeDb(terrainDetailProvider
                                                          , commonExecutorUtProxy
                                                          , _gameInitializationFields.Retrive <TerrainDetailAlignmentCalculator>()
                                                          , _configuration.TerrainShapeDbConfiguration.MergeTerrainDetail
                                                          , _configuration.TerrainShapeDbConfiguration.UseTextureSavingToDisk
                                                          , _configuration.TerrainShapeDbConfiguration.UseTextureLoadingFromDisk, terrainDetailFileManager);

                TerrainShapeDbProxy terrainShapeDbProxy = new TerrainShapeDbProxy(terrainShapeDb);
                var baseTerrainDetailProvider           = BaseTerrainDetailProvider.CreateFrom(terrainShapeDb);
                _gameInitializationFields.SetField(baseTerrainDetailProvider);
                terrainDetailGenerator.SetBaseTerrainDetailProvider(baseTerrainDetailProvider);

                _ultraUpdatableContainer.AddOtherThreadProxy(terrainShapeDbProxy);

                _gameInitializationFields.SetField(terrainShapeDbProxy);
            }
            else
            {
                ITerrainShapeDb terrainShapeDbProxy = new DebugSlopedTerrainShapeDb(
                    _gameInitializationFields.Retrive <UTTextureRendererProxy>()
                    );

                terrainShapeDbProxy = new RecordingTerrainShapeDb(terrainShapeDbProxy);
                _gameInitializationFields.SetField((RecordingTerrainShapeDb)terrainShapeDbProxy);
            }
        }
Example #7
0
        public void Start()
        {
            TaskUtils.SetGlobalMultithreading(false);
            var heightTex = SavingFileManager.LoadPngTextureFromFile(@"C:\inz\cont\smallCut.png", 240, 240,
                                                                     TextureFormat.RGBA32, true, true);

            _currentHeightmap = HeightmapUtils.CreateHeightmapArrayFromTexture(heightTex);

            MyArrayUtils.Normalize(_currentHeightmap.HeightmapAsArray);
            MyArrayUtils.InvertNormalized(_currentHeightmap.HeightmapAsArray);

            //for (int x = 0; x < 40; x++)
            //{
            //    for (int y = 0; y < 40; y++)
            //    {
            //        _currentHeightmap.HeightmapAsArray[90+x, 90+y] = 0;
            //    }
            //}

            CreateComparisionObject();
            MyArrayUtils.Multiply(_currentHeightmap.HeightmapAsArray, 400);


            Mei_RenderComputeShader();
        }
Example #8
0
        public async Task <TextureWithSize> RetriveHeightDetailElementAsync(string filename)
        {
            IntVector2 textureSize = new IntVector2(241, 241);
            var        path        = _mainDictionaryPath + filename + _extension;

            Preconditions.Assert(File.Exists(path), $"Cannot retrive heightDetailElement of path {path} as it does not exist");
            {
                var texture = await _commonExecutor.AddAction(() =>
                {
                    var tex = SavingFileManager.LoadPngTextureFromFile(path, textureSize.X, textureSize.Y,
                                                                       TextureFormat.ARGB32, true, true);
                    tex.wrapMode = TextureWrapMode.Clamp;
                    return(tex);
                });

                var transformator = new TerrainTextureFormatTransformator(_commonExecutor);
                var plainTexture  = await transformator.EncodedHeightTextureToPlainAsync(new TextureWithSize()
                {
                    Texture = texture,
                    Size    = textureSize
                });

                return(new TextureWithSize()
                {
                    Size = textureSize,
                    Texture = plainTexture
                });
            }
        }
Example #9
0
        public HeightmapArray LoadHeightmapFromTextureFile(string pathToTemplateFile)
        {
            var tex = SavingFileManager.LoadPngTextureFromFile(pathToTemplateFile, 240, 240,
                                                               TextureFormat.ARGB32, false,
                                                               false);

            return(HeightmapUtils.CreateHeightmapArrayFromTexture(tex));
        }
Example #10
0
        public void Start()
        {
            TaskUtils.SetGlobalMultithreading(false);

            var rgbaMainTexture = SavingFileManager.LoadPngTextureFromFile(@"C:\inz\cont\n49_e019_1arc_v3.png", 3600,
                                                                           3600,
                                                                           TextureFormat.ARGB32, true, false);

            MainTexture = _transformator.EncodedHeightTextureToPlainAsync(new TextureWithSize()
            {
                Size    = new IntVector2(3600, 3600),
                Texture = rgbaMainTexture
            }).Result;

            //var heightArray = HeightmapUtils.CreateHeightmapArrayFromTexture(MainTexture);
            //for (int x = 0; x < 5; x++)
            //{
            //    for (int y = 0; y < 5; y++)
            //    {
            //        heightArray.HeightmapAsArray[x, y] = 0.3f;
            //    }
            //}
            //MainTexture = HeightmapUtils.CreateTextureFromHeightmap(heightArray);


            InitializeFields();

            var unitySideLength = 10f;
            var realSideLength  = 240 * 24;
            var metersPerUnit   = realSideLength / unitySideLength;

            _gameObject = GameObject.CreatePrimitive(PrimitiveType.Quad);
            var material = new Material(Shader.Find("Custom/Terrain/Terrain_Debug_Plain"));

            _gameObject.GetComponent <MeshRenderer>().material = material;
            _gameObject.name = "Terrain";
            _gameObject.transform.localRotation = Quaternion.Euler(0, 0, 0);

            //_gameObject.transform.localScale = new Vector3(10, (6500 / metersPerUnit) , 10);
            //_gameObject.transform.localPosition = new Vector3(0 , 0, 0);

            //_gameObject.transform.localScale = new Vector3(10, (6500 / metersPerUnit) * 8, 10);
            //_gameObject.transform.localPosition = new Vector3(0, 0, 0);

            _gameObject.transform.localScale             = new Vector3(10, 1 / 64f * (6500 / metersPerUnit) * 8 * 8, 10);
            _gameObject.transform.localPosition          = new Vector3(0, -30, 0);
            _gameObject.GetComponent <MeshFilter>().mesh = PlaneGenerator.CreateFlatPlaneMesh(240, 240);

            RegenerateTextures();

            //Camera.main.transform.localPosition = new Vector3(10,2,0);
            //Camera.main.transform.eulerAngles = new Vector3(30,-45,0);
            Camera.main.transform.localPosition = new Vector3(-1, -25, 10);
            Camera.main.transform.eulerAngles   = new Vector3(30, 132, 0);
        }
Example #11
0
        public void StartY()
        {
            var heightTexture = SavingFileManager.LoadPngTextureFromFile(@"C:\inz\cont\smallCut.png", 240,
                                                                         240, TextureFormat.RGBA32, true, true);

            _currentHeightmap = HeightmapUtils.CreateHeightmapArrayFromTexture(heightTexture);
            var array = _currentHeightmap.HeightmapAsArray;

            MyArrayUtils.Multiply(array, 65000);
            var extremes = MyArrayUtils.CalculateExtremes(array);

            Debug.Log("Max: " + extremes.Max + " min: " + extremes.Min);
        }
        public void Start()
        {
            TaskUtils.SetGlobalMultithreading(false);

            var rgbaMainTexture = SavingFileManager.LoadPngTextureFromFile(@"C:\inz\cont\n49_e019_1arc_v3.png", 3600,
                                                                           3600,
                                                                           TextureFormat.ARGB32, true, false);


            TerrainTextureFormatTransformator transformator =
                new TerrainTextureFormatTransformator(new CommonExecutorUTProxy());
            var mainTexture = transformator.EncodedHeightTextureToPlainAsync(new TextureWithSize()
            {
                Size    = new IntVector2(3600, 3600),
                Texture = rgbaMainTexture
            }).Result;


            var gameObject = GameObject.CreatePrimitive(PrimitiveType.Quad);
            var material   = new Material(Shader.Find("Custom/Terrain/Ring1"));

            TerrainAndNormalTexture pair = CreateTerrainAndNormalTexture(mainTexture);

            material.SetTexture("_HeightmapTex", pair.HeightTexture);
            material.SetTexture("_NormalmapTex", pair.NormalTexture);

            gameObject.GetComponent <MeshRenderer>().material = material;
            gameObject.name = "Terrain";
            gameObject.transform.localRotation = Quaternion.Euler(0, 0, 0);

            var unitySideLength = 10f;
            var realSideLength  = 240 * 24;
            var metersPerUnit   = realSideLength / unitySideLength;

            if (_terrainResolution == TerrainCardinalResolution.MIN_RESOLUTION)
            {
                gameObject.transform.localScale    = new Vector3(10, (6500 / metersPerUnit), 10);
                gameObject.transform.localPosition = new Vector3(0, 0, 0);
            }
            else if (_terrainResolution == TerrainCardinalResolution.MID_RESOLUTION)
            {
                gameObject.transform.localScale    = new Vector3(10, (6500 / metersPerUnit) * 8, 10);
                gameObject.transform.localPosition = new Vector3(0, 0, 0);
            }
            else
            {
                gameObject.transform.localScale    = new Vector3(10, (6500 / metersPerUnit) * 8 * 8, 10);
                gameObject.transform.localPosition = new Vector3(0, -30, 0);
            }
            gameObject.GetComponent <MeshFilter>().mesh = PlaneGenerator.CreateFlatPlaneMesh(240, 240);
        }
Example #13
0
        private void GenerateTexture()
        {
            var heightTexture1 = SavingFileManager.LoadPngTextureFromFile(@"C:\inz\cont\temp3.png", 240,
                                                                          240, TextureFormat.RGBA32, true, true);
            Material material = new Material(Shader.Find("Custom/TerGen/ErosionThermal"));

            material.SetTexture("_MainInputTex", heightTexture1);

            RenderTextureInfo renderTextureInfo = new RenderTextureInfo(240, 240, RenderTextureFormat.ARGB32);

            ConventionalTextureInfo outTextureInfo = new ConventionalTextureInfo(240, 240, TextureFormat.ARGB32, false);

            OutputTexture = UltraTextureRenderer.RenderTextureAtOnce(material, renderTextureInfo, outTextureInfo);
            OutputShowingObject.GetComponent <MeshRenderer>().material.SetTexture("_MainTex", OutputTexture);
        }
Example #14
0
        public async Task <TextureWithSize> RetriveNormalDetailElementAsync(string filename)
        {
            IntVector2 textureSize = new IntVector2(241, 241);
            var        path        = _mainDictionaryPath + filename + _extension;

            Preconditions.Assert(File.Exists(path), $"Cannot retrive normalDetailElement of path {path} as it does not exist");
            var texture = await _commonExecutor.AddAction(() =>
                                                          SavingFileManager.LoadPngTextureFromFile(path, textureSize.X, textureSize.Y,
                                                                                                   TextureFormat.ARGB32, true, true));

            return(new TextureWithSize()
            {
                Size = textureSize,
                Texture = texture
            });
        }
Example #15
0
        public TAMSoleImagesPack Load(string directoryPath, List <TAMTone> tones, List <TAMMipmapLevel> levels)
        {
            var columns = Enumerable.Range(0, tones.Count).ToDictionary(
                toneIndex => tones[toneIndex],
                toneIndex =>

                Enumerable.Range(0, levels.Count).ToDictionary(
                    levelIndex => levels[levelIndex],
                    levelIndex =>
            {
                var path = directoryPath + CreateFileNameToSoleImage(toneIndex, levelIndex);
                return(SavingFileManager.LoadPngTextureFromFile(path));
            })
                );

            return(new TAMSoleImagesPack(columns));
        }
Example #16
0
        public void Start_Thermal()
        {
            var heightTexture1 = SavingFileManager.LoadPngTextureFromFile(@"C:\inz\cont\smallCut.png", 240,
                                                                          240, TextureFormat.RGBA32, true, true);
            var heightmap1 = HeightmapUtils.CreateHeightmapArrayFromTexture(heightTexture1);

            DiamondSquareCreator creator = new DiamondSquareCreator(new RandomProvider(22));
            var heightmap2 = creator.CreateDiamondSquareNoiseArray(new IntVector2(240, 240), 64);

            MyArrayUtils.Multiply(heightmap2.HeightmapAsArray, 0.1f);

            var tParam       = EroderDebugObject.CalculateFromHillFactor(1, new ArrayExtremes(0, 5000), 24);
            var erodedArrays = GenerateErodedArrays(heightmap1, new List <ThermalErosionConfiguration>()
            {
                new ThermalErosionConfiguration()
                {
                    CParam          = 0.5f,
                    StepCount       = 10,
                    TParam          = tParam * 0.6f,
                    NeighbourFinder = NeighbourFinders.Big9Finder,
                    GroundMover     = ThermalErosionGroundMovers.OnlyBestMover
                },
                new ThermalErosionConfiguration()
                {
                    CParam          = 0.5f,
                    StepCount       = 10,
                    TParam          = tParam * 0.6f,
                    NeighbourFinder = NeighbourFinders.Big9Finder,
                    GroundMover     = ThermalErosionGroundMovers.AllNeighboursMover
                },
                new ThermalErosionConfiguration()
                {
                    CParam            = 0.5f,
                    StepCount         = 10,
                    TParam            = tParam * 0.6f,
                    NeighbourFinder   = NeighbourFinders.Big9Finder,
                    GroundMover       = ThermalErosionGroundMovers.OnlyBestMoverTweaked,
                    NeighboursChooser = ThermalEroderNeighboursChoosers.LesserEqualThanTChooser
                },
            });

            CreateTestObject(heightmap1, erodedArrays);
        }
Example #17
0
        public void Start()
        {
            var image  = SavingFileManager.LoadPngTextureFromFile(SourceImagePath, false);
            var width  = image.width;
            var height = image.height;

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    var p      = image.GetPixel(x, y);
                    var tParam = x / ((float)(width - 1));
                    p.b = tParam;
                    image.SetPixel(x, y, p);
                }
            }

            SavingFileManager.SaveTextureToPngFile(DestinationImagePath, image);
        }
Example #18
0
        public void StartX()
        {
            TaskUtils.SetGlobalMultithreading(false);
            MainTexture = SavingFileManager.LoadPngTextureFromFile(@"C:\inz\cont\n49_e019_1arc_v3.png", 3600, 3600,
                                                                   TextureFormat.ARGB32, true, false);

            var plain = _transformator.EncodedHeightTextureToPlainAsync(new TextureWithSize()
            {
                Size    = new IntVector2(3600, 3600),
                Texture = MainTexture
            });

            var decoded = _transformator.PlainToEncodedHeightTextureAsync(new TextureWithSize()
            {
                Size    = new IntVector2(3600, 3600),
                Texture = plain.Result
            });

            SavingFileManager.SaveTextureToPngFile(@"C:\inz\cont\n49_e019_1arc_v4.rfloat.png", decoded.Result);
        }
        private static RenderTexture CreateGlobalHeightTexture(CommonExecutorUTProxy commonExecutorUtProxy)
        {
            var rgbaMainTexture = SavingFileManager.LoadPngTextureFromFile(@"C:\mgr\PwMgrProject\precomputedResources\allTerrainF1.png", 3600,
                                                                           3600,
                                                                           TextureFormat.ARGB32, true, false);
            TerrainTextureFormatTransformator transformator =
                new TerrainTextureFormatTransformator(commonExecutorUtProxy);
            var mirroredImage = transformator.MirrorHeightTexture(new TextureWithSize()
            {
                Size    = new IntVector2(3600, 3600),
                Texture = rgbaMainTexture
            });
            var globalHeightTexture = transformator.EncodedHeightTextureToPlain(new TextureWithSize()
            {
                Size    = new IntVector2(3600, 3600),
                Texture = mirroredImage
            });

            return(globalHeightTexture);
        }
Example #20
0
        // Use this for initialization
        void Start()
        {
            _updatableContainer = new UpdatableContainer();
            TaskUtils.SetGlobalMultithreading(false);

            _ring1Tree = new Ring1Tree();

            //////////////////

            var rgbaMainTexture = SavingFileManager.LoadPngTextureFromFile(@"C:\inz\cont\n49_e019_1arc_v3.png", 3600,
                                                                           3600,
                                                                           TextureFormat.ARGB32, true, false);


            CommonExecutorUTProxy commonExecutorUtProxy = new CommonExecutorUTProxy(); //todo

            _updatableContainer.AddUpdatableElement(commonExecutorUtProxy);
            TerrainTextureFormatTransformator transformator =
                new TerrainTextureFormatTransformator(commonExecutorUtProxy);
            var globalHeightTexture = transformator.EncodedHeightTextureToPlain(new TextureWithSize()
            {
                Size    = new IntVector2(3600, 3600),
                Texture = rgbaMainTexture
            });

            /// /// VISIBILITY TEXTURE
            var visibilityTextureSideLength = 16;
            var visibilityTexture           = new Texture2D(visibilityTextureSideLength, visibilityTextureSideLength,
                                                            TextureFormat.RFloat, false);

            visibilityTexture.filterMode = FilterMode.Point;

            var visibilityTextureProcessorProxy =
                new Ring1VisibilityTextureProcessorUTProxy(new Ring1VisibilityTextureProcessor(visibilityTexture));

            _updatableContainer.AddUpdatableElement(visibilityTextureProcessorProxy);


            var visibilityTextureChangeGrabber = new Ring1VisibilityTextureChangeGrabber();

            var terrainParentGameObject = new GameObject("TerrainParent");

            var unityCoordsCalculator = new UnityCoordsCalculator(new Vector2(24 * 240 * 2, 24 * 240 * 2));
            var orderGrabber          = new Ring1PaintingOrderGrabber();

            var painterProxy = new RingTerrainPainterUTProxy(new RingTerrainPainter());

            _updatableContainer.AddUpdatableElement(painterProxy);

            painterProxy.Update();

            var mainRespondingProxy = new Ring1NodeEventMainRespondingProxy(new Ring1NodeEventMainResponder());

            _otherThreadActionPairs.Add(new OtherThreadProxyAndActionPair()
            {
                Proxy           = mainRespondingProxy,
                EveryPostAction =
                    () =>
                {
                    var delta = visibilityTextureChangeGrabber.RetriveVisibilityChanges();

                    if (delta.AnyChange)
                    {
                        var visibilityTextureChagnes = visibilityTextureChangeGrabber.RetriveVisibilityChanges();
                        visibilityTextureProcessorProxy.AddOrder(visibilityTextureChagnes);
                    }

                    if (orderGrabber.IsAnyOrder)
                    {
                        painterProxy.AddOrder(orderGrabber.RetriveOrderAndClear());
                    }
                }
            });


            UTTextureRendererProxy textureRendererProxy = new UTTextureRendererProxy(new TextureRendererService(
                                                                                         new MultistepTextureRenderer(ContainerGameObject), new TextureRendererServiceConfiguration()
            {
                StepSize = new Vector2(500, 500)
            }));

            _updatableContainer.AddUpdatableElement(textureRendererProxy);

            UnityThreadComputeShaderExecutorObject computeShaderExecutorObject =
                new UnityThreadComputeShaderExecutorObject();

            _updatableContainer.AddUpdatableElement(computeShaderExecutorObject);
            _updatableContainer.AddUpdatableElement(commonExecutorUtProxy);

            TerrainDetailGenerator terrainDetailGenerator =
                CreateTerrainDetailGenerator(
                    globalHeightTexture, textureRendererProxy, commonExecutorUtProxy, computeShaderExecutorObject,
                    ContainerGameObject);
            TerrainDetailProvider terrainDetailProvider =
                CreateTerrainDetailProvider(terrainDetailGenerator);

            var terrainShapeDb = FETerrainShapeDbInitialization.CreateTerrainShapeDb(terrainDetailProvider, commonExecutorUtProxy
                                                                                     , new TerrainDetailAlignmentCalculator(240), false, false, false, null);
            TerrainShapeDbProxy terrainShapeDbProxy = new TerrainShapeDbProxy(terrainShapeDb);

            terrainDetailGenerator.SetBaseTerrainDetailProvider(BaseTerrainDetailProvider.CreateFrom(terrainShapeDb));

            _otherThreadActionPairs.Add(new OtherThreadProxyAndActionPair()
            {
                Proxy = terrainShapeDbProxy
            });

            var meshGeneratorProxy = new MeshGeneratorUTProxy(new MeshGeneratorService());

            _updatableContainer.AddUpdatableElement(meshGeneratorProxy);

            _stainTerrainResourceCreatorUtProxy =
                new StainTerrainResourceCreatorUTProxy(new StainTerrainResourceCreator());
            _updatableContainer.AddUpdatableElement(_stainTerrainResourceCreatorUtProxy);

            var stainTerrainServiceProxy = new StainTerrainServiceProxy(
                new StainTerrainService(
                    new ComputationStainTerrainResourceGenerator(
                        new StainTerrainResourceComposer(
                            _stainTerrainResourceCreatorUtProxy
                            ),
                        new StainTerrainArrayMelder(),
                        new DummyStainTerrainArrayFromBiomesGenerator(
                            new DebugBiomeContainerGenerator().GenerateBiomesContainer(
                                new BiomesContainerConfiguration()),
                            new StainTerrainArrayFromBiomesGeneratorConfiguration()
                            )),
                    new MyRectangle(0, 0, 24 * 240 * 2, 24 * 240 * 2)));

            _otherThreadActionPairs.Add(new OtherThreadProxyAndActionPair()
            {
                Proxy = stainTerrainServiceProxy
            });

            var gRing1NodeTerrainCreator = new GRing1NodeTerrainCreator(
                orderGrabber,
                terrainParentGameObject,
                meshGeneratorProxy,
                terrainShapeDbProxy,
                stainTerrainServiceProxy,
                unityCoordsCalculator,
                null,
                null,
                new GRingGroundShapeProviderConfiguration(),
                new GRingTerrainMeshProviderConfiguration());

            var gRing2NodeTerrainCreator = new GRing2NodeTerrainCreator(
                orderGrabber,
                terrainParentGameObject,
                meshGeneratorProxy,
                terrainShapeDbProxy,
                unityCoordsCalculator,
                new GRing2PatchesCreatorProxy(CreateRing2PatchesCreator()),
                null,
                null,
                new GRingGroundShapeProviderConfiguration(),
                new GRingTerrainMeshProviderConfiguration());

            UTRing2PlateStamperProxy stamperProxy = new UTRing2PlateStamperProxy(
                new Ring2PlateStamper(new Ring2PlateStamperConfiguration()
            {
                PlateStampPixelsPerUnit = new Dictionary <int, float>()
            }, ContainerGameObject));

            _updatableContainer.AddUpdatableElement(stamperProxy);

            Ring2PatchStamplingOverseerFinalizer patchStamper =
                new Ring2PatchStamplingOverseerFinalizer(stamperProxy, textureRendererProxy, commonExecutorUtProxy);

            var gStampedRing2NodeTerrainCreator = new GStampedRing2NodeTerrainCreator(
                orderGrabber,
                terrainParentGameObject,
                meshGeneratorProxy,
                terrainShapeDbProxy,
                unityCoordsCalculator,
                new GRing2PatchesCreatorProxy(CreateRing2PatchesCreator()),
                patchStamper,
                null,
                null,
                new GRingGroundShapeProviderConfiguration(),
                new GRingTerrainMeshProviderConfiguration());

            var subCreator = new SupremeGRingNodeTerrainCreator(new List <NewListenersCreatorWithLimitation>()
            {
                //new NewListenersCreatorWithMaximumLod()
                //{
                //    Creator = gRing1NodeTerrainCreator,
                //    MaximumLod = new FlatLod(6)
                //},
                new NewListenersCreatorWithLimitation()
                {
                    Creator    = new GVoidNodeTerrainCreator(),
                    MaximumLod = new FlatLod(6)
                },
                //new NewListenersCreatorWithMaximumLod()
                //{
                //    Creator = gRing2NodeTerrainCreator,
                //    MaximumLod = new FlatLod(8)
                //}
                new NewListenersCreatorWithLimitation()
                {
                    Creator    = gStampedRing2NodeTerrainCreator,
                    MaximumLod = new FlatLod(9)
                }
            });

            var eventCollector = new Ring1NodeEventCollector(
                new DynamicFlatLodGRingNodeTerrainCreator(subCreator, new FlatLodCalculator(unityCoordsCalculator)));

            _ring1TreeProxy = new Ring1TreeProxy(_ring1Tree);
            _otherThreadActionPairs.Add(new OtherThreadProxyAndActionPair()
            {
                Proxy           = _ring1TreeProxy,
                EveryPostAction =
                    () =>
                {
                    if (eventCollector.Any)
                    {
                        mainRespondingProxy.AddOrder(eventCollector.RetriveOrderAndClear());
                    }
                }
            });

            var baseQuadSideLength = 90f;

            StartThreading(_otherThreadActionPairs);
            _ring1TreeProxy.CreateHeightmap(new Ring1Tree.RootNodeCreationParameters()
            {
                UnityCoordsCalculator = unityCoordsCalculator,
                NodeListener          = eventCollector,
                PrecisionDistances    =
                    new Dictionary <float, int>
                {
                    //{4f * 50f/3f, 9},
                    //{4f * 50f/2f, 8},
                    { CalculatePrecisionDistance(baseQuadSideLength, 2, 1), 7 },
                    { 6.5f * 50f, 6 },
                    { 20 * 50f, 5 },
                    { 40 * 50f, 4 },
                    { 50 * 50f, 3 },
                    { 100 * 50f, 2 },
                    { 200 * 50f, 1 }
                },
                InitialCameraPosition = Vector3.zero,
            });
        }
        public void Start()
        {
            _unityThreadComputeShaderExecutorObject = new UnityThreadComputeShaderExecutorObject();
            var globalHeightTexture = SavingFileManager.LoadPngTextureFromFile(@"C:\inz\cont\n49_e019_1arc_v3.png",
                                                                               3600, 3600,
                                                                               TextureFormat.ARGB32, true, false);
            var sizedGlobalHeightTexture = new TextureWithSize()
            {
                Size    = new IntVector2(3600, 3600),
                Texture = globalHeightTexture
            };

            TaskUtils.SetGlobalMultithreading(true);

            _executionThreadProxy = new GenericAsyncExecutionThreadProxy("TerrainProviding");
            _executionThreadProxy.StartThreading(() => { });
            _executionThreadProxy.PostAction(async() =>
            {
                InitializeFields();
                //var tex0 = await CreateGenerateAndGenerateTexture(new List<RankedTerrainFeatureApplier>()
                //{
                //    new RankedTerrainFeatureApplier()
                //    {
                //        Rank = 1,
                //        Applier = new RandomNoiseTerrainFeatureApplier(_utTextureRendererProxy, _commonExecutor,
                //            new Dictionary<TerrainCardinalResolution, RandomNoiseTerrainFeatureApplierConfiguration>
                //        {
                //            { TerrainCardinalResolution.LOW_RESOLUTION, new RandomNoiseTerrainFeatureApplierConfiguration() { DetailResolutionMultiplier = 1} },
                //            { TerrainCardinalResolution.MID_RESOLUTION, new RandomNoiseTerrainFeatureApplierConfiguration() {DetailResolutionMultiplier =  8}},
                //        }),
                //        AvalibleResolutions = new List<TerrainCardinalResolution>()
                //        {
                //            TerrainCardinalResolution.LOW_RESOLUTION,
                //            TerrainCardinalResolution.MID_RESOLUTION,
                //            TerrainCardinalResolution.MAX_RESOLUTION
                //        }
                //    },
                //    new RankedTerrainFeatureApplier()
                //    {
                //        Rank = 2,
                //        Applier = new DiamondSquareTerrainFeatureApplier(
                //            new DiamondSquareCreator(_randomProvider), _commonExecutor,
                //            _utTextureRendererProxy),
                //        AvalibleResolutions = new List<TerrainCardinalResolution>()
                //        {
                //            TerrainCardinalResolution.LOW_RESOLUTION,
                //            TerrainCardinalResolution.MID_RESOLUTION,
                //            TerrainCardinalResolution.MAX_RESOLUTION
                //        }
                //    },
                //    new RankedTerrainFeatureApplier()
                //    {
                //        Rank = 3,
                //        Applier = new ThermalErosionTerrainFeatureApplier(ContainerGameObject,
                //            _unityThreadComputeShaderExecutorObject, _commonExecutor),
                //        AvalibleResolutions = new List<TerrainCardinalResolution>()
                //        {
                //            TerrainCardinalResolution.LOW_RESOLUTION,
                //            TerrainCardinalResolution.MID_RESOLUTION,
                //            TerrainCardinalResolution.MAX_RESOLUTION
                //        }
                //    },
                //    new RankedTerrainFeatureApplier()
                //    {
                //        Rank = 4,
                //        Applier = new HydraulicErosionTerrainFeatureApplier(ContainerGameObject,_unityThreadComputeShaderExecutorObject),
                //        AvalibleResolutions = new List<TerrainCardinalResolution>()
                //        {
                //            TerrainCardinalResolution.LOW_RESOLUTION,
                //            TerrainCardinalResolution.MID_RESOLUTION,
                //            TerrainCardinalResolution.MAX_RESOLUTION
                //        }
                //    },
                //    //new RankedTerrainFeatureApplier()
                //    //{
                //    //    Rank = 6,
                //    //    Applier = new TweakedThermalErosionTerrainFeatureApplier(ContainerGameObject, _unityThreadComputeShaderExecutorObject),
                //    //    AvalibleResolutions = new List<TerrainCardinalResolution>()
                //    //    {
                //    //        TerrainCardinalResolution.LOW_RESOLUTION,
                //    //        TerrainCardinalResolution.MID_RESOLUTION,
                //    //        TerrainCardinalResolution.MAX_RESOLUTION
                //    //    }
                //    //}

                //}, sizedGlobalHeightTexture);

                //var tex1 = await CreateGenerateAndGenerateTexture(new List<RankedTerrainFeatureApplier>()
                //{
                //    new RankedTerrainFeatureApplier()
                //    {
                //        Rank = 1,
                //        Applier = new RandomNoiseTerrainFeatureApplier(_utTextureRendererProxy, _commonExecutor,
                //            new Dictionary<TerrainCardinalResolution, RandomNoiseTerrainFeatureApplierConfiguration>
                //        {
                //            { TerrainCardinalResolution.LOW_RESOLUTION, new RandomNoiseTerrainFeatureApplierConfiguration() { DetailResolutionMultiplier = 1} },
                //            { TerrainCardinalResolution.MID_RESOLUTION, new RandomNoiseTerrainFeatureApplierConfiguration() {DetailResolutionMultiplier =  8}},
                //        }),
                //        AvalibleResolutions = new List<TerrainCardinalResolution>()
                //        {
                //            TerrainCardinalResolution.LOW_RESOLUTION,
                //            TerrainCardinalResolution.MID_RESOLUTION,
                //            TerrainCardinalResolution.MAX_RESOLUTION
                //        }
                //    },
                //    new RankedTerrainFeatureApplier()
                //    {
                //        Rank = 2,
                //        Applier = new DiamondSquareTerrainFeatureApplier(
                //            new DiamondSquareCreator(_randomProvider), _commonExecutor,
                //            _utTextureRendererProxy),
                //        AvalibleResolutions = new List<TerrainCardinalResolution>()
                //        {
                //            TerrainCardinalResolution.LOW_RESOLUTION,
                //            TerrainCardinalResolution.MID_RESOLUTION,
                //            TerrainCardinalResolution.MAX_RESOLUTION
                //        }
                //    },
                //    new RankedTerrainFeatureApplier()
                //    {
                //        Rank = 3,
                //        Applier = new ThermalErosionTerrainFeatureApplier(ContainerGameObject,
                //            _unityThreadComputeShaderExecutorObject, _commonExecutor),
                //        AvalibleResolutions = new List<TerrainCardinalResolution>()
                //        {
                //            TerrainCardinalResolution.LOW_RESOLUTION,
                //            TerrainCardinalResolution.MID_RESOLUTION,
                //            TerrainCardinalResolution.MAX_RESOLUTION
                //        }
                //    },
                //    new RankedTerrainFeatureApplier()
                //    {
                //        Rank = 6,
                //        Applier = new HydraulicErosionTerrainFeatureApplier(ContainerGameObject,_unityThreadComputeShaderExecutorObject),
                //        AvalibleResolutions = new List<TerrainCardinalResolution>()
                //        {
                //            TerrainCardinalResolution.LOW_RESOLUTION,
                //            TerrainCardinalResolution.MID_RESOLUTION,
                //            TerrainCardinalResolution.MAX_RESOLUTION
                //        }
                //    },
                //    //new RankedTerrainFeatureApplier()
                //    //{
                //    //    Rank = 5,
                //    //    Applier = new TweakedThermalErosionTerrainFeatureApplier(ContainerGameObject, _unityThreadComputeShaderExecutorObject),
                //    //    AvalibleResolutions = new List<TerrainCardinalResolution>()
                //    //    {
                //    //        TerrainCardinalResolution.MID_RESOLUTION,
                //    //        TerrainCardinalResolution.MAX_RESOLUTION
                //    //    }
                //    //}

                //}, sizedGlobalHeightTexture);


                //_resultBag.Add(new MyTexturePair()
                //{
                //    Tex0 = tex0,
                //    Tex1 = tex1
                //});
            });
        }
        public void Start()
        {
            TaskUtils.SetGlobalMultithreading(true);
            _computeShaderExecutorObject = new UnityThreadComputeShaderExecutorObject();
            _commonExecutorUtProxy       = new CommonExecutorUTProxy();
            _utTextureRendererProxy      = new UTTextureRendererProxy(new TextureRendererService(
                                                                          new MultistepTextureRenderer(ContainerGameObject), new TextureRendererServiceConfiguration()
            {
                StepSize = new Vector2(500, 500)
            }));

            var rgbaMainTexture = SavingFileManager.LoadPngTextureFromFile(@"C:\inz\cont\n49_e019_1arc_v3.png", 3600,
                                                                           3600,
                                                                           TextureFormat.ARGB32, true, false);


            TerrainTextureFormatTransformator transformator =
                new TerrainTextureFormatTransformator(_commonExecutorUtProxy);

            transformator.EncodedHeightTextureToPlainAsync(new TextureWithSize()
            {
                Size    = new IntVector2(3600, 3600),
                Texture = rgbaMainTexture
            }).ContinueWith(x =>
            {
                var mainTexture = x.Result;
                TerrainDetailGenerator generator = CreateTerrainDetailGenerator(new TextureWithSize()
                {
                    Size    = new IntVector2(3600, 3600),
                    Texture = mainTexture
                });
                TerrainDetailProvider terrainDetailProvider = CreateTerrainDetailProvider(generator);
                var db = FETerrainShapeDbInitialization.CreateTerrainShapeDb(terrainDetailProvider, _commonExecutorUtProxy,
                                                                             new TerrainDetailAlignmentCalculator(240), false, false, false, null);


                MyRectangle queryArea = null;
                if (_terrainResolution == TerrainCardinalResolution.MIN_RESOLUTION)
                {
                    queryArea = new MyRectangle(0, 0, 24 * 240, 24 * 240);
                }
                else if (_terrainResolution == TerrainCardinalResolution.MID_RESOLUTION)
                {
                    queryArea = new MyRectangle(3 * 240, 3 * 240, 3 * 240, 3 * 240);
                }
                else
                {
                    queryArea =
                        new MyRectangle(5 * 0.375f * 240, 5 * 0.375f * 240, 0.375f * 240, 0.375f * 240);
                }


                var outputOfGeneration = db.QueryAsync(new TerrainDescriptionQuery()
                {
                    QueryArea = queryArea,
                    RequestedElementDetails = new List <TerrainDescriptionQueryElementDetail>()
                    {
                        new TerrainDescriptionQueryElementDetail()
                        {
                            Resolution = _terrainResolution.LowerResolution,
                            Type       = TerrainDescriptionElementTypeEnum.HEIGHT_ARRAY
                        },
                        new TerrainDescriptionQueryElementDetail()
                        {
                            Resolution = _terrainResolution,
                            Type       = TerrainDescriptionElementTypeEnum.NORMAL_ARRAY
                        },
                    }
                });

                outputOfGeneration.ContinueWith(c =>
                {
                    GeneratedTerrainElements elem = new GeneratedTerrainElements();
                    elem.HeightElement            = c.Result.GetElementOfType(TerrainDescriptionElementTypeEnum.HEIGHT_ARRAY);
                    elem.NormalElement            = c.Result.GetElementOfType(TerrainDescriptionElementTypeEnum.NORMAL_ARRAY);
                    _generatedElements.Add(elem);
                }).ContinueWith(q =>
                {
                    Debug.Log("Error: Executing task");
                    Debug.Log("Error descr is " + q.Exception);
                }, TaskContinuationOptions.OnlyOnFaulted
                                );
            });
        }
Example #23
0
        public void Start_Mai_Debug()
        {
            var heightTexture1 = SavingFileManager.LoadPngTextureFromFile(@"C:\inz\cont\smallCut.png", 240,
                                                                          240, TextureFormat.RGBA32, true, true);
            var heightmap1 = HeightmapUtils.CreateHeightmapArrayFromTexture(heightTexture1);

            //DiamondSquareCreator creator = new DiamondSquareCreator(new RandomProvider(22));
            //var heightmap2 = creator.CreateDiamondSquareNoiseArray(new IntVector2(240, 240), 64);
            //MyArrayUtils.Multiply(heightmap2.HeightmapAsArray, 0.1f);
            //HeightmapArray workingHeightmap = LoadHeightmapFromTextureFile(@"C:\inz\cont\temp3.png");
            HeightmapArray workingHeightmap = heightmap1;

            MyArrayUtils.Normalize(workingHeightmap.HeightmapAsArray);
            MyArrayUtils.InvertNormalized(workingHeightmap.HeightmapAsArray);
            HeightmapArray originalMap = new HeightmapArray(MyArrayUtils.DeepClone(workingHeightmap.HeightmapAsArray));

            MyArrayUtils.Multiply(workingHeightmap.HeightmapAsArray, 400);

            var configuration = new MeiHydraulicEroderConfiguration()
            {
                StepCount           = 50,
                A_PipeCrossSection  = 0.05f,
                ConstantWaterAdding = 1 / 64f,
                GravityAcceleration = 9.81f,
                DeltaT                   = 1f,
                DepositionConstant       = 0.0001f * 12 * 2f,
                DissolvingConstant       = 0.0001f * 12 * 2f,
                EvaporationConstant      = 0.05f * 10,
                GridSize                 = new Vector2(1, 1),
                L_PipeLength             = 1,
                SedimentCapacityConstant = 250
            };

            var eroder    = new MeiHydraulicEroder();
            var debOutput = eroder.ErodeWithDebug(SimpleHeightArray.FromHeightmap(workingHeightmap), configuration);

            MyArrayUtils.Multiply(workingHeightmap.HeightmapAsArray, 1f / 400);
            debOutput.NormalizeInGroups();


            _go = GameObject.CreatePrimitive(PrimitiveType.Quad);
            var material = new Material(Shader.Find("Custom/Terrain/Terrain_Mei_Debug_Comparision_StepByStep"));

            _go.GetComponent <MeshRenderer>().material = material;
            _go.name = "Terrain";
            _go.transform.localRotation          = Quaternion.Euler(0, 0, 0);
            _go.transform.localScale             = new Vector3(10, 1, 10);
            _go.transform.localPosition          = new Vector3(0, 0, 0);
            _go.GetComponent <MeshFilter>().mesh = PlaneGenerator.CreateFlatPlaneMesh(240, 240);

            MyHeightTextureArray heightTextureArray =
                new MyHeightTextureArray(240, 240, 2, TextureFormat.ARGB32, false, true);

            heightTextureArray.AddElementArray(originalMap, 0);
            heightTextureArray.AddElementArray(workingHeightmap, 1);
            _go.GetComponent <MeshRenderer>().material
            .SetTexture("_HeightmapTexArray", heightTextureArray.ApplyAndRetrive());


            var arrayListsCount  = debOutput.OneArrayListCount;
            var arrayListsLength = debOutput.OneArrayListLength;
            MyHeightTextureArray detailHeightTexturesArray =
                new MyHeightTextureArray(240, 240, arrayListsCount * arrayListsLength, TextureFormat.ARGB32, false,
                                         true);

            foreach (var snapshot in debOutput.ArraysDict.Values.SelectMany(c => c))
            {
                detailHeightTexturesArray.AddElementArray(snapshot);
            }
            _go.GetComponent <MeshRenderer>().material
            .SetTexture("_DetailTexArray", detailHeightTexturesArray.ApplyAndRetrive());
            _go.GetComponent <MeshRenderer>().material.SetFloat("_DetailTexLength", arrayListsLength);
        }
Example #24
0
        public void Start_Hydraulic_Debuggable()
        {
            var heightTexture1 = SavingFileManager.LoadPngTextureFromFile(@"C:\inz\cont\smallCut.png", 240,
                                                                          240, TextureFormat.RGBA32, true, true);
            var heightmap1 = HeightmapUtils.CreateHeightmapArrayFromTexture(heightTexture1);

            //DiamondSquareCreator creator = new DiamondSquareCreator(new RandomProvider(22));
            //var heightmap2 = creator.CreateDiamondSquareNoiseArray(new IntVector2(240, 240), 64);
            //MyArrayUtils.Multiply(heightmap2.HeightmapAsArray, 0.1f);

            var tParam = EroderDebugObject.CalculateFromHillFactor(1, new ArrayExtremes(0, 5000), 24);

            var extents = MyArrayUtils.CalculateExtremes(heightmap1.HeightmapAsArray);

            MyArrayUtils.Normalize(heightmap1.HeightmapAsArray);

            var configuration =
                new HydraulicEroderConfiguration()
            {
                StepCount                  = 20,
                NeighbourFinder            = NeighbourFinders.Big9Finder,
                kr_ConstantWaterAddition   = 0.001f,
                ks_GroundToSedimentFactor  = 1f,
                ke_WaterEvaporationFactor  = 0.05f,
                kc_MaxSedimentationFactor  = 0.8f,
                FinalSedimentationToGround = false,
                WaterGenerator             = HydraulicEroderWaterGenerator.FirstFrame,
                DestinationFinder          = HydraulicEroderWaterDestinationFinder.OnlyBest
            };

            var copyArray          = MyArrayUtils.DeepClone(heightmap1.HeightmapAsArray);
            var currentHeightArray = new SimpleHeightArray(copyArray);
            var eroder             = new DebuggableHydraulicEroder();
            var debuggingOutput    = eroder.Erode(currentHeightArray, configuration, 1);

            var sedimentExtentsArr = debuggingOutput.SedimentSnapshots
                                     .Select(c => MyArrayUtils.CalculateExtremes(c.Array)).ToList();
            var sedimentExtents = new ArrayExtremes(sedimentExtentsArr.Min(c => c.Min),
                                                    sedimentExtentsArr.Max(c => c.Max));

            debuggingOutput.SedimentSnapshots.ForEach(c => MyArrayUtils.Normalize(c.Array, sedimentExtents));

            var waterExtentsArr = debuggingOutput.WaterSnapshots.Select(c => MyArrayUtils.CalculateExtremes(c.Array))
                                  .ToList();
            var waterExtents = new ArrayExtremes(waterExtentsArr.Min(c => c.Min), waterExtentsArr.Max(c => c.Max));

            debuggingOutput.WaterSnapshots.ForEach(c => MyArrayUtils.Normalize(c.Array, waterExtents));


            _go = GameObject.CreatePrimitive(PrimitiveType.Quad);
            var material = new Material(Shader.Find("Custom/Terrain/Terrain_Debug_Comparision_StepByStep"));

            _go.GetComponent <MeshRenderer>().material = material;
            _go.name = "Terrain";
            _go.transform.localRotation          = Quaternion.Euler(0, 0, 0);
            _go.transform.localScale             = new Vector3(10, 1, 10);
            _go.transform.localPosition          = new Vector3(0, 0, 0);
            _go.GetComponent <MeshFilter>().mesh = PlaneGenerator.CreateFlatPlaneMesh(240, 240);

            MyHeightTextureArray heightTextureArray =
                new MyHeightTextureArray(240, 240, 2, TextureFormat.ARGB32, false, true);

            heightTextureArray.AddElementArray(heightmap1, 0);
            heightTextureArray.AddElementArray(new HeightmapArray(currentHeightArray.Array), 1);
            _go.GetComponent <MeshRenderer>().material
            .SetTexture("_HeightmapTexArray", heightTextureArray.ApplyAndRetrive());


            MyHeightTextureArray waterArray = new MyHeightTextureArray(240, 240, debuggingOutput.WaterSnapshots.Count,
                                                                       TextureFormat.ARGB32, false, true);
            int i = 0;

            foreach (var waterSnapshot in debuggingOutput.WaterSnapshots)
            {
                waterArray.AddElementArray(new HeightmapArray(waterSnapshot.Array), i);
                i++;
            }
            _go.GetComponent <MeshRenderer>().material.SetTexture("_WaterArray", waterArray.ApplyAndRetrive());


            MyHeightTextureArray sedimentArray = new MyHeightTextureArray(240, 240,
                                                                          debuggingOutput.SedimentSnapshots.Count, TextureFormat.ARGB32, false, true);
            int j = 0;

            foreach (var sedimentSnapshot in debuggingOutput.SedimentSnapshots)
            {
                sedimentArray.AddElementArray(new HeightmapArray(sedimentSnapshot.Array), j);
                j++;
            }
            _go.GetComponent <MeshRenderer>().material.SetTexture("_SedimentArray", sedimentArray.ApplyAndRetrive());
        }