public void Start() { var heightmapTextureSize = new IntVector2(3600, 3600); var rgbaMainTexture = SavingFileManager.LoadPngTextureFromFile(_filePathsConfiguration.HeightmapFilePath, heightmapTextureSize.X, heightmapTextureSize.Y, TextureFormat.ARGB32, true, false); TerrainTextureFormatTransformator transformator = new TerrainTextureFormatTransformator(_gameInitializationFields.Retrive <CommonExecutorUTProxy>()); var globalHeightTexture = transformator.EncodedHeightTextureToPlain(new TextureWithSize() { Size = heightmapTextureSize, Texture = rgbaMainTexture }); if (true) { _gameInitializationFields.SetField(new TerrainDetailAlignmentCalculator(240)); TerrainDetailGenerator terrainDetailGenerator = CreateTerrainDetailGenerator( globalHeightTexture, _gameInitializationFields.Retrive <UTTextureRendererProxy>(), _gameInitializationFields.Retrive <CommonExecutorUTProxy>(), _gameInitializationFields.Retrive <UnityThreadComputeShaderExecutorObject>(), _gameInitializationFields.Retrive <ComputeShaderContainerGameObject>()); var commonExecutorUtProxy = _gameInitializationFields.Retrive <CommonExecutorUTProxy>(); TerrainDetailProvider terrainDetailProvider = CreateTerrainDetailProvider(terrainDetailGenerator, commonExecutorUtProxy); var terrainDetailFileManager = new TerrainDetailFileManager(_configuration.TerrainDetailCachePath, commonExecutorUtProxy); var terrainShapeDb = CreateTerrainShapeDb(terrainDetailProvider , commonExecutorUtProxy , _gameInitializationFields.Retrive <TerrainDetailAlignmentCalculator>() , _configuration.TerrainShapeDbConfiguration.MergeTerrainDetail , _configuration.TerrainShapeDbConfiguration.UseTextureSavingToDisk , _configuration.TerrainShapeDbConfiguration.UseTextureLoadingFromDisk, terrainDetailFileManager); TerrainShapeDbProxy terrainShapeDbProxy = new TerrainShapeDbProxy(terrainShapeDb); var baseTerrainDetailProvider = BaseTerrainDetailProvider.CreateFrom(terrainShapeDb); _gameInitializationFields.SetField(baseTerrainDetailProvider); terrainDetailGenerator.SetBaseTerrainDetailProvider(baseTerrainDetailProvider); _ultraUpdatableContainer.AddOtherThreadProxy(terrainShapeDbProxy); _gameInitializationFields.SetField(terrainShapeDbProxy); } else { ITerrainShapeDb terrainShapeDbProxy = new DebugSlopedTerrainShapeDb( _gameInitializationFields.Retrive <UTTextureRendererProxy>() ); terrainShapeDbProxy = new RecordingTerrainShapeDb(terrainShapeDbProxy); _gameInitializationFields.SetField((RecordingTerrainShapeDb)terrainShapeDbProxy); } }
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 static Texture BaseCreateHeightTexture(Func <int, int, float> heightResolver) { var traditionalHeightMap = new Texture2D(241, 241, TextureFormat.ARGB32, true); for (int x = 0; x < 241; x++) { for (int y = 0; y < 241; y++) { float height = heightResolver(x, y); traditionalHeightMap.SetPixel(x, y, HeightColorTransform.EncodeHeight(height)); } } traditionalHeightMap.Apply(true); var transformator = new TerrainTextureFormatTransformator(new CommonExecutorUTProxy()); return(transformator.EncodedHeightTextureToPlain(new TextureWithSize() { Texture = traditionalHeightMap, Size = new IntVector2(241, 241) })); }
public static UpdatedTerrainTextures GenerateDebugUpdatedTerrainTextures() { var height = 1; var heightArray = new float[12, 12]; for (int x = 0; x < 12; x++) { for (int y = 0; y < 12; y++) { heightArray[x, y] = height; } } var ha = new HeightmapArray(heightArray); var encodedHeightTex = HeightmapUtils.CreateTextureFromHeightmap(ha); var transformer = new TerrainTextureFormatTransformator(new CommonExecutorUTProxy()); var plainHeightTex = transformer.EncodedHeightTextureToPlain(TextureWithSize.FromTex2D(encodedHeightTex)); var normalArray = new Vector3[12, 12]; for (int x = 0; x < 12; x++) { for (int y = 0; y < 12; y++) { normalArray[x, y] = new Vector3(0.0f, 0.0f, 1.0f).normalized; } } var normalTexture = HeightmapUtils.CreateNormalTexture(normalArray); return(new UpdatedTerrainTextures() { HeightTexture = plainHeightTex, NormalTexture = normalTexture, TextureCoords = new MyRectangle(0, 0, 1, 1), TextureGlobalPosition = new MyRectangle(0, 0, 90, 90), }); }