Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[RELEASED] Vegetation Studio

Discussion in 'Assets and Asset Store' started by LennartJohansen, Jun 23, 2017.

Thread Status:
Not open for further replies.
  1. bok

    bok

    Joined:
    Feb 24, 2014
    Posts:
    44
    Thank you so much for the fast and helpful reply rasto61!
     
  2. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Wondering if there is a way to do this with VS.

    Basically, I want to replace trees or objects with another mesh at the same position. So for example a tree morphs into a stump with some logs by it, then next version logs are removed, then stump is removed to be replaced by the original tree.

    It needs to use the core instanced direct rendering system not spawn gameobjects, as it needs to work at scale. I don't anticipate morphing all objects in a scene this way, but up to a few thousand.

    I have a simple instanced direct rendering system with cpu frustum culling via jobs that works. I can say mask out a VS tree then start the morphing process via my system. But I'd rather just standardize on VS for all of it if possible.
     
  3. A2GStudios

    A2GStudios

    Joined:
    Nov 21, 2016
    Posts:
    52
    What am I doing wrong to get these extra colliders around the map? Odd colliders.PNG
     
  4. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Hi.

    It looks like you added a collider to a VegetationItem? like a small rock?
    Or maybe you baked tree colliders to the scene with the bake function on the collider system?

    Lennart
     
  5. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    340
    Lennart is actually writing an example script on how to access trees, remove specific instances , and replace them by new ones, all in the VS system. I've been discussing with him about this and he said he'd post the example right here, so it shouldn't be long ! :)
     
  6. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Hi. You can do this with the persistent storage.

    1. Add both the tree and the stump/logs vegetation item to the Vegetation Package

    2. set up spawn rules for the tree as normal. Disable run-time spawn for the stump/logs

    3. Bake the tree instances to the persistent storage.

    4. Run-time you select the instances you want to change. You can query for area, or maybe use scripts on colliders. Depends on your game logic.

    5. Change the tree instance to a stump.

    You can do this with the static API on the VegetationStudioManager. You remove the tree instance and add the stump instance at the same position, rotation and scale. Clear the cache to refresh the affected area.

    Code (csharp):
    1.  
    2.  
    3. public static void RemoveVegetationItemInstance(string vegetationItemID, Vector3 worldPosition,
    4. float minimumDistance, bool clearCellCache = true)
    5.  
    6. public static void AddVegetationItemInstance(string vegetationItemID, Vector3 worldPosition, Vector3 scale, Quaternion rotation,bool applyMeshRotation, byte vegetationSourceID, bool clearCellCache = true)
    7.        
    8.  
    If you want this to save between sessions you need to store the changes and apply again at load.

    There is a ExportToStream and ImportToStream function on the PersistentVegetationStoragePackage that will serialize the entire persistent storage to a binary blob. But it is probably better to just save you changes.

    Lennart
     
    nirvanajie likes this.
  7. A2GStudios

    A2GStudios

    Joined:
    Nov 21, 2016
    Posts:
    52
    Ok, I will check both of those areas. I also sent you a PM asking some questions about the integration with Ultimate Survival. I added the scripts from the previous post but they are still not minable.

    If those colliders got baked on, how would I go about removing them? Thanks for all the help
     
    Last edited: Mar 13, 2018
  8. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Thanks for the fast reply, looks like what I need.

    This is multiplayer so I I basically just store a compact representation of changes only and then just apply those in the same way I applied the original change, via the api.
     
  9. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Look in the scene. they should be in there. as a root object.

    I will get around to your PM soon.

    Lennart
     
  10. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Hi. You can not do that. The vegetation masks have to be in the scene as objects. They need to register and are used during spawning.

    I think Rasto61 answered your other questions.

    Lennart
     
  11. bok

    bok

    Joined:
    Feb 24, 2014
    Posts:
    44
    Got it, thanks Lennart! Do you happen to know of any other third party plugin that can do that? To mask out the VS grass near randomly spawned prefabs?
     
  12. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    You can do this with VegetationMasks if you spawn your houses or other prefabs to the scene. The vegetation mask can be saved with the prefab. But it does not work if you try to spawn the house as a object in Vegetation Studio.

    Lennart
     
    bok likes this.
  13. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Hi.

    We found a solution to the inspector refresh slowdown with a large amount of vegetation items.
    Thanks @Dorian-Dowse for helping testing. It will be in an update at the end of the week.

    Lennart
     
    Mark_01 and Akshara like this.
  14. voncarp

    voncarp

    Joined:
    Jan 3, 2012
    Posts:
    187
  15. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
  16. voncarp

    voncarp

    Joined:
    Jan 3, 2012
    Posts:
    187
    I am using a Mac. Unity 2017.2.1f1
     
  17. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Change the editor Graphics API to Metal or go on each grass item and change rendering from instanced indirect to instanced.
    OpenGL does not support the graphics API needed for instanced indirect rendering.

    Lennart
     
    voncarp likes this.
  18. voncarp

    voncarp

    Joined:
    Jan 3, 2012
    Posts:
    187
    Changing to Metal did it. Thanks!
     
  19. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    So this modifies the storage which I don't want. Which is editor only I realize but that means every play session I have to go reset the data which is a pain. I can probably work around that though.

    But I couldn't figure out how to clear the cache so nothing was being removed at runtime.
     
  20. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Ya just replacing the scriptable object with an instantiated copy on Awake fixes the first issue.
     
  21. Dorian-Dowse

    Dorian-Dowse

    Joined:
    Jun 2, 2016
    Posts:
    95
    If you set Advanced/Manual Vegetation Refresh to on, then turn tree density to 0, then click Refresh vegetation, the billboard trees are not removed.
     
  22. Maximilious

    Maximilious

    Joined:
    Nov 29, 2016
    Posts:
    28
    lol dont worry about it
     
    Last edited: Mar 14, 2018
  23. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Ok so for adding/remove instances. You have to disable runtime spawning on everything. If you remove an instance with runtime spawning enabled, it just removes it from the storage only.

    But now the issue is the billboards still remain even after removing an instance. I could fix it via masks, although I'm thinking there is a more direct/correct way to deal with that issue.
     
  24. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Yes. This should work good. Maybe I should make an option for this. For use in editor playmode testing.
     
    Mark_01 likes this.
  25. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    I will look at the billboards. They should in theory be removed automatic when cells affected by the peristent storage API was refreshed. Probably an event that is not called when done from the API.

    Lennart
     
  26. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    I will have a look at this. Thanks for finding this :)
     
  27. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Late here so no time to investigate. But during some quick stress testing where I'm replacing around 50 or so trees and then adding a mask every 2-3 seconds, I saw the billboard system causing consistent 2.5mb of allocations every few seconds also. I think it was in pre late update something in the profiler. I'll look closer when I'm up and around next.
     
  28. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    340
    So all I need is how to get the position, rotation and scale of trees from a matrix4x4
     
  29. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    You can use the static functions in the MatrixTools class. pass the matrix and get the position, rotation and scale back.

    Code (csharp):
    1.  
    2. public class MatrixTools
    3. {
    4. public static Vector3 ExtractTranslationFromMatrix(Matrix4x4 matrix)
    5. public static Quaternion ExtractRotationFromMatrix(Matrix4x4 matrix)
    6. public static Vector3 ExtractScaleFromMatrix(Matrix4x4 matrix)
    7. }
    8.  
    Lennart
     
  30. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    340
    Ok, thanks

    How should I use the float minimumDistance in RemoveVegetationItemInstance, if I already have the exact position of the instance ?
     
  31. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Use 0.2f That is the default the VegetationMaskItem uses also.
     
  32. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    340
    Thanks a lot for your time!!
     
  33. bok

    bok

    Joined:
    Feb 24, 2014
    Posts:
    44
    Could I spawn the house including the Vegetation Mask with MapMagic to disable grass around the house?
     
  34. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Yes. I think that should work good.

    Lennart
     
  35. DirtyHippy

    DirtyHippy

    Joined:
    Jul 17, 2012
    Posts:
    224
    Hi -

    I have an elaborate build process that strips out everything for my headless server build, and it would need to strip out Vegetation Studio as well. My server build would need some way of pulling out prefab type/pos/rot/scale for things like trees so I could generate the runtime collider I need and inject it into my chunking system. Since I couldn't pull this out at run-time (since the component wouldn't exist), I would need to pull it at build time.

    Is there an easy way to retrieve this data through the API in Editor mode?

    If not, if there is a way to just have it plop colliders on the scene itself like you describe above that would be enough as well, as long as I had some way of identifying what they are so I could deal with them appropriately.

    Thanks!
     
  36. bok

    bok

    Joined:
    Feb 24, 2014
    Posts:
    44
    I have a top down game (the perspective is like Divinity Original Sin or Diablo). This means that I only ever need to see the vegetation that is near my characters surroundings and I don't need to see any far away plants or far LOD.
    Are there any settings that I can use to save me a lot of performance for a top down game or anything else I need to consider?
     
  37. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    If you go to the collider system there is an option there to bake all the colliders assigned to the trees to the scene. You can get them as meshes or colliders depending on your navmesh system and what it needs.

    Image is an example of colliders baked out and used to create a unity navmesh. But you have the individual colliders and can feed them to whatever system you want.

    Lennart

     
  38. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    You can turn of the billboard system component since you will never get in the position to see billboards. This will save the generation and culling for that.

    The rest is done automatic based on camera frustum and culling.

    Lennart
     
  39. bok

    bok

    Joined:
    Feb 24, 2014
    Posts:
    44
    Thank you!
     
  40. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Instanced GI

    Hi. I am working on a small video to show how Vegetation Studio can use the new instancing with GI lighting that will be available in Unity 2018.1

    I wanted to share a couple of screenshots showing progress.

    The torches in the image are baked lights. Lightprobes is placed in the scene.
    Vegetation is run-time spawned from a Vegetation Package.

    First image is without the Instanced GI enabled.




    And this with...

     
  41. Dorian-Dowse

    Dorian-Dowse

    Joined:
    Jun 2, 2016
    Posts:
    95
    Conversely, If it's on manual refresh, it doesn't create billboards either.
     
  42. Dorian-Dowse

    Dorian-Dowse

    Joined:
    Jun 2, 2016
    Posts:
    95
    On the subject of billboards, I'm making a scene with big old gum trees lining a river. I want them to lean out over the river. Using the rotation set to "Follow Terrain" does this nicely. However, I noticed that it doesn't apply the rotation to the billboards. This is quite noticeable in the transition as the tree goes from upright to leaning.
     
  43. Suavomirro

    Suavomirro

    Joined:
    Dec 3, 2012
    Posts:
    61
    I tried to find if someone asked this but search tool isn't really great. So, is there an option to reach position of single object(tree)? In standard Unity system Im placing trees with brush and then exporting them to empty folder using script, so I have physical objects. I need this because our trees are spawning server side so players online can chop them. It will be much easier for me to use vegetation system spawning rules and then when I have positions, discard trees from spawner.
     
  44. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Hi.

    The SceneVegetationBaker component can export all trees or other vegetation to the scene.
    Have a look here.

    You can also do this with the API. Have a look at this post.

    Lennart
     
  45. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    This is the same issue as you reported with the density to 0. The billboard refresh is not called. I will add a fix.

    The billboard system only allows for rotation around the Y axis. I will add a warning to the inspector about this. I still will keep the follow terrain option on rotation if someone wants to use this for trees without billboards.

    Lennart
     
  46. AndyNeoman

    AndyNeoman

    Joined:
    Sep 28, 2014
    Posts:
    938
    Hi @LennartJohansen , Is there a event I can hook into when the grass has touchbend so I can play a soundfx file for the rustle?
     
  47. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    EasyRoads3D

    EasyRoads3D just released beta 3.1 with Vegetation Studio support. It will create VegetationMaskLines automatic for new roads masking out vegetation. It is also using the new VegetationMaskLine features from the last update allowing for per segment settings. This allows changing road width and vegetation under bridges without making multiple mask components. Thanks to @raoul for adding this integration.

    Lennart



     
  48. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    No, that is not that easy. it all happens on the GPU. CPU does not know what is going on...
    You could maybe generate a VegetationColor map of the terrain and sample the alpha and color of that to know that your character is walking on grass.

    Lennart
     
  49. Suavomirro

    Suavomirro

    Joined:
    Dec 3, 2012
    Posts:
    61
    Thank you very much Lennart, baker is working great.
    Maybe you will have idea how to do one thing. So like I said I want to have trees on server side to enable chopping them down by players and have synced visuals for them all. But vegetation studio trees are much faster than normal objects. Do you think there is a way to keep positions of trees on server and dynamically update vegetation system for all of players? Something like dynamic mask change for specific object.

    PS: Im posting one of my first results with this addon and I'm very impressed.
     

    Attached Files:

  50. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Hi. I did a post on somehing like this a couple of days ago. Have a look.

    You would basically bake the vegetation to the persistent storage when you are happy with the distribution. Then export the instances and colliders if you need for your server.

    When a user chops down a tree, you remove the tree with the API and sync the remove command to the other clients. Your server keep the chop command list and syncs this to new clients as the connect.

    Lennart
     
    AndyNeoman likes this.
Thread Status:
Not open for further replies.