コード例 #1
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();
        }
コード例 #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);
        }
コード例 #3
0
        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();
        }
コード例 #4
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);
        }
コード例 #5
0
        public HeightmapArray LoadHeightmapFromTextureFile(string pathToTemplateFile)
        {
            var tex = SavingFileManager.LoadPngTextureFromFile(pathToTemplateFile, 240, 240,
                                                               TextureFormat.ARGB32, false,
                                                               false);

            return(HeightmapUtils.CreateHeightmapArrayFromTexture(tex));
        }
コード例 #6
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);
        }
コード例 #7
0
        public HeightmapArray CreateRing1HeightmapArray(HeightmapArray inputHeightmap)
        {
            assertInputHeightmapHasProperSize(inputHeightmap);
            var inputTexture =
                HeightmapUtils.CreateTextureFromHeightmap(inputHeightmap); // input texture is 256x256 (5.7x5.7) p22.3m
            var conventionalRing1Texture = RenderConventionalRing1Texture(inputTexture, new UniformsPack());
            var heightmapArray           = HeightmapUtils.CreateHeightmapArrayFromTexture(conventionalRing1Texture);

            DiamondSquareCreator diamondSquareCreator = new DiamondSquareCreator(new RandomProvider());

            heightmapArray = diamondSquareCreator.AddDetail(heightmapArray);
            return(heightmapArray);
        }
コード例 #8
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);
        }
コード例 #9
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());
        }
コード例 #10
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);
        }