public HeightArrayWeldingPack(TextureWithSize weldTexture, HeightArrayWelderProxy welderProxy, CommonExecutorUTProxy commonExecutorUtProxy, bool weldingEnabled) { _weldTexture = weldTexture; _welderProxy = welderProxy; _commonExecutorUtProxy = commonExecutorUtProxy; _weldingEnabled = weldingEnabled; }
public EPropElevationManager(CommonExecutorUTProxy commonExecutor, UnityThreadComputeShaderExecutorObject shaderExecutorObject, EPropElevationConfiguration configuration, EPropConstantPyramidParameters constantPyramidParameters) { _configuration = configuration; _localeBufferManager = new EPropLocaleBufferManager(commonExecutor, shaderExecutorObject, configuration, constantPyramidParameters); _pointersOccupancyContainer = new EPropElevationLocalePointersOccupancyContainer(configuration); }
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); }
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); }
public RandomNoiseTerrainFeatureApplier(UTTextureRendererProxy rendererProxy, CommonExecutorUTProxy commonExecutor, Dictionary <TerrainCardinalResolution, RandomNoiseTerrainFeatureApplierConfiguration> configurations) { _rendererProxy = rendererProxy; _commonExecutor = commonExecutor; _configurations = configurations; }
public void Start(ComputeShaderContainerGameObject computeShaderContainer) { var commonExecutor = new CommonExecutorUTProxy(); var shaderExecutorObject = new UnityThreadComputeShaderExecutorObject(); var updater = new DesignBodySpotUpdater(new DesignBodySpotChangeCalculator(computeShaderContainer, shaderExecutorObject, commonExecutor, HeightDenormalizer.Identity)); _designBodySpotUpdaterProxy = new DesignBodySpotUpdaterProxy(updater); updater.SetChangesListener(new LambdaSpotPositionChangesListener(null, dict => { foreach (var pair in dict) { _grassGroupsPlanter.GrassGroupSpotChanged(pair.Key, pair.Value); } })); _designBodySpotUpdaterProxy.StartThreading(() => { }); var meshGenerator = new GrassMeshGenerator(); var mesh = meshGenerator.GetGrassBladeMesh(1); var instancingMaterial = new Material(Shader.Find("Custom/Vegetation/Grass.Instanced")); instancingMaterial.enableInstancing = true; var commonUniforms = new UniformsPack(); commonUniforms.SetUniform("_BendingStrength", 0.0f); commonUniforms.SetUniform("_WindDirection", Vector4.one); var instancingContainer = new GpuInstancingVegetationSubjectContainer( new GpuInstancerCommonData(mesh, instancingMaterial, commonUniforms), new GpuInstancingUniformsArrayTemplate(new List <GpuInstancingUniformTemplate>() { new GpuInstancingUniformTemplate("_Color", GpuInstancingUniformType.Vector4), new GpuInstancingUniformTemplate("_InitialBendingValue", GpuInstancingUniformType.Float), new GpuInstancingUniformTemplate("_PlantBendingStiffness", GpuInstancingUniformType.Float), new GpuInstancingUniformTemplate("_PlantDirection", GpuInstancingUniformType.Vector4), new GpuInstancingUniformTemplate("_RandSeed", GpuInstancingUniformType.Float), }) ); _globalGpuInstancingContainer = new GlobalGpuInstancingContainer(); var bucketId = _globalGpuInstancingContainer.CreateBucket(instancingContainer); GrassGroupsContainer grassGroupsContainer = new GrassGroupsContainer(_globalGpuInstancingContainer, bucketId); IGrassPositionResolver grassPositionResolver = new SimpleRandomSamplerPositionResolver(); GrassDetailInstancer grassDetailInstancer = new GrassDetailInstancer(); _grassGroupsPlanter = new GrassGroupsPlanter( grassDetailInstancer, grassPositionResolver, grassGroupsContainer, _designBodySpotUpdaterProxy, new LegacyGrass2BladeAspectsGenerator(), GrassDebugUtils.TemplatesDictionary, Repositioner.Identity); }
public ESurfacePatchProvider(GRing2PatchesCreatorProxy patchesCreator, Ring2PatchStamplingOverseerFinalizer patchStamper, CommonExecutorUTProxy commonExecutor, MipmapExtractor mipmapExtractor, int mipmapLevelToExtract) { _patchesCreator = patchesCreator; _patchStamper = patchStamper; _commonExecutor = commonExecutor; _mipmapExtractor = mipmapExtractor; _mipmapLevelToExtract = mipmapLevelToExtract; }
public EPropLocaleBufferManager(CommonExecutorUTProxy commonExecutor, UnityThreadComputeShaderExecutorObject shaderExecutorObject, EPropElevationConfiguration configuration , EPropConstantPyramidParameters constantPyramidParameters) { _shaderExecutorObject = shaderExecutorObject; _configuration = configuration; _commonExecutor = commonExecutor; _constantPyramidParameters = constantPyramidParameters; _scopes = new EPropLocaleBufferScopeRegistry[configuration.MaxScopesCount]; }
public HabitatToGrassIntensityMapGenerator(ComputeShaderContainerGameObject computeShaderContainer, UnityThreadComputeShaderExecutorObject shaderExecutorObject, CommonExecutorUTProxy commonExecutor, HabitatToGrassIntensityMapGeneratorConfiguration configuration) { _computeShaderContainer = computeShaderContainer; _shaderExecutorObject = shaderExecutorObject; _configuration = configuration; _commonExecutor = commonExecutor; }
public DiamondSquareTerrainFeatureApplier(RandomProviderGenerator randomProviderGenerator, CommonExecutorUTProxy commonExecutor, UTTextureRendererProxy rendererProxy, Dictionary <TerrainCardinalResolution, DiamondSquareTerrainFeatureApplierConfiguration> configurations) { _randomProviderGenerator = randomProviderGenerator; _commonExecutor = commonExecutor; _rendererProxy = rendererProxy; _configurations = configurations; }
public ThermalErosionTerrainFeatureApplier(ComputeShaderContainerGameObject computeShaderContainer, UnityThreadComputeShaderExecutorObject shaderExecutorObject, CommonExecutorUTProxy commonExecutor, Dictionary <TerrainCardinalResolution, ThermalErosionTerrainFeatureApplierConfiguration> configurations) { _computeShaderContainer = computeShaderContainer; _shaderExecutorObject = shaderExecutorObject; _commonExecutor = commonExecutor; _configurations = configurations; }
public void Compute() { CommonExecutorUTProxy commonExecutor = new CommonExecutorUTProxy(); HabitatMapDbProxy habitatMapDbProxy = _gameInitializationFields.Retrive <HabitatMapDbProxy>(); ComputeShaderContainerGameObject computeShaderContainer = _gameInitializationFields.Retrive <ComputeShaderContainerGameObject>(); UnityThreadComputeShaderExecutorObject shaderExecutorObject = _gameInitializationFields.Retrive <UnityThreadComputeShaderExecutorObject>(); var templatesDict = _vegetationConfiguration.FloraDomainCreationTemplates; var floraConfiguration = _vegetationConfiguration.FloraConfiguration; var spatialDbConfiguration = _vegetationConfiguration.FloraDomainSpatialDbConfiguration; var dbsDict = new Dictionary <HabitatAndZoneType, ISpatialDb <FloraDomainIntensityArea> >(); foreach (var pair in templatesDict) { IStoredPartsGenerator <FloraDomainIntensityArea> partsGenerator = new FloraDomainIntensityGenerator(pair.Value, computeShaderContainer, shaderExecutorObject, commonExecutor, 1f, floraConfiguration); var spatialDb = new CacheingSpatialDb <FloraDomainIntensityArea>( new SpatialDb <FloraDomainIntensityArea>(partsGenerator, spatialDbConfiguration), spatialDbConfiguration); dbsDict[pair.Key] = spatialDb; } var floraDomainDb = new FloraDomainDbProxy(dbsDict); var biomeProvidersGenerators = _vegetationConfiguration.BiomeConfigurationsDict(floraDomainDb) .ToDictionary(c => c.Key, c => new BiomeProvidersFromHabitatGenerator(habitatMapDbProxy, c.Value)); var genralPlacer = new GeneralMultiDistrictPlacer( _vegetationConfiguration.GeneralMultiDistrictPlacerConfiguration, _gameInitializationFields.Retrive <TerrainShapeDbProxy>(), commonExecutor, biomeProvidersGenerators); var database = genralPlacer.Generate( _vegetationConfiguration.GenerationArea, _vegetationConfiguration.RankDependentSpeciesCharacteristics(), _vegetationConfiguration.GenerationCenter); var vegetationOnRoadRemover = new VegetationOnRoadRemover( _gameInitializationFields.Retrive <RoadDatabaseProxy>(), _vegetationConfiguration.VegetationOnRoadRemoverConfiguration ); var newDb = vegetationOnRoadRemover.RemoveCollidingTrees(database, _vegetationConfiguration.GenerationArea); //CreateDebugObjects(newDb.Subjects.ToDictionary(c => c.Key, c => c.Value.QueryAll())); VegetationDatabaseFileUtils.WriteToFileNonOverwrite( _pathsConfiguration.LoadingVegetationDatabaseDictionaryPath, newDb); }
public TerrainDetailGenerator(TerrainDetailGeneratorConfiguration configuration, UTTextureRendererProxy rendererProxy, TextureWithCoords fullFundationTextureData, List <RankedTerrainFeatureApplier> featureAppliers, CommonExecutorUTProxy commonExecutor) { _configuration = configuration; _rendererProxy = rendererProxy; _fullFundationTextureData = fullFundationTextureData; _featureAppliers = featureAppliers; _commonExecutor = commonExecutor; }
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; }
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; }
public HeightArrayDb(TerrainShapeDbProxy terrainShapeDb, CommonExecutorUTProxy commonExecutor) { TerrainTextureFormatTransformator transformator = new TerrainTextureFormatTransformator(commonExecutor); foreach (var resolution in TerrainCardinalResolution.AllResolutions) { SpatialDbConfiguration configuration = new SpatialDbConfiguration() { QueryingCellSize = VectorUtils.FillVector2(TerrainDescriptionConstants.DetailCellSizesPerResolution[resolution]) }; IStoredPartsGenerator <MySimpleArray <float> > partsGenerator = new HeightArrayGenerator(terrainShapeDb, transformator, resolution); _resolutionDbs[resolution] = new SpatialDb <MySimpleArray <float> >(partsGenerator, configuration); } }
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 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); }
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); }
public void Start(ComputeShaderContainerGameObject computeShaderContainer) { var commonExecutor = new CommonExecutorUTProxy(); var shaderExecutorObject = new UnityThreadComputeShaderExecutorObject(); var updater = new DesignBodySpotUpdater(new DesignBodySpotChangeCalculator(computeShaderContainer, shaderExecutorObject, commonExecutor, HeightDenormalizer.Identity)); _designBodySpotUpdaterProxy = new DesignBodySpotUpdaterProxy(updater); updater.SetChangesListener(new LambdaSpotPositionChangesListener(null, dict => { foreach (var pair in dict) { _grassGroupsPlanter.GrassGroupSpotChanged(pair.Key, pair.Value); } })); _designBodySpotUpdaterProxy.StartThreading(() => { }); var meshGenerator = new GrassMeshGenerator(); var mesh = meshGenerator.GetGrassBillboardMesh(0, 1); var instancingMaterial = new Material(Shader.Find("Custom/Vegetation/GrassBushBillboard.Instanced")); instancingMaterial.enableInstancing = true; /// CLAN var billboardsFileManger = new Grass2BillboardClanFilesManager(); var clan = billboardsFileManger.Load(@"C:\inz\billboards\", new IntVector2(256, 256)); var singleToDuo = new Grass2BakingBillboardClanGenerator(computeShaderContainer, shaderExecutorObject); var bakedClan = singleToDuo.GenerateBakedAsync(clan).Result; /// var commonUniforms = new UniformsPack(); commonUniforms.SetUniform("_BendingStrength", 0.0f); commonUniforms.SetUniform("_WindDirection", Vector4.one); commonUniforms.SetTexture("_DetailTex", bakedClan.DetailTextureArray); commonUniforms.SetTexture("_BladeSeedTex", bakedClan.BladeSeedTextureArray); var instancingContainer = new GpuInstancingVegetationSubjectContainer( new GpuInstancerCommonData(mesh, instancingMaterial, commonUniforms), new GpuInstancingUniformsArrayTemplate(new List <GpuInstancingUniformTemplate>() { new GpuInstancingUniformTemplate("_Color", GpuInstancingUniformType.Vector4), new GpuInstancingUniformTemplate("_InitialBendingValue", GpuInstancingUniformType.Float), new GpuInstancingUniformTemplate("_PlantBendingStiffness", GpuInstancingUniformType.Float), new GpuInstancingUniformTemplate("_PlantDirection", GpuInstancingUniformType.Vector4), new GpuInstancingUniformTemplate("_RandSeed", GpuInstancingUniformType.Float), new GpuInstancingUniformTemplate("_ArrayTextureIndex", GpuInstancingUniformType.Float), }) ); _globalGpuInstancingContainer = new GlobalGpuInstancingContainer(); var bucketId = _globalGpuInstancingContainer.CreateBucket(instancingContainer); GrassGroupsContainer grassGroupsContainer = new GrassGroupsContainer(_globalGpuInstancingContainer, bucketId); IGrassPositionResolver grassPositionResolver = new PoissonDiskSamplerPositionResolver(new MyRange(1.5f * 0.4f * 10, 10 * 2 * 1.3f)); //IGrassPositionResolver grassPositionResolver = new SimpleRandomSamplerPositionResolver(); GrassDetailInstancer grassDetailInstancer = new GrassDetailInstancer(); _grassGroupsPlanter = new GrassGroupsPlanter( grassDetailInstancer, grassPositionResolver, grassGroupsContainer, _designBodySpotUpdaterProxy, new Grass2BushAspectsGenerator(bakedClan), //todo! GrassDebugUtils.BushTemplates, Repositioner.Identity); }
public ESurfaceTexturesPackFileManager(CommonExecutorUTProxy commonExecutor, string mainDictionaryPath) { _commonExecutor = commonExecutor; _mainDictionaryPath = mainDictionaryPath; }
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); }
public TextureWithSizeActionsPerformer(CommonExecutorUTProxy commonExecutor) { _commonExecutor = commonExecutor; }
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 ); }); }
// Use this for initialization void Start() { _updatableContainer = new UpdatableContainer(); TaskUtils.SetGlobalMultithreading(true); int minSubmapWidth = 256; //(int)Math.Floor((double)filePixelWidth/subTerrainCount)-1 ; var ring1Array = SavingFileManager.LoadFromFile("map.dat", 2048, 2048); ring1Array = BasicHeightmapModifier.Multiply(1000, ring1Array); _ring1Tree = new Ring1Tree(); ////////////////// var tessalationRequirementTextureGenerator = new TessalationRequirementTextureGenerator(); var tessalationReqTexture = tessalationRequirementTextureGenerator.GenerateTessalationRequirementTexture(ring1Array, 64); var heightmapBundle = SavingFileManager.LoadHeightmapBundlesFromFiles("heightmapBundle", 4, 2048); var submapTextures = new Ring1SubmapTextures(heightmapBundle, tessalationReqTexture); /// /// 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(256, 256)); 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()); } } }); var commonExecutor = new CommonExecutorUTProxy(); _updatableContainer.AddUpdatableElement(commonExecutor); TerrainShapeDbProxy terrainShapeDbProxy = new TerrainShapeDbProxy( FETerrainShapeDbInitialization.CreateTerrainShapeDb(null /*todo here*/, commonExecutor, new TerrainDetailAlignmentCalculator(240), false, false, false, null)); _otherThreadActionPairs.Add(new OtherThreadProxyAndActionPair() { Proxy = terrainShapeDbProxy }); var meshGeneratorProxy = new MeshGeneratorUTProxy(new MeshGeneratorService()); _updatableContainer.AddUpdatableElement(meshGeneratorProxy); //var eventCollector = new Ring1NodeEventCollector((node) => // new Ring1NodeDirectHeightTerrain( // node, // visibilityTextureChangeGrabber, // visibilityTexture, // terrainParentGameObject, // unityCoordsCalculator, // orderGrabber, // terrainShapeDbProxy, // ring1Array, // meshGeneratorProxy)); var eventCollector = new Ring1NodeEventCollector(new FromLambdaListenersCreator((node) => new Ring1ListenerToGRingListener( new Ring1NodeShaderHeightTerrain( node, visibilityTextureChangeGrabber, visibilityTexture, terrainParentGameObject, unityCoordsCalculator, orderGrabber, terrainShapeDbProxy, meshGeneratorProxy, null)))); //todo if you want this to work var ring1Proxy = new Ring1TreeProxy(_ring1Tree); _otherThreadActionPairs.Add(new OtherThreadProxyAndActionPair() { Proxy = ring1Proxy, EveryPostAction = () => { if (eventCollector.Any) { mainRespondingProxy.AddOrder(eventCollector.RetriveOrderAndClear()); } } }); StartThreading(); ring1Proxy.CreateHeightmap( new Ring1Tree.RootNodeCreationParameters() { UnityCoordsCalculator = unityCoordsCalculator, NodeListener = eventCollector, PrecisionDistances = Ring1TestDefaults.PrecisionDistances, InitialCameraPosition = Vector3.zero, }); }
private string _extension = ".png"; //TODO to configuration public TerrainDetailFileManager(string mainDictionaryPath, CommonExecutorUTProxy commonExecutor) { _mainDictionaryPath = mainDictionaryPath; _commonExecutor = commonExecutor; }
private TerrainDetailProvider CreateTerrainDetailProvider(TerrainDetailGenerator generator, CommonExecutorUTProxy commonExecutorUtProxy) { var cornerMerger = new TerrainDetailCornerMerger( new LateAssignFactory <BaseTerrainDetailProvider>(() => _gameInitializationFields.Retrive <BaseTerrainDetailProvider>()), _gameInitializationFields.Retrive <TerrainDetailAlignmentCalculator>(), _gameInitializationFields.Retrive <UTTextureRendererProxy>(), _gameInitializationFields.Retrive <TextureConcieverUTProxy>(), commonExecutorUtProxy, _configuration.TerrainMergerConfiguration); var provider = new TerrainDetailProvider(generator, cornerMerger, _gameInitializationFields.Retrive <TerrainDetailAlignmentCalculator>()); return(provider); }
public TerrainTextureFormatTransformator(CommonExecutorUTProxy commonExecutor) { _commonExecutor = commonExecutor; }
// 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 static TerrainShapeDb CreateTerrainShapeDb(TerrainDetailProvider terrainDetailProvider, CommonExecutorUTProxy commonExecutorUtProxy, TerrainDetailAlignmentCalculator terrainDetailAlignmentCalculator, bool mergingEnabled, bool saveTexturesToFile, bool loadTexturesFromFile, TerrainDetailFileManager fileManager) { var cachingConfiguration = new CachingConfiguration() { SaveAssetsToFile = saveTexturesToFile, UseFileCaching = loadTexturesFromFile }; Func <IAssetsCache <InternalTerrainDetailElementToken, TextureWithSize> > terrainCacheGenerator = () => new InMemoryAssetsCache <InternalTerrainDetailElementToken, TextureWithSize>( CreateLevel2AssetsCache <InternalTerrainDetailElementToken, TextureWithSize>( cachingConfiguration, new InMemoryCacheConfiguration(), new TextureWithSizeActionsPerformer(commonExecutorUtProxy), new CachingTerrainDetailFileManager(fileManager))); var cachedTerrainDetailProvider = new CachedTerrainDetailProvider( terrainDetailProvider, terrainCacheGenerator, mergingEnabled); cachedTerrainDetailProvider.Initialize().Wait(); var terrainShapeDb = new TerrainShapeDb(cachedTerrainDetailProvider, terrainDetailAlignmentCalculator); return(terrainShapeDb); }