public void ErodeOneStep() { var currentHeightArray = SimpleHeightArray.FromHeightmap(_currentHeightmap); var eroder = new ThermalEroder(); var extremes = new ArrayExtremes(1517, 6161); var tParam = CalculateFromHillFactor(1, extremes, 24); Debug.Log("TPAN IS " + tParam); eroder.Erode(currentHeightArray, new ThermalErosionConfiguration() { StepCount = 5, CParam = 0.3f, TParam = tParam }); var doneTexture = HeightmapUtils.CreateTextureFromHeightmap( SimpleHeightArray.ToHeightmap(currentHeightArray)); //_go.GetComponent<MeshRenderer>().material.SetTexture("_HeightmapTex0", _oldDoneTexture); _go.GetComponent <MeshRenderer>().material.SetTexture("_HeightmapTex1", doneTexture); _oldDoneTexture = doneTexture; }
public void Start() { //var heightTexture = SavingFileManager.LoadPngTextureFromFile(@"C:\inz\cont\smallCut.png", 240, // 240, TextureFormat.RGBA32, true, true); //_currentHeightmap = HeightmapUtils.CreateHeightmapArrayFromTexture(heightTexture); DiamondSquareCreator creator = new DiamondSquareCreator(new RandomProvider(22)); _currentHeightmap = creator.CreateDiamondSquareNoiseArray(new IntVector2(240, 240), 64); MyArrayUtils.Multiply(_currentHeightmap.HeightmapAsArray, 0.1f); _go = GameObject.CreatePrimitive(PrimitiveType.Quad); var material = new Material(Shader.Find("Custom/Terrain/Terrain_Debug")); _go.GetComponent <MeshRenderer>().material = material; _go.name = "Terrain"; _go.transform.localRotation = Quaternion.Euler(0, 0, 0); _go.transform.localScale = new Vector3(10, 10, 10); _go.transform.localPosition = new Vector3(0, 0, 0); _go.GetComponent <MeshFilter>().mesh = PlaneGenerator.CreateFlatPlaneMesh(240, 240); var doneTexture = HeightmapUtils.CreateTextureFromHeightmap(_currentHeightmap); _go.GetComponent <MeshRenderer>().material.SetTexture("_HeightmapTex0", doneTexture); _go.GetComponent <MeshRenderer>().material.SetTexture("_HeightmapTex1", doneTexture); _oldDoneTexture = doneTexture; }
private TextureWithSize CreateBaseTexture(float height, DebugTerrainCharacter character) { if (character == DebugTerrainCharacter.Noise) { var texture = new RenderTexture(241, 241, 0, RenderTextureFormat.RFloat); texture.wrapMode = TextureWrapMode.Clamp; texture.filterMode = FilterMode.Point; var material = new Material(Shader.Find("Custom/Tool/FillHeightTextureWithRandomValues")); material.SetTexture("_HeightTexture", texture); Graphics.Blit(texture, (RenderTexture)texture, material); return(new TextureWithSize() { Texture = texture, Size = new IntVector2(241, 241) }); } else { float[,] heightArray; if (character == DebugTerrainCharacter.Flat) { heightArray = MyArrayUtils.CreateFilled(241, 241, height); } else //if (character == DebugTerrainCharacter.Volcano) { heightArray = new float[241, 241]; float minHeight = height * 0.2f; float maxHeight = height; for (int x = 0; x < 241; x++) { for (int y = 0; y < 241; y++) { heightArray[x, y] = Mathf.Lerp(minHeight, maxHeight, 1 - Vector2.Distance(new Vector2(x, y), new Vector2(120, 120)) / 200f); } } } var heightTex = HeightmapUtils.CreateTextureFromHeightmap(new HeightmapArray(heightArray)); var transformator = new TerrainTextureFormatTransformator(new CommonExecutorUTProxy()); var plainHeightTexture = transformator.EncodedHeightTextureToPlain(new TextureWithSize() { Size = new IntVector2(241, 241), Texture = heightTex }); plainHeightTexture.wrapMode = TextureWrapMode.Clamp; return(new TextureWithSize() { Size = new IntVector2(241, 241), Texture = plainHeightTexture }); } }
public async Task <TextureWithCoords> ApplyFeatureAsync(TextureWithCoords texture, TerrainCardinalResolution resolution, bool canMultistep) { var configuration = _configurations[resolution]; var detailedHeightmapArray = await TaskUtils .RunInThreadPool( () => { var creator = new DiamondSquareCreator(_randomProviderGenerator.GetRandom()); var initialArray = creator.CreateDiamondSquareNoiseArray( texture.TextureSize, configuration.DiamondSquareWorkingArrayLength); return(initialArray); }); var detailedTexture = await _commonExecutor .AddAction(() => HeightmapUtils.CreateTextureFromHeightmap(detailedHeightmapArray)); UniformsPack pack = new UniformsPack(); pack.SetTexture("_Texture1", texture.Texture); pack.SetTexture("_Texture2", detailedTexture); pack.SetUniform("_Texture2Weight", configuration.DiamondSquareWeight); var renderCoords = new MyRectangle(0, 0, 1, 1); var outTextureSize = texture.TextureSize; ConventionalTextureInfo outTextureInfo = new ConventionalTextureInfo(outTextureSize.X, outTextureSize.Y, TextureFormat.ARGB32, true); TextureRenderingTemplate template = new TextureRenderingTemplate() { CanMultistep = canMultistep, Coords = renderCoords, OutTextureInfo = outTextureInfo, RenderTextureFormat = RenderTextureFormat.RFloat, ShaderName = "Custom/TerrainCreation/DiamondSquareTextureAddingPlain", UniformPack = pack, CreateTexture2D = false }; var renderedTexture = await _rendererProxy.AddOrder(template); await _commonExecutor.AddAction(() => GameObject.Destroy(detailedTexture)); return(new TextureWithCoords(sizedTexture: new TextureWithSize() { Texture = renderedTexture, Size = texture.TextureSize }, coords: texture.Coords)); }
public HeightmapArray CreateRing1HeightmapArray(HeightmapArray inputHeightmap) { assertInputHeightmapHasProperSize(inputHeightmap); var inputTexture = HeightmapUtils.CreateTextureFromHeightmap(inputHeightmap); // input texture is 256x256 (5.7x5.7) p22.3m var conventionalRing1Texture = RenderConventionalRing1Texture(inputTexture, new UniformsPack()); var heightmapArray = HeightmapUtils.CreateHeightmapArrayFromTexture(conventionalRing1Texture); DiamondSquareCreator diamondSquareCreator = new DiamondSquareCreator(new RandomProvider()); heightmapArray = diamondSquareCreator.AddDetail(heightmapArray); return(heightmapArray); }
public void Start231() { string bilFilePath = @"C:\inz\cont\n49_e019_1arc_v3.bil"; HeightmapFile heightmapFile = new HeightmapFile(); const int filePixelWidth = 3601; heightmapFile.LoadFile(bilFilePath, 3601); heightmapFile.MirrorReflectHeightDataInXAxis(); var heightArray = heightmapFile.GlobalHeightArray; var smallArray = HeightmapUtils.CutSubArray(heightArray, new IntArea(100, 100, 240, 240)); SavingFileManager.SaveTextureToPngFile(@"C:\inz\cont\smallCut.png", HeightmapUtils.CreateTextureFromHeightmap(smallArray)); }
private void CreateComparisionObject() { _go = GameObject.CreatePrimitive(PrimitiveType.Quad); var material = new Material(Shader.Find("Custom/Terrain/Terrain_Debug")); _go.GetComponent <MeshRenderer>().material = material; _go.name = "Terrain"; _go.transform.localRotation = Quaternion.Euler(0, 0, 0); _go.transform.localScale = new Vector3(10, 1, 10); _go.transform.localPosition = new Vector3(0, 0, 0); _go.GetComponent <MeshFilter>().mesh = PlaneGenerator.CreateFlatPlaneMesh(240, 240); var doneTexture = HeightmapUtils.CreateTextureFromHeightmap(_currentHeightmap); _go.GetComponent <MeshRenderer>().material.SetTexture("_HeightmapTex0", doneTexture); _go.GetComponent <MeshRenderer>().material.SetTexture("_HeightmapTex1", doneTexture); }
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), }); }