Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Terrain Feature Requests for Terrain

Discussion in 'World Building' started by UlfvonEschlauer, Apr 30, 2020.

  1. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    After having worked quite extensively with the terrain tools in Unity, here are a few feature requests that if implemented would have made my life a lot easier:

    1. Mesh Stamp: I often build my levels elsewhere to get certain things like roads especially on incline exactly right (they need to be perfectly even for my game but then I want to bring them into unity to make use of the texture paint, tree placement, etc.
    • Right now the size of the Mesh Stamp depends on the brush size. It would be great to have an override to use the exact mesh dimensions (and the same for the height). Right now I have to fiddle with this until I get it just right.
    • If the mesh has a texture, it would be great to (optionally) have that texture added as a Texture Layer to the terrain and painted when the mesh is stamped. Another great option would be to have gray scale texture on that Mesh act as a layer mask for a certain texture layer.
    2. Tree placement:
    • Mass Place: It would be great if this had more parameters. E.g. have the amount and size of trees placed differ by the slope of the terrain (more slope means less and smaller trees, e.g.) and the altitude (higher altitude means less trees).
      Also allow terrain texture layers as masks for trees, so the mass placement won't place trees on roads.
      The Mass place algorithm should also respect the density value of the brush. Currently I often see trees placed almost on top of each other (which looks bad and is unrealistic), when in other places large sections of the terrain can be completely void of any trees.
    • When manually placing trees, it would be very useful to place several types of trees at once. Just allow multi- selection for the tree type. A slope modifier for the tree size and density would be great for this too.
    • Tree rendering: The shadows of trees should fade out with the tree. Right now, the pop in and out when a tree switches to billboard. Better even would be a way to preserve the shadows of the trees when they switch to billboard (at least some kind of representation of them). The last part is a huge deal, at least for me.
    3. Paint details:
    • A mass placement for details with slope/altitude modifiers described in the Tree placement section would be very useful.
    • Also needs multi select and slope/altitude modifiers for manual placement as outlined above.
    4. Paint Texture:
    • Slope and altitude modifier as outlined for tree placement and detail placement would be awesome. E.g. I would want to do some quick basic terrain texture painting, where rocks are only painted in spots with more slope and grass is only painted in areas with less slope.
    • This would be even better if these types of modifiers worked with multiple layer selections in some way.
      E.g. if I had 3 layers selected. One for rock, one for grass and one for the transition in between and each can have a range of slope and altitude applied to it, maybe even with a slight jitter/noise variation if the ranges overlap a bit. With that I could texture paint an entire terrain with a single brush stroke before working on details.
    • A diffuse color modifier for Terrain texture layers like we have for the Albedo in the standard shader would be great. This could provide for a quick fix when two texture layers used on a terrain do not blend/transition well. Right now, I have to go and edit the color texture in an external program every time in want to reuse it in a different context. This also means clones of the same texture with slightly different hue/brightness.

    5. Crop/extend terrain:
    • It would be great, if we could crop and extend terrains without effectively destroying what is there. I know this is complicated because the textures have to be resampled or extended in size. So this is would not be a priority.
    6. Terrain mesh.
    • Right now, textures tend to stretch a lot in sloped areas.It would be great if the terrain mesh could be "relaxed" in a way to prevent that. Not sure of this is possible with the way terrain meshes are generated right now and I hope I was able explain this properly.
    • Stencil/clipmap for making holes into terrain. I presume that this could be done with some sort of shader trick. Essentially have a transparency setting in the Layer. This is useful for making things like tunnels/mines, etc, where the tunnel would be a separate (manually modeled) mesh that would be placed to fill in the "hole" left by the clip map. Alternatively some sort of boolean with a mesh/primitive could work too. Of course the collision with the terrain would somehow have to be deactivated at that spot as well.
    Hope I was able to describe everything in an understandable way.
    Thanks!
     
    Last edited: May 22, 2020
    banan1234, Gokcan and wyattt_ like this.
  2. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    330
    Thanks for the feedback! I'll go ahead and track these on our end in case we end up working on these
     
  3. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    Thanks for the response and thanks a ton for considering my suggestions! I am looking forward to seeing how the terrain tools will develop in the future!
     
  4. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    Adding more to this thread:
    Trees, trees, trees...
    It would be wonderful if Unity offered some good quality pre- made mesh tree assets, ready for use with the Terrain in various resolutions with pre- made billboards/LODs. There are some free ones available in the Asset Store, but they do require a lot of work (usually the leaves textures have too strong highlights in them). Some are also fairly high poly. Making your own trees is a lot of work for a single indie developer like me. So having a library of good trees to work with would be godsend.
     
  5. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    276
    Regards the texture stretching or 'relaxing' idea you are probably looking for triplanar mapping. I personally use the excellent and very inexpensive microsplat asset for this.
     
    UlfvonEschlauer likes this.
  6. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    Here is another feature request regarding trees: The ability to define regions (or maybe even individual trees) as "hero"- trees. Those would be trees (or regions of trees) that always remain as meshes, no matter the settings for the rest of the trees on the terrain. In my current project, I have a very dense forest, but it is mainly in the background. The actual action happens in a clearing. Now for the trees closest to the tree line, it would be great to have them remain meshes all the time. The rest (the ones behind them, deeper in the forest) I would just have as billboards for performance reasons.
    Certainly, I could just go and replace those trees in question with mesh trees by hand, but it is a lot of extra work, especially for a long and complex tree line. Hope that one makes sense...
     
  7. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    I checked it out and it does look interesting. Is there anything I need to watch out for when using it with my current Unity terrains? Will I have to redo them, or will it just add on? I don't want to break the things I have already working.
     
  8. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    276
    Personally i have found the system easy to use and the author regularly updates and provides excellent support, however your circumstances may be different of course. I would strongly recommend making a full backup of your whole project before installing any third party assets so you can roll back if there is a problem. You could also make a new separate project just to try it out of course.

    The base microsplat package is free so you could try this out at no financial risk although triplanar does cost.

    Good luck with your project!
     
    UlfvonEschlauer likes this.
  9. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    My life would be so much easier, if Unity had shadows for billboard trees. Is there a quick, easy and cheap solution out there for that somewhere?
     
  10. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    276
    Hi. Kind of depends how you define cheap i suppose. I have used vegetation studio and microsplat to bake a shadow mask across a terrain, e.g.

    https://www.awesometech.no/index.php/configure-shadow-mask-with-microsplat/

    This works pretty well i think. Vegetation studio is not exactly cheap by most assets standards (especially the pro version) but it is very good at what it does IMHO
     
  11. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    Thanks for the reply! I have been thinking about getting vegetation studio, but have been hesitant to do so as it is a bit pricey and I am on a tight budget after wasting 50 dollars on Nature Renderer, which unfortunately does not do what I need :(
    Also (and correct me if I am wrong), I need to use their own tools to place trees, rather than being able to re- use the trees I have already placed using Unity's tools. Hope they allow me to do things equally well and precise.
    Also, do I need microsplat to have billboard shadows?
     
  12. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    276
    Hi. Yes i think you would need to use the built in tools of vs to place. Personally i just used auto generation features of vs as i needed a forest and wasn't too concerned about precise placement
     
  13. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    Alright, so I have learned a lot about doing dense forests with Unity in the past days.
    I tried all sorts of things to get good results and I here is what I learned. @wyattt_ and Unity devs please read if you have the time!
    Attached is my result for a lush and dense forest (6500 trees) that goes all the way to the horizon. It runs at near 100 fps on my ~2.5 years old laptop with a GX1060 and looks really great (at least I think so).
    Here is what I did (and learned) after spending many hours fiddling with billboards, materials, etc:
    First I made two sets of prefabs for the same set of tree models. One is static, has no shadows, no GI and pretty much everything set to the lowest level possible. Those are the trees I am using with the Unity terrain system. I mass placed them to get started, then removed and re- added some to get a more even distribution (again the mass distribution ain't that great right now).
    The second set of trees are my "Hero Trees". They have everything turned on. Full shadows, full GI, all the bells and whistles. Otherwise they are identical though. Same materials and all that.
    I hand placed the second set of trees at the transition to the actual area where the player is going to spend most of his time. It did not quite take as long as I originally thought it would. But with larger scenarios, this may differ.
    Then I created a terrain texture Layer that looks like foliage with shadows in it. For Unity's terrain this has to be very dark. I am not sure whether that is because of my scene setup or something I am doing wrong with the reflection probes (which do affect the terrain for some reason), but even really dark texture layers will look much brighter on the terrain. I added a pretty strong bump map to simulate random shadows dropped onto the ground. Without that it would simply be too bright. This texture layer covers the ground under all the terrain system trees (all of those without shadows on them).
    Now I set the Billboard start to about 20% of the terrain width (your actual numbers might differ depending on your scene scale). There is another 5% for fade length. So the transition is very soft. Essentially when the camera is in the center of the terrain (where the action is), the billboards don't start until almost half way to the horizon.
    With all billboards (Billboard Start, Fade Length and Max Mesh Trees set to zero) I will get about 120 FPS. With this I get about 100. From what I can see, the CPU is the most limiting factor here, slightly more than the GPU. I did some tests with the Billboard Start maxed out to the full terrain length and I still get about 45 fps, which is too low, but there may still be some room for optimization with all this (I am still learning).
    In comparison, I get about 50 FPS with terrain trees with shadows and a much closer (10% terrain width) billboard start but the result leaves a lot to be desired. The billboards and shadows visibly "pop in" much too close to the player. This is especially a problem for my type of game, where the player can look down at the terrain from an (almost) top down view at a considerable distance.
    Batches are ~22,000 for trees with shadows and billboards at 10% terrain width vs ~3,000 for my current setup.
    My takeaway is this: Realtime shadows from terrain trees are the biggest performance killer. I don't quite understand why. They should not affect performance that much. I would be perfectly happy with some form of shadow approximation for terrain trees that is persistent. With that, I would not have to place hero trees (at least I don't think so). Note that I have not been able to try lightmaps on the terrain because I keep getting errors whenever I try to bake (I think my machine is running out of memory). So that is not really an option. Just some simple baking of the realtime shadows onto the terrain (even at a relatively low resolution) should work well enough though.
    Then have a setting for the distance at which Unity displays static trees with low res baked shadows vs the nice trees with realtime shadows. I believe that with a nice cross fade, this would look perfect and if the same low res shadows stayed for the billboard trees, the transition to billboards would also be (almost) impossible to notice for the player.
    All that could run even faster than my current setup and look better, while being a lot less work for the developer.
    Hope all that made sense...
    ForestLevel02.jpg
     
    Last edited: May 23, 2020
    jamespaterson likes this.
  14. Cam_Crichton

    Cam_Crichton

    Joined:
    Oct 31, 2019
    Posts:
    6
    if you are looking for a third party solution to all of these issues I can recommend looking into Gaia and Gena from Procedural Worlds. Scattering full biomes across terrains with rules for contextual placement is a breeze. Stamping details into terrain with full control over stamps and how they are applied. Well worth the price.
     
  15. banan1234

    banan1234

    Joined:
    Mar 31, 2018
    Posts:
    87
    Gaia allows for fast creation of the terrain, but sadly at the same time It doesn't allow for creation of the best quality terrain. Manual production is still the best option as far as I know.

    Doesn't terrain tools already allow for that? I mean, the preview package in package manager. Here is an good "tutorial" explaining what I'm talking about.
    https://blogs.unity3d.com/2019/08/1...ainting-with-the-2019-2-terrain-tools-update/

    From what I know the rest of the stuff doesn't exist in new terrain tools, However, they are good ideas.
     
  16. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    You are right, the texture painting has the ability for masking in the preview version, though from what I see, one has to make one for each texture and then still paint each texture separately. It would be much nicer, if I could have a single slope and height curve (or maybe better even a gradient texture) covering all texture layers and then painting them all at once in a single brush stroke, if that makes sense. Also it does not seem to work with trees and detail objects.
     
  17. valarus

    valarus

    Joined:
    Apr 7, 2019
    Posts:
    200
    Would it be possible to make this system agnostic to the pieline we're using?
    Terrain, instancing trees and grass would work with SRP as well with their wind shaders.
     
  18. banan1234

    banan1234

    Joined:
    Mar 31, 2018
    Posts:
    87
    It does work exactly like what you want, you at first set up condition with a curve and other options, then you select which layer you want to paint currently and which conditions you want to have on/off. I have like 7 conditions for my terrain and It does work perfectly. Workflow is rather nice and the tool allows you for creation of really professional stuff.


    Something that I really want are the features unreal engine got lately:

    First one allows for a layer based painting. It works similar to what photoshop offers, you set up a layer, paint inside of it and then you can set up stuff like transparency or even turn It off. I think they are trying to do something like that with their environment system, but no one knows really since there is total radio silence about this project and the future of the terrain tools.


    Second one is about creating new mountains with a different approach. I saw that unreal engine wants to use this tool for transferring images from earth maps (with height map, textures, etc.) and then allow for some manipulation of this map with this tool.
     
    wyattt_ likes this.
  19. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    I understood that. My point was that I want to paint several layers in one stroke with the conditions applied. So say. you have slope gradient (or curve or some other way to set it up). At a slope of 1 you have the rock layer, at a slope of 0.5 you have rocky moss layer and at a slope of 0 you have the grass layer, with smooth transitions between them (and yes the numbers are not realistic but this is just for illustrative purposes). Then you just paint all three layers in a single brush stroke with the textures chosen depending on the underlying geometry. Hope that makes sense now.
     
  20. banan1234

    banan1234

    Joined:
    Mar 31, 2018
    Posts:
    87
    This would be nice, but probably not the easiest thing to implement and there aren't that many cases where you can actually use that feature so probably unity won't do that even though It sounds like a nice, small feature.
     
  21. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    I think it would be very useful to just broadly paint the entire terrain with basic textures. I mean it is essentially what the masking does right now, but it applies it to multiple selections of texture layers in a sense. If that makes sense.
     
    wyattt_ likes this.
  22. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    330
    If you don't mind some programming, you could probably have an automated version of this. I can't remember off the top of my head, but I think you can make FilterStack assets with the TerrainTools package. FilterStack assets are the same assets we use for the procedural masking on painting operations. You could make those on disk, one for each Terrain Layer on the Terrain, probably map those to Terrain Layers via a separate Monobehaviour, and then subscribe to the heightmap changed callback in the TerrainCallbacks API. When the heightmap changes, get the alpha map texture for that same modified region (or with some padding) and apply custom filter stacks for each Terrain Layer attached to the Terrain using the mapped FilterStacks

    If anyone wants to attempt this let me know. I would be glad to provide more info. This isn't a part of our timeline at all for TerrainTools currently

    It's not quite what you were asking for but you at least shouldn't have to jump around in the package code to modify the PaintTextureTool
     
    Last edited: Jun 25, 2020
    UlfvonEschlauer likes this.
  23. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    330
    ^^ Requires an Editor version of 2019.2+ I believe for the TerrainCallback API and then FilterStacks / Brush Filters are in TerrainTools 2.0.0+ and requires at least 2019.2
     
    UlfvonEschlauer likes this.
  24. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,448
    You might as well use MicroSplat Runtime Procedural texturing:

    https://assetstore.unity.com/packages/tools/terrain/microsplat-runtime-procedural-texturing-143039

    I'm not sure if that is possible for a mask though, rather for the entire terrain.
     
  25. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    544
    Realtime shadows are a big issue with a system like this(or any complex rendering), so it would not be unexpected to have it take up a lot of time. Have you tried baking lightmaps for static far shadowing and using distance shadow mask for realtime shadows up close? You could probably set the shadow distance closer and reduce the number shadow cascades to get really good shadow performance. Unfortunately, Unity doesn't have any good solutions for realtime far-shadows like Unreal has(Distance Field shadows)
     
    chanfort likes this.
  26. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    I tried baking lightmaps for the terrain but it was very slow and eventually hang with some error. I believe it might have run out of memory (it is a big terrain and I only have 16GB). So I never figured out what the result would have been. I am not even sure it would have baked the shadows for the trees. I think the overall result is better with shadow-less trees. It is faster to work with too.
     
  27. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    628
    That's a good point. I think shadows for trees needs to be written in a specific way. Majority of trees can be rendered using billboard renderer (capable rendering millions of trees) if setup is correct. Then in shader shadows are usually defined through second pass. So I imagine if billboards rendered to camera would be used to project shadows on terrain, it could be very efficient billboard shadow renderer...
     
  28. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    544
    Can't Unity already render shadows with billboards? Or at least some very low-poly version of a tree at the farthest LOD? The problem is that to render those far away shadows, you need to have a very high Shadow Distance, which means that up-close shadows are going look worse because of lower resolution.
     
  29. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    628
    No, Unity does not render shadows for tree billboards or at least not as I am aware of. That's a good question about shadow quality. I guess it would need to find a balance between desired distance and quality. On large distances I would imagine trees would blend with each other and shadows are more likely to be obscured by trees...
     
  30. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    No, the lack of shadows is obvious even at a great distance. What is most noticeable though is when the shadows are 'popping" in and out of existence.
    The "problem" with rendering shadows for billboards is that the billboards need to be oriented towards the light, not the camera when the shadows are calculated.
     
  31. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    628
    Yeah, I guess distance is a bit tricky to balance in general, not just trees.

    As for rotation, yes, it would be two billboards, one which faces camera and being rendered and another which faces light source and only being rendered as a shadow. Then it should appear correctly.
     
  32. banan1234

    banan1234

    Joined:
    Mar 31, 2018
    Posts:
    87
    Rather than that you can use imposters, which looks better in general and allows you to use 2/3 LOD levels at best even with high quality graphics. Every new, open world game uses this solution and from what I know every engine that treats their 3D stuff seriously have already managed to bundle this solution into the engine, everyone but unity.

    Here is an example of something like that.
    https://github.com/xraxra/IMP

    Also, stuff like the size of the world and thus the distance of shadows in the scene has to be decided before you start making any terrain. If your level does look bad because of that, then you have to redesign some parts of It and then rework the problematic stuff.
     
    chanfort likes this.
  33. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    628
    Hmm, never heard about imposters before. But looks very interesting. Will bookmark the page to try at some point :) . I guess it's a bit similar to billboards except it's more advanced. Now as I know how it's called, I guess will give a try at some point.

    Was just curious before trying, can these imposters be created on runtime, i.e. when generating infinite terrains or dynamically spawning new objects while playing?
     
  34. banan1234

    banan1234

    Joined:
    Mar 31, 2018
    Posts:
    87
    This should be possible, but probably generation will take some time to do. Another thing, impostors are made for already made models/prefabs you would spawn in the generated scene, stuff like trees, rocks, buildings, etc. There are really few situations where the runtime generation of impostors would be useful.
     
    chanfort likes this.
  35. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    628
    Yeah, that sounds great and promising. I would imagine in most cases meshes and textures are ready before runtime. But even if meshes and textures are generated on runtime, it would be quite easy to pass these ones through game objects and materials and generate impostors as well as long as "Editor only" functionality is not used.

    I quickly looked into repo, looks like it's using Editor only functionality for saving prefabs into disk. But billboard baking seems to be based on RenderTexture, which is runtime compatible (I think built in tree billboards also use RenderTexture or something similar internally). So will take a look a bit deeper into this in order to get it baking on runtime. Quite keen to check what are baking times for large number of pre-placed trees.
     
  36. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    628
    So, I just did a bit of exploration on these IMP imposters and they indeed look great. I made some tests repo here https://github.com/chanfort/Imposters-stress-tests and they show the following framerates for 50k tree instances:

    - Standard instantiate with mesh renderers: 16.7 FPS
    - Calling Graphics.DrawMesh for each tree instance in Update: 10.9 FPS
    - Using Graphics.DrawMeshInstanced: 178 FPS

    So maximum performance is not as good as Unity billboards as 178 FPS is for just 50k trees. But it's much better than using regular meshes. I also noticed that this requires instancing and older graphics cards may have issues while Unity's tree billboards are running nicely since early days of Unity.

    On a good side, trees are aligning nicely to perspective camera. They also react nicely to directional light. The side of trees looking into the direction of sun appears brighter than the opposite side. And trees can have randomized rotations.

    I missed shadows a bit, these imposters are not casting shadows so far. I also found comment in ImposterStandard.shader with TODO that is needs a proper shadows pass. But so far no new updates since 2018 in that repo.

    But overall, it gives very interesting solution so far :)
     
    Last edited: Jul 9, 2020
    UlfvonEschlauer likes this.
  37. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,550
    You should use Frustrum Shadows for far away trees. It is a cheap image effect. Next-Gen Soft Shadows (NGSS) comes with a camera script for this.

    Note: There are 0 shadow casters in this screenshot. All trees are imposter billboards from Amplify Imposters.
    Capture.PNG
     
    UlfvonEschlauer likes this.
unityunity