- Home /
Smoothing Terrain after setting its Heightmap in a script
I have a terrain and I manually set the heightmap of it in a script at runtime. It is a little blocky (I cannot get more detailed heightmap data). I notice that I can smooth the map using the unity editor, and that this smoothness is of a higher resolution than the terrain heightmap (or at least a higher resolution than I have control over using the terrain.terrainData).
So it currently looks like this:
but I want it to look like this
which is what happens when I do a quick smooth brush on the terrain in the unity editor whilst the game is running.
I have to reload the heightmap data from a file every time the game runs and there is no way for me to smooth the terrain and export it from unity and then reload it (I could, but I'm using real world height data so I don't want to smooth the entire world's heightmap! :p)
Is there no way I can smooth the terrain's heightmap data from a script in a similar way to the way unity's terrain editor can? I don't understand enough about the terrain's inner working, nor any way to edit them to do this currently. It should be possible for me to smooth the heightmap at runtime using a similar gaussian blur of some form in a script, shouldn't it?
Any help would be greatly appriciated, many thanks.
I am also having the same issue! Were you able to find a solution?
Ins$$anonymous$$d of smoothing the terrain, for which there is no easy way, you have to do it yourself (script or otherwise), I suggest you take your heightmap, scale it up so it matches the terrain, and then smooth that out, which is much easier
I wasn't able to, there seems to be no way to smooth terrains that you initially set in runtime. However if I had to approach it again, I'd probably build my own mesh from scratch and smooth that. Or as benproductions suggests, set the height in groups of 4 (2x2) or 9 (3x3) and smooth that, but then you might as well investigate making a mesh (which was too hectic for me when I first wrote the post but with a bit of effort they aren't that scary now :p)
Your answer
Follow this Question
Related Questions
Export terrain from Cinema4d to Unity3d 1 Answer
How to use Height Maps 2 Answers
Edit Terrain Script 0 Answers
Randomized terrain? 0 Answers
Stitching grid of terrains together 1 Answer