Пример #1
0
        public static TerrainDetailGenerator CreateTerrainDetailGenerator(
            Texture mainTexture, UTTextureRendererProxy utTextureRendererProxy,
            CommonExecutorUTProxy commonExecutorUtProxy,
            UnityThreadComputeShaderExecutorObject computeShaderExecutorObject,
            ComputeShaderContainerGameObject containerGameObject)
        {
            var featureAppliers =
                TerrainDetailProviderDebugUtils.CreateFeatureAppliers(utTextureRendererProxy, containerGameObject,
                                                                      commonExecutorUtProxy, computeShaderExecutorObject);

            TerrainDetailGeneratorConfiguration generatorConfiguration = new TerrainDetailGeneratorConfiguration()
            {
                TerrainDetailImageSideDisjointResolution = 240
            };
            TextureWithCoords fullFundationData = new TextureWithCoords(new TextureWithSize()
            {
                Texture = mainTexture,
                Size    = new IntVector2(mainTexture.width, mainTexture.height)
            }, new MyRectangle(0, 0, 3601 * 24, 3601 * 24));

            TerrainDetailGenerator generator =
                new TerrainDetailGenerator(generatorConfiguration, utTextureRendererProxy, fullFundationData,
                                           featureAppliers, commonExecutorUtProxy);

            return(generator);
        }
        private TerrainDetailGenerator CreateTerrainDetailGenerator(
            Texture mainTexture,
            UTTextureRendererProxy utTextureRendererProxy,
            CommonExecutorUTProxy commonExecutorUtProxy,
            UnityThreadComputeShaderExecutorObject computeShaderExecutorObject,
            ComputeShaderContainerGameObject containerGameObject)
        {
            var featureAppliers = new List <RankedTerrainFeatureApplier>();

            if (_configuration.EngraveTerrainFeatures)
            {
                featureAppliers.AddRange(FinalTerrainFeatureAppliers.CreateFeatureAppliers(
                                             utTextureRendererProxy, containerGameObject, commonExecutorUtProxy, computeShaderExecutorObject
                                             ));
            }
            if (_configuration.EngraveRoadsInTerrain)
            {
                featureAppliers.Add(FinalTerrainFeatureAppliers.CreateRoadEngravingApplier(CreateRoadEngravingFeatureApplier()));
            }

            TerrainDetailGeneratorConfiguration generatorConfiguration =
                _configuration.TerrainDetailGeneratorConfiguration;

            TextureWithCoords fullFundationData = new TextureWithCoords(new TextureWithSize()
            {
                Texture = mainTexture,
                Size    = new IntVector2(mainTexture.width, mainTexture.height)
            }, new MyRectangle(0, 0, 3601 * 24, 3601 * 24));

            TerrainDetailGenerator generator = new TerrainDetailGenerator(generatorConfiguration,
                                                                          utTextureRendererProxy, fullFundationData, featureAppliers, commonExecutorUtProxy);

            return(generator);
        }
Пример #3
0
        public void Start()
        {
            TaskUtils.SetGlobalMultithreading(false);
            TextureRendererServiceConfiguration textureRendererServiceConfiguration = new TextureRendererServiceConfiguration();

            textureRendererServiceConfiguration.StepSize = new Vector2(10, 10);

            UTTextureRendererProxy utTextureRenderer = new UTTextureRendererProxy(new TextureRendererService(
                                                                                      new MultistepTextureRenderer(Object.FindObjectOfType <ComputeShaderContainerGameObject>()), textureRendererServiceConfiguration));

            TextureConcieverUTProxy utTextureConciever = new TextureConcieverUTProxy();

            LateAssignFactory <BaseTerrainDetailProvider> terrainDetailProviderFactory = new LateAssignFactory <BaseTerrainDetailProvider>(() => _mockProvider);

            _merger = new TerrainDetailCornerMerger(terrainDetailProviderFactory, new TerrainDetailAlignmentCalculator(240), utTextureRenderer, utTextureConciever, new CommonExecutorUTProxy(), new TerrainDetailCornerMergerConfiguration());

            //TaskUtils.DebuggerAwareWait(Test1());
            //TaskUtils.DebuggerAwareWait(Test2());
            //TaskUtils.DebuggerAwareWait(Test3());
            //TaskUtils.DebuggerAwareWait(Test4());
            //TaskUtils.DebuggerAwareWait(Test5());
            //TaskUtils.DebuggerAwareWait(Test6());
            //TaskUtils.DebuggerAwareWait(Test7());
            TaskUtils.DebuggerAwareWait(Test8());
        }
Пример #4
0
 public RandomNoiseTerrainFeatureApplier(UTTextureRendererProxy rendererProxy,
                                         CommonExecutorUTProxy commonExecutor,
                                         Dictionary <TerrainCardinalResolution, RandomNoiseTerrainFeatureApplierConfiguration> configurations)
 {
     _rendererProxy  = rendererProxy;
     _commonExecutor = commonExecutor;
     _configurations = configurations;
 }
Пример #5
0
 public ETerrainHeightPyramidFacade(ETerrainHeightBuffersManager buffersManager,
                                    MeshGeneratorUTProxy meshGeneratorUtProxy, UTTextureRendererProxy textureRendererProxy,
                                    ETerrainHeightPyramidFacadeStartConfiguration startConfiguration)
 {
     _buffersManager       = buffersManager;
     _meshGeneratorUtProxy = meshGeneratorUtProxy;
     _textureRendererProxy = textureRendererProxy;
     _startConfiguration   = startConfiguration;
 }
Пример #6
0
        public void InitializeUTRendererProxy()
        {
            UTTextureRendererProxy textureRendererProxy = new UTTextureRendererProxy(new TextureRendererService(
                                                                                         new MultistepTextureRenderer(_gameInitializationFields.Retrive <ComputeShaderContainerGameObject>()),
                                                                                         _configuration.TextureRendererServiceConfiguration));

            _updatableContainer.Add(textureRendererProxy);
            _gameInitializationFields.SetField(textureRendererProxy);
        }
Пример #7
0
 public ESurfaceSegmentPlacer(UTTextureRendererProxy renderer, RenderTexture floorTextureArray
                              , int ceilArraySliceIndex, IntVector2 floorSlotsCount, IntVector2 floorTextureSize)
 {
     _renderer            = renderer;
     _floorTextureArray   = floorTextureArray;
     _ceilArraySliceIndex = ceilArraySliceIndex;
     _floorSlotsCount     = floorSlotsCount;
     _floorTextureSize    = floorTextureSize;
 }
Пример #8
0
 public DiamondSquareTerrainFeatureApplier(RandomProviderGenerator randomProviderGenerator,
                                           CommonExecutorUTProxy commonExecutor, UTTextureRendererProxy rendererProxy,
                                           Dictionary <TerrainCardinalResolution, DiamondSquareTerrainFeatureApplierConfiguration> configurations)
 {
     _randomProviderGenerator = randomProviderGenerator;
     _commonExecutor          = commonExecutor;
     _rendererProxy           = rendererProxy;
     _configurations          = configurations;
 }
Пример #9
0
 public TerrainDetailGenerator(TerrainDetailGeneratorConfiguration configuration,
                               UTTextureRendererProxy rendererProxy, TextureWithCoords fullFundationTextureData,
                               List <RankedTerrainFeatureApplier> featureAppliers, CommonExecutorUTProxy commonExecutor)
 {
     _configuration            = configuration;
     _rendererProxy            = rendererProxy;
     _fullFundationTextureData = fullFundationTextureData;
     _featureAppliers          = featureAppliers;
     _commonExecutor           = commonExecutor;
 }
        private void InitializeFields()
        {
            TextureRendererServiceConfiguration rendererServiceConfiguration = new TextureRendererServiceConfiguration()
            {
                StepSize = new Vector2(500, 500)
            };

            _utTextureRendererProxy = new UTTextureRendererProxy(
                new TextureRendererService(new MultistepTextureRenderer(ContainerGameObject),
                                           rendererServiceConfiguration));
        }
Пример #11
0
 public TerrainDetailCornerMerger(LateAssignFactory <BaseTerrainDetailProvider> terrainDetailProviderFactory,
                                  TerrainDetailAlignmentCalculator alignmentCalculator, UTTextureRendererProxy renderer, TextureConcieverUTProxy textureConciever,
                                  CommonExecutorUTProxy commonExecutor, TerrainDetailCornerMergerConfiguration configuration)
 {
     _terrainDetailProviderFactory = terrainDetailProviderFactory;
     _alignmentCalculator          = alignmentCalculator;
     _renderer            = renderer;
     _textureConciever    = textureConciever;
     this._commonExecutor = commonExecutor;
     _configuration       = configuration;
 }
Пример #12
0
 public HeightSegmentPlacer(UTTextureRendererProxy renderer, CommonExecutorUTProxy commonExecutor, RenderTexture heightMap, int heightMapSliceIndex,
                            IntVector2 floorSlotsCount, IntVector2 floorTextureSize, float interSegmentMarginSize, IntVector2 modifiedCornerBufferSize, bool modifyCorners = true)
 {
     _renderer                 = renderer;
     _commonExecutor           = commonExecutor;
     _heightMap                = heightMap;
     _heightMapSliceIndex      = heightMapSliceIndex;
     _floorSlotsCount          = floorSlotsCount;
     _floorTextureSize         = floorTextureSize;
     _interSegmentMarginSize   = interSegmentMarginSize;
     _modifiedCornerBufferSize = modifiedCornerBufferSize;
     _modifyCorners            = modifyCorners;
 }
Пример #13
0
        public DebugFlatTerrainShapeDb(UTTextureRendererProxy textureRenderer)
        {
            var size = new IntVector2(241, 241);
            var tex  = new Texture2D(size.X, size.Y, TextureFormat.ARGB32, true, true);

            for (int x = 0; x < size.X; x++)
            {
                for (int y = 0; y < size.Y; y++)
                {
                    tex.SetPixel(x, y, new Color(0, 0, 0, 0));
                }
            }
            tex.Apply();

            _blankTexture = new TextureWithSize()
            {
                Texture = tex,
                Size    = size
            };

            var pack = new UniformsPack();

            pack.SetTexture("_HeightmapTex", tex);
            pack.SetUniform("_HeightMultiplier", 80);
            ConventionalTextureInfo outTextureInfo =
                new ConventionalTextureInfo(size.X, size.Y, TextureFormat.ARGB32, true);

            var renderCoords = new MyRectangle(0, 0, 1, 1);
            TextureRenderingTemplate template = new TextureRenderingTemplate()
            {
                CanMultistep        = false,
                Coords              = renderCoords,
                OutTextureInfo      = outTextureInfo,
                RenderTextureFormat = RenderTextureFormat.ARGB32,
                ShaderName          = "Custom/Terrain/NormalmapGenerator",
                UniformPack         = pack,
                CreateTexture2D     = false
            };
            var outNormalTex = textureRenderer.AddOrder(template).Result;

            _normalTexture = new TextureWithSize()
            {
                Size    = size,
                Texture = outNormalTex
            };
        }
        public static ESurfacePatchProvider ConstructProvider(UltraUpdatableContainer updatableContainer, Dictionary <int, float> intensityPatternPixelsPerUnit,
                                                              ComputeShaderContainerGameObject shaderContainerGO, int mipmapLevelToExtract, Dictionary <int, float> plateStampPixelsPerUnit)
        {
            var ring2ShaderRepository         = Ring2PlateShaderRepository.Create();
            TextureConcieverUTProxy conciever = new TextureConcieverUTProxy();

            updatableContainer.Add(conciever);

            var ring2PatchesPainterUtProxy = new Ring2PatchesPainterUTProxy(
                new Ring2PatchesPainter(
                    new Ring2MultishaderMaterialRepository(ring2ShaderRepository, Ring2ShaderNames.ShaderNames)));

            updatableContainer.Add(ring2PatchesPainterUtProxy);

            UTRing2PlateStamperProxy stamperProxy = new UTRing2PlateStamperProxy(
                new Ring2PlateStamper(new Ring2PlateStamperConfiguration()
            {
                PlateStampPixelsPerUnit = plateStampPixelsPerUnit
            }, shaderContainerGO));

            updatableContainer.Add(stamperProxy);

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

            updatableContainer.Add(textureRendererProxy);

            CommonExecutorUTProxy commonExecutorUtProxy = new CommonExecutorUTProxy(); //todo

            updatableContainer.Add(commonExecutorUtProxy);

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

            MipmapExtractor mipmapExtractor     = new MipmapExtractor(textureRendererProxy);
            var             patchesCreatorProxy = new GRing2PatchesCreatorProxy(CreateRing2PatchesCreator(updatableContainer, intensityPatternPixelsPerUnit));

            return(new ESurfacePatchProvider(patchesCreatorProxy, patchStamperOverseerFinalizer, commonExecutorUtProxy, mipmapExtractor, mipmapLevelToExtract));
        }
        private TerrainAndNormalTexture CreateTerrainAndNormalTexture(RenderTexture mainTexture)
        {
            TextureRendererServiceConfiguration rendererServiceConfiguration = new TextureRendererServiceConfiguration()
            {
                StepSize = new Vector2(500, 500)
            };

            _utTextureRendererProxy = new UTTextureRendererProxy(
                new TextureRendererService(new MultistepTextureRenderer(ContainerGameObject),
                                           rendererServiceConfiguration));

            var provider =
                CreateTerrainDetailProvider(
                    TerrainDetailProviderDebugUtils.CreateFeatureAppliers(_utTextureRendererProxy, ContainerGameObject,
                                                                          new CommonExecutorUTProxy(), new UnityThreadComputeShaderExecutorObject()), mainTexture);

            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 outTex    = provider.GenerateHeightDetailElementAsync(queryArea, _terrainResolution, CornersMergeStatus.NOT_MERGED).Result.Texture;
            var outNormal = provider.GenerateNormalDetailElementAsync(queryArea, _terrainResolution, CornersMergeStatus.NOT_MERGED).Result.Texture;

            return(new TerrainAndNormalTexture()
            {
                HeightTexture = outTex.Texture,
                NormalTexture = outNormal.Texture
            });
        }
Пример #16
0
        public TerrainShapeDbUnderTest(bool useTextureSavingToDisk  = false, bool useCornerMerging = false,
                                       string terrainDetailFilePath = "C:\\unityCache\\", bool useTextureLoadingFromDisk = false)
        {
            CommonExecutorUTProxy            commonExecutorUtProxy = new CommonExecutorUTProxy();
            ComputeShaderContainerGameObject containerGameObject   = GameObject.FindObjectOfType <ComputeShaderContainerGameObject>();

            var globalHeightTexture = CreateGlobalHeightTexture(commonExecutorUtProxy);

            UTTextureRendererProxy textureRendererProxy = new UTTextureRendererProxy(new TextureRendererService(
                                                                                         new MultistepTextureRenderer(containerGameObject), new TextureRendererServiceConfiguration()
            {
                StepSize = new Vector2(400, 400)
            }));

            UnityThreadComputeShaderExecutorObject computeShaderExecutorObject = new UnityThreadComputeShaderExecutorObject();
            var terrainDetailGenerator = Ring1DebugObjectV2.CreateTerrainDetailGenerator(
                globalHeightTexture, textureRendererProxy, commonExecutorUtProxy, computeShaderExecutorObject,
                containerGameObject);

            TerrainDetailCornerMerger merger = null;
            LateAssignFactory <BaseTerrainDetailProvider> detailProviderFactory = new LateAssignFactory <BaseTerrainDetailProvider>();

            if (useCornerMerging)
            {
                merger = new TerrainDetailCornerMerger(detailProviderFactory, new TerrainDetailAlignmentCalculator(240), textureRendererProxy, new TextureConcieverUTProxy(),
                                                       new CommonExecutorUTProxy(), new TerrainDetailCornerMergerConfiguration());
            }

            var terrainDetailProvider = Ring1DebugObjectV2.CreateTerrainDetailProvider(terrainDetailGenerator, merger);

            _shapeDb = FETerrainShapeDbInitialization.CreateTerrainShapeDb(terrainDetailProvider, commonExecutorUtProxy
                                                                           , new TerrainDetailAlignmentCalculator(240), useCornerMerging, useTextureSavingToDisk, useTextureLoadingFromDisk
                                                                           , new TerrainDetailFileManager(terrainDetailFilePath, commonExecutorUtProxy));

            var baseProvider = new FromTerrainDbBaseTerrainDetailProvider(_shapeDb);

            detailProviderFactory.Assign(baseProvider);
            terrainDetailGenerator.SetBaseTerrainDetailProvider(baseProvider);
        }
Пример #17
0
        public void Start()
        {
            TaskUtils.SetGlobalMultithreading(false);
            ComputeShaderContainerGameObject containerGameObject  = GameObject.FindObjectOfType <ComputeShaderContainerGameObject>();
            UTTextureRendererProxy           textureRendererProxy = new UTTextureRendererProxy(new TextureRendererService(
                                                                                                   new MultistepTextureRenderer(containerGameObject), new TextureRendererServiceConfiguration()
            {
                StepSize = new Vector2(400, 400)
            }));
            var meshGeneratorUtProxy = new MeshGeneratorUTProxy(new MeshGeneratorService());


            eTerrainHeightPyramidFacades = new List <ETerrainHeightPyramidFacade>()
            {
                StartTerrainThings(meshGeneratorUtProxy, textureRendererProxy, containerGameObject,
                                   new List <HeightPyramidLevel>()
                {
                    HeightPyramidLevel.Top
                }),
                //StartTerrainThings(meshGeneratorUtProxy, textureRendererProxy, containerGameObject,
                //    new List<HeightPyramidLevel>() {HeightPyramidLevel.Top, HeightPyramidLevel.Mid, HeightPyramidLevel.Bottom})
            };
        }
Пример #18
0
        private ETerrainHeightPyramidFacade StartTerrainThings(MeshGeneratorUTProxy meshGeneratorUtProxy, UTTextureRendererProxy textureRendererProxy,
                                                               ComputeShaderContainerGameObject containerGameObject, List <HeightPyramidLevel> startConfigurationHeightPyramidLevels)
        {
            var startConfiguration = ETerrainHeightPyramidFacadeStartConfiguration.DefaultConfiguration;

            //startConfiguration.HeightPyramidLevels = new List<HeightPyramidLevel>() {HeightPyramidLevel.Top};
            startConfiguration.HeightPyramidLevels = startConfigurationHeightPyramidLevels;

            ETerrainHeightBuffersManager buffersManager = new ETerrainHeightBuffersManager();
            var eTerrainHeightPyramidFacade             = new ETerrainHeightPyramidFacade(buffersManager, meshGeneratorUtProxy, textureRendererProxy, startConfiguration);

            var perLevelTemplates = eTerrainHeightPyramidFacade.GenerateLevelTemplates();
            var levels            = startConfiguration.HeightPyramidLevels;

            buffersManager.InitializeBuffers(levels.ToDictionary(c => c, c => new EPyramidShaderBuffersGeneratorPerRingInput()
            {
                FloorTextureResolution = startConfiguration.CommonConfiguration.FloorTextureSize.X,            //TODO i use only X, - works only for squares
                HeightMergeRanges      = perLevelTemplates[c].PerRingTemplates.ToDictionary(k => k.Key, k => k.Value.HeightMergeRange),
                CeilSliceWorldSize     = startConfiguration.PerLevelConfigurations[c].FloorTextureWorldSize.x, // TODO works only for square pyramids - i use width
                RingUvRanges           = startConfiguration.CommonConfiguration.RingsUvRange
            }), startConfiguration.CommonConfiguration.MaxLevelsCount, startConfiguration.CommonConfiguration.MaxRingsPerLevelCount);


            var configuration = new FEConfiguration(new FilePathsConfiguration());
            GlobalServicesProfileInfo servicesProfileInfo = new GlobalServicesProfileInfo();
            var ultraUpdatableContainer = new UltraUpdatableContainer(
                configuration.SchedulerConfiguration,
                servicesProfileInfo,
                configuration.UpdatableContainerConfiguration);
            var updatableContainer            = new UpdatableContainer();
            var intensityPatternPixelsPerUnit = new Dictionary <int, float>()
            {
                { 1, 1 }
            };
            int mipmapLevelToExtract    = 2;
            var plateStampPixelsPerUnit = new Dictionary <int, float>()
            {
                { 1, 3 }
            };
            var surfacePatchProvider = ESurfaceProviderInitializationHelper.ConstructProvider(
                ultraUpdatableContainer, intensityPatternPixelsPerUnit, containerGameObject, mipmapLevelToExtract, plateStampPixelsPerUnit);
            var surfaceTextureFormat = RenderTextureFormat.ARGB32;

            eTerrainHeightPyramidFacade.Start(perLevelTemplates,
                                              new Dictionary <EGroundTextureType, OneGroundTypeLevelTextureEntitiesGenerator>()
            {
                //{
                //    EGroundTextureType.SurfaceTexture, new OneGroundTypeLevelTextureEntitiesGenerator()
                //    {
                //        SegmentFillingListenerGeneratorFunc = (level) =>
                //        {
                //            var floorTexture = EGroundTextureGenerator.GenerateEmptyGroundTexture(startConfiguration.CommonConfiguration.FloorTextureSize,
                //                surfaceTextureFormat);
                //            var segmentsPlacer = new ESurfaceSegmentPlacer(textureRendererProxy, floorTexture
                //                , startConfiguration.CommonConfiguration.SlotMapSize, startConfiguration.CommonConfiguration.FloorTextureSize);
                //            var pyramidLevelManager = new GroundLevelTexturesManager(startConfiguration.CommonConfiguration.SlotMapSize);
                //            var segmentModificationManager = new SoleLevelGroundTextureSegmentModificationsManager(segmentsPlacer, pyramidLevelManager);

                //            return new SegmentFillingListenerWithFloorTexture()
                //            {
                //                FloorTexture = floorTexture,
                //                SegmentFillingListener =
                //                    new LambdaSegmentFillingListener(
                //                        (c) =>
                //                        {
                //                            var segmentLength = startConfiguration.PerLevelConfigurations[level].BiggestShapeObjectInGroupLength;
                //                            var sap = c.SegmentAlignedPosition;
                //                            MyRectangle surfaceWorldSpaceRectangle = new MyRectangle(sap.X * segmentLength, sap.Y * segmentLength,
                //                                segmentLength, segmentLength);
                //                            var texturesPack = surfacePatchProvider.ProvideSurfaceDetailAsync(surfaceWorldSpaceRectangle, new FlatLod(1, 1)).Result;
                //                            if (texturesPack != null)
                //                            {
                //                                var mainTexture = texturesPack.MainTexture;
                //                                segmentModificationManager.AddSegmentAsync(mainTexture, c.SegmentAlignedPosition);
                //                                GameObject.Destroy(mainTexture);
                //                            }

                //                            //}
                //                        },
                //                        (c) => { },
                //                        (c) => { })
                //            };

                //        },
                //    }
                //}
            }
                                              );

            Traveller.transform.position = new Vector3(startConfiguration.InitialTravellerPosition.x, 0, startConfiguration.InitialTravellerPosition.y);
            eTerrainHeightPyramidFacade.DisableLevelShapes(HeightPyramidLevel.Bottom);

            return(eTerrainHeightPyramidFacade);
        }
Пример #19
0
 public TAMMarginsWrapper(UTTextureRendererProxy textureRenderer, TAMMarginsWrapperConfiguration configuration)
 {
     _textureRenderer = textureRenderer;
     _configuration   = configuration;
 }
Пример #20
0
        public DebugSlopedTerrainShapeDb(UTTextureRendererProxy textureRenderer)
        {
            var size             = new IntVector2(241, 241);
            var tex              = new Texture2D(size.X, size.Y, TextureFormat.ARGB32, true, true);
            var encodedHeightTex = new Texture2D(size.X, size.Y, TextureFormat.ARGB32, true, true);

            for (int x = 0; x < size.X; x++)
            {
                for (int y = 0; y < size.Y; y++)
                {
                    tex.SetPixel(x, y, new Color(0, 0, 0, 0));

                    //var distanceToCenter = 1 - (Vector2.Distance(new Vector2(120, 120), new Vector2(x, y)) /
                    //                            Mathf.Sqrt(120 * 120)) / 2;
                    //encodedHeightTex.SetPixel(x, y, HeightColorTransform.EncodeHeight(distanceToCenter / 100));

                    //var distanceToCenter = Mathf.Clamp01(
                    //    Mathf.Min(
                    //        Mathf.Abs(y - 100) / 50.0f,
                    //        Mathf.Abs(x - 100) / 50.0f)
                    //        ) / 300;

                    //encodedHeightTex.SetPixel(x, y, HeightColorTransform.EncodeHeight(distanceToCenter));


                    var heightInUnits = HeightDenormalizer.Default.Normalize(5);
                    var encodedHeight = HeightColorTransform.EncodeHeight(heightInUnits);
                    encodedHeightTex.SetPixel(x, y, encodedHeight);
                }
            }
            tex.Apply();
            encodedHeightTex.Apply();

            _blankTexture = new TextureWithSize()
            {
                Texture = tex,
                Size    = size
            };

            var transformator        = new TerrainTextureFormatTransformator(new CommonExecutorUTProxy());
            var encodedHeightTexture = new TextureWithSize()
            {
                Texture = encodedHeightTex,
                Size    = new IntVector2(241, 241)
            };
            var plainTex = transformator.EncodedHeightTextureToPlain(encodedHeightTexture);

            _heightTexture = new TextureWithSize()
            {
                Size    = new IntVector2(241, 241),
                Texture = plainTex
            };

            var pack = new UniformsPack();

            pack.SetTexture("_HeightmapTex", plainTex);
            pack.SetUniform("_HeightMultiplier", 80);
            ConventionalTextureInfo outTextureInfo =
                new ConventionalTextureInfo(size.X, size.Y, TextureFormat.ARGB32, true);

            var renderCoords = new MyRectangle(0, 0, 1, 1);
            TextureRenderingTemplate template = new TextureRenderingTemplate()
            {
                CanMultistep        = false,
                Coords              = renderCoords,
                OutTextureInfo      = outTextureInfo,
                RenderTextureFormat = RenderTextureFormat.ARGB32,
                ShaderName          = "Custom/Terrain/NormalmapGenerator",
                UniformPack         = pack,
                CreateTexture2D     = false
            };
            var outNormalTex = textureRenderer.AddOrder(template).Result;

            _normalTexture = new TextureWithSize()
            {
                Size    = size,
                Texture = outNormalTex
            };
        }
Пример #21
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,
            });
        }
Пример #22
0
 public MipmapExtractor(UTTextureRendererProxy textureRenderer)
 {
     _textureRenderer = textureRenderer;
 }
Пример #23
0
        public void Start()
        {
            UnityEngine.Random.InitState(412);
            TaskUtils.SetGlobalMultithreading(false);
            UnityThreadComputeShaderExecutorObject shaderExecutorObject = new UnityThreadComputeShaderExecutorObject();
            ComputeShaderContainerGameObject       containerGameObject  = GameObject.FindObjectOfType <ComputeShaderContainerGameObject>();
            UTTextureRendererProxy textureRendererProxy = new UTTextureRendererProxy(new TextureRendererService(
                                                                                         new MultistepTextureRenderer(containerGameObject), new TextureRendererServiceConfiguration()
            {
                StepSize = new Vector2(400, 400)
            }));
            var meshGeneratorUtProxy = new MeshGeneratorUTProxy(new MeshGeneratorService());

            var startConfiguration = ETerrainHeightPyramidFacadeStartConfiguration.DefaultConfiguration;

            ETerrainHeightBuffersManager buffersManager = new ETerrainHeightBuffersManager();

            _eTerrainHeightPyramidFacade = new ETerrainHeightPyramidFacade(buffersManager, meshGeneratorUtProxy, textureRendererProxy, startConfiguration);

            var perLevelTemplates = _eTerrainHeightPyramidFacade.GenerateLevelTemplates();

            var levels = startConfiguration.PerLevelConfigurations.Keys;
            var ePyramidShaderBuffersGeneratorPerRingInputs = levels.ToDictionary(c => c, c => new EPyramidShaderBuffersGeneratorPerRingInput()
            {
                FloorTextureResolution = startConfiguration.CommonConfiguration.FloorTextureSize.X,            //TODO i use only X, - works only for squares
                HeightMergeRanges      = perLevelTemplates[c].PerRingTemplates.ToDictionary(k => k.Key, k => k.Value.HeightMergeRange),
                CeilSliceWorldSize     = startConfiguration.PerLevelConfigurations[c].FloorTextureWorldSize.x, // TODO works only for square pyramids - i use width
                RingUvRanges           = startConfiguration.CommonConfiguration.RingsUvRange
            });

            buffersManager.InitializeBuffers(ePyramidShaderBuffersGeneratorPerRingInputs, startConfiguration.CommonConfiguration.MaxLevelsCount, startConfiguration.CommonConfiguration.MaxRingsPerLevelCount);

            _eTerrainHeightPyramidFacade.Start(perLevelTemplates,
                                               new Dictionary <EGroundTextureType, OneGroundTypeLevelTextureEntitiesGenerator>()
            {
                //{
                //    EGroundTextureType.HeightMap, new OneGroundTypeLevelTextureEntitiesGenerator()
                //    {
                //        SegmentFillingListenerGeneratorFunc = (level) =>
                //        {
                //            var floorTexture =
                //                EGroundTextureGenerator.GenerateEmptyGroundTexture(startConfiguration.CommonConfiguration.FloorTextureSize,
                //                    startConfiguration.CommonConfiguration.HeightTextureFormat);
                //            var segmentsPlacer = new ESurfaceSegmentPlacer(textureRendererProxy, floorTexture
                //                , startConfiguration.CommonConfiguration.SlotMapSize, startConfiguration.CommonConfiguration.FloorTextureSize);
                //            var pyramidLevelManager = new GroundLevelTexturesManager(startConfiguration.CommonConfiguration.SlotMapSize);
                //            var segmentModificationManager = new SoleLevelGroundTextureSegmentModificationsManager(segmentsPlacer, pyramidLevelManager);
                //            return new SegmentFillingListenerWithFloorTexture()
                //            {
                //                FloorTexture = floorTexture,
                //                SegmentFillingListener = new LambdaSegmentFillingListener(
                //                    (c) =>
                //                    {
                //                        var segmentTexture = ETerrainIntegrationMultipleSegmentsDEO.CreateDummySegmentTexture(c, level);
                //                        segmentModificationManager.AddSegmentAsync(segmentTexture, c.SegmentAlignedPosition);
                //                    },
                //                    (c) => { },
                //                    (c) => { }

                //                )
                //            };

                //        },
                //    }
                //}
            }
                                               );
            //_eTerrainHeightPyramidFacade.DisableShapes();
            _eTerrainHeightPyramidFacade.DisableLevelShapes(HeightPyramidLevel.Bottom);

            Traveller.transform.position = new Vector3(startConfiguration.InitialTravellerPosition.x, 0, startConfiguration.InitialTravellerPosition.y);

            var ePropLocationConfiguration = new EPropElevationConfiguration();
            EPropConstantPyramidParameters ePropConstantPyramidParameters = new EPropConstantPyramidParameters()
            {
                LevelsCount        = startConfiguration.HeightPyramidLevels.Count,
                RingsPerLevelCount = startConfiguration.CommonConfiguration.MaxRingsPerLevelCount, //TODO parametrize
                HeightScale        = startConfiguration.CommonConfiguration.YScale
            };

            _elevationManager = new EPropElevationManager(new CommonExecutorUTProxy(), shaderExecutorObject, ePropLocationConfiguration, ePropConstantPyramidParameters);
            var heightFloorTextureArray = _eTerrainHeightPyramidFacade.FloorTextureArrays.Where(c => c.TextureType == EGroundTextureType.HeightMap).Select(c => c.Texture).First();
            var initializedBuffers      = _elevationManager.Initialize(buffersManager.PyramidPerFrameParametersBuffer, buffersManager.EPyramidConfigurationBuffer,
                                                                       heightFloorTextureArray);
            var ePropLocaleBuffer = initializedBuffers.EPropLocaleBuffer;
            var ePropIdsBuffer    = initializedBuffers.EPropIdsBuffer;

            _dummyObjectsDisplayer = new EPropDummyObjectsDisplayer(ePropLocationConfiguration.ScopeLength, ePropLocaleBuffer, ePropIdsBuffer, FindObjectOfType <BufferReloaderRootGO>());
            _dummyObjectsDisplayer.Start();

            _dummyObjectsInstancingDisplayer = new EPropDummyObjectsInstancingDisplayer(DebugMesh, DebugMeshMaterial);
            _dummyObjectsInstancingDisplayer.Start();
            _dummyObjectsInstancingDisplayer.SetLocaleBuffers(ePropLocaleBuffer, ePropIdsBuffer, ePropLocationConfiguration.ScopeLength);

            _sectorAreasDisplayer = new EPropDebugSectorAreasDisplayer();
            _sectorAreasDisplayer.Start();

            _mergeRingsDisplayer = new EPropDebugMergeRingsDisplayer();
            _mergeRingsDisplayer.Start();
            var levelWorldSizes = startConfiguration.PerLevelConfigurations.ToDictionary(c => c.Key, c => c.Value.FloorTextureWorldSize);
            var ringMergeRanges = perLevelTemplates.ToDictionary(c => c.Key,
                                                                 c => c.Value.PerRingTemplates.ToDictionary(k => k.Key, k => k.Value.HeightMergeRange));

            _ePropHotAreaSelector = new EPropHotAreaSelector(levelWorldSizes, ringMergeRanges);

            _elevationManager.DebugInitializeSectors(new MyRectangle(-200, -200, 400, 400));
        }
Пример #24
0
 public Grass2BillboardGenerator(UTTextureRendererProxy textureRenderer,
                                 Grass2BillboardGeneratorConfiguration configuration)
 {
     _textureRenderer = textureRenderer;
     _configuration   = configuration;
 }
        public static List <RankedTerrainFeatureApplier> CreateFeatureAppliers(
            UTTextureRendererProxy utTextureRendererProxy,
            ComputeShaderContainerGameObject computeShaderContainerGameObject,
            CommonExecutorUTProxy commonExecutor,
            UnityThreadComputeShaderExecutorObject threadComputeShaderExecutorObject,
            Func <RoadEngravingTerrainFeatureApplier> roadApplierCreatingFunc = null)
        {
            var toReturn = new List <RankedTerrainFeatureApplier>()
            {
                new RankedTerrainFeatureApplier()
                {
                    Rank    = 1,
                    Applier = new RandomNoiseTerrainFeatureApplier(utTextureRendererProxy, commonExecutor,
                                                                   new Dictionary <TerrainCardinalResolution, RandomNoiseTerrainFeatureApplierConfiguration>
                    {
                        {
                            TerrainCardinalResolution.MIN_RESOLUTION,
                            new RandomNoiseTerrainFeatureApplierConfiguration()
                            {
                                DetailResolutionMultiplier = 1,
                                NoiseStrengthMultiplier    = 1
                            }
                        },
                        {
                            TerrainCardinalResolution.MID_RESOLUTION,
                            new RandomNoiseTerrainFeatureApplierConfiguration()
                            {
                                DetailResolutionMultiplier = 8,
                                NoiseStrengthMultiplier    = 0.45f
                            }
                        },
                        {
                            TerrainCardinalResolution.MAX_RESOLUTION,
                            new RandomNoiseTerrainFeatureApplierConfiguration()
                            {
                                DetailResolutionMultiplier = 8 * 8,
                                NoiseStrengthMultiplier    = 4.7f * 0.45f / 9f  //todo CHANGE IT !!
                            }
                        },
                    }),
                    AvalibleResolutions = new List <TerrainCardinalResolution>()
                    {
                        TerrainCardinalResolution.MIN_RESOLUTION,
                        TerrainCardinalResolution.MID_RESOLUTION,
                        TerrainCardinalResolution.MAX_RESOLUTION,
                    }
                },
                new RankedTerrainFeatureApplier()
                {
                    Rank    = 2,
                    Applier = new DiamondSquareTerrainFeatureApplier(
                        new RandomProviderGenerator(123), commonExecutor,
                        utTextureRendererProxy,
                        new Dictionary <TerrainCardinalResolution, DiamondSquareTerrainFeatureApplierConfiguration>
                    {
                        {
                            TerrainCardinalResolution.MIN_RESOLUTION,
                            new DiamondSquareTerrainFeatureApplierConfiguration
                            {
                                DiamondSquareWorkingArrayLength = 32,
                                DiamondSquareWeight             = 0.012f
                            }
                        },
                        {
                            TerrainCardinalResolution.MID_RESOLUTION,
                            new DiamondSquareTerrainFeatureApplierConfiguration
                            {
                                DiamondSquareWorkingArrayLength = 32,
                                DiamondSquareWeight             = 0.0025f * 1.3f
                            }
                        },
                        {
                            TerrainCardinalResolution.MAX_RESOLUTION,
                            new DiamondSquareTerrainFeatureApplierConfiguration
                            {
                                DiamondSquareWorkingArrayLength = 32,
                                DiamondSquareWeight             = 0.0003f
                            }
                        },
                    }),
                    AvalibleResolutions = new List <TerrainCardinalResolution>()
                    {
                        TerrainCardinalResolution.MIN_RESOLUTION,
                        TerrainCardinalResolution.MID_RESOLUTION,
                        TerrainCardinalResolution.MAX_RESOLUTION,
                    }
                },
                new RankedTerrainFeatureApplier()
                {
                    Rank    = 3,
                    Applier = new ThermalErosionTerrainFeatureApplier(computeShaderContainerGameObject,
                                                                      threadComputeShaderExecutorObject, commonExecutor,
                                                                      new Dictionary <TerrainCardinalResolution, ThermalErosionTerrainFeatureApplierConfiguration>
                    {
                        {
                            TerrainCardinalResolution.MIN_RESOLUTION,
                            new ThermalErosionTerrainFeatureApplierConfiguration
                            {
                            }
                        },
                        {
                            TerrainCardinalResolution.MID_RESOLUTION,
                            new ThermalErosionTerrainFeatureApplierConfiguration
                            {
                                TParam = 0.001f / 2.3f,
                                CParam = 0.06f
                            }
                        },
                    }),
                    AvalibleResolutions = new List <TerrainCardinalResolution>()
                    {
                        TerrainCardinalResolution.MIN_RESOLUTION,
                        TerrainCardinalResolution.MID_RESOLUTION
                    }
                },
                new RankedTerrainFeatureApplier()
                {
                    Rank    = 4,
                    Applier = new HydraulicErosionTerrainFeatureApplier(computeShaderContainerGameObject,
                                                                        threadComputeShaderExecutorObject,
                                                                        new Dictionary <TerrainCardinalResolution, HydraulicEroderConfiguration>()
                    {
                        {
                            TerrainCardinalResolution.MIN_RESOLUTION, new HydraulicEroderConfiguration()
                            {
                                StepCount = 20,
                                kr_ConstantWaterAddition  = 0.000002f,    // 0.0001f,
                                ks_GroundToSedimentFactor = 1f,
                                ke_WaterEvaporationFactor = 0.05f,
                                kc_MaxSedimentationFactor = 0.8f,
                            }
                        },
                        {
                            TerrainCardinalResolution.MID_RESOLUTION, new HydraulicEroderConfiguration()
                            {
                                StepCount = 20,
                                kr_ConstantWaterAddition  = 0.000002f,    // 0.0001f,
                                ks_GroundToSedimentFactor = 1f,
                                ke_WaterEvaporationFactor = 0.05f,
                                kc_MaxSedimentationFactor = 0.8f / 2f,
                            }
                        },
                        {
                            TerrainCardinalResolution.MAX_RESOLUTION, new HydraulicEroderConfiguration()
                            {
                                StepCount = 20,
                                kr_ConstantWaterAddition  = 0.0000035f,    // 0.0001f,
                                ks_GroundToSedimentFactor = 1f,
                                ke_WaterEvaporationFactor = 0.05f,
                                kc_MaxSedimentationFactor = 0.8f / 4f,
                            }
                        }
                    }),
                    AvalibleResolutions = new List <TerrainCardinalResolution>()
                    {
                        TerrainCardinalResolution.MIN_RESOLUTION,
                        TerrainCardinalResolution.MID_RESOLUTION,
                        TerrainCardinalResolution.MAX_RESOLUTION,
                    }
                },
                new RankedTerrainFeatureApplier()
                {
                    Rank    = 5,
                    Applier = new TweakedThermalErosionTerrainFeatureApplier(computeShaderContainerGameObject,
                                                                             threadComputeShaderExecutorObject,
                                                                             new Dictionary <TerrainCardinalResolution,
                                                                                             TweakedThermalErosionTerrainFeatureApplierConfiguration>
                    {
                        {
                            TerrainCardinalResolution.MIN_RESOLUTION,
                            new TweakedThermalErosionTerrainFeatureApplierConfiguration()
                            {
                            }
                        },
                        {
                            TerrainCardinalResolution.MID_RESOLUTION,
                            new TweakedThermalErosionTerrainFeatureApplierConfiguration()
                            {
                                TParam = 0.001f,
                                CParam = 0.008f
                            }
                        },
                        {
                            TerrainCardinalResolution.MAX_RESOLUTION,
                            new TweakedThermalErosionTerrainFeatureApplierConfiguration()
                            {
                                TParam = 0.001f,
                                CParam = 0.008f
                            }
                        },
                    }),
                    AvalibleResolutions = new List <TerrainCardinalResolution>()
                    {
                        TerrainCardinalResolution.MIN_RESOLUTION,
                        TerrainCardinalResolution.MID_RESOLUTION,
                        TerrainCardinalResolution.MAX_RESOLUTION,
                    }
                },
            };

            if (roadApplierCreatingFunc != null)
            {
                var roadApplier = roadApplierCreatingFunc();
                toReturn.Add(new RankedTerrainFeatureApplier()
                {
                    Applier             = roadApplier,
                    AvalibleResolutions = new List <TerrainCardinalResolution>()
                    {
                        TerrainCardinalResolution.MAX_RESOLUTION
                    },
                    Rank = 10
                });
            }

            return(toReturn);
        }
Пример #26
0
        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
                                );
            });
        }