Search Unity

[RELEASED] Vegetation Studio

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

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

    LennartJohansen

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

    I have been doing some refactoring of the RuntimePrefabSpawner component.
    It is now possible to add multiple prefabs for each VegetationItem. Each have a configurable seed and separate settings.

    Before you had to use multiple components but now you can configure for all VegetationItems in the same component.

    There is also a new event you can connect to.

    Code (csharp):
    1.  
    2. OnEvaluateRuntimePrefabSpawnChance(string vegetationItemInstanceID, ref float spawnFrequency,int seed)
    3.  
    this will be called when evaluating the spawn chance of the prefab. It passes you an unique ID for the VegetationItemInstance and the current spawnFrequency. You can here use your own logic to modify the spawn chance of the prefab.

     
  2. Olander

    Olander

    Joined:
    Sep 13, 2014
    Posts:
    405
    And this keeps getting better and better. Lennart! Reading my mind? Not such a good thing. haha!!
     
  3. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    Nice!
    Is the seed to dictate the chance only? It would be useful in other ways if there was a range of offsets, letting the prefab go anywhere within a 20cm-100cm radius around the object for example.

    so I'm thinking (danger)... Could I feed an empty GameObject into the VegetationStudio and use the runtime prefab spawner to dictate what gets spawned. For example right now I have lots of tree, and managing the settings on them all is very time consuming. If I had a ForestA group that had a chance at becoming any one of the 10 trees added within the group I would only have to setup the spawn settings of ForestA. Not quite the purpose of what you're showing here, more like a switch mechanic instead of multiple choice, but that would be very useful.

    I was thinking earlier too (danger!), I have a modular building system in my game that makes it really easy to place a lot of walls/floors/etc very fast because I like to build big. Imagining I've got a house with 500+ walls, those are going to start eating at the GPU if not handled properly. I've messed with a few methods, but heck, VegetationStudio is doing a badass batch and sort job........ not at all what this is intended for, but I don't often follow the guildelines... say I setup my building classes to feed objects into VegetationStudio for all the batching and collider support. Afterall, they're just GameObjects... I'm just thinking outside the box, but I'm so impressed with the grass and tree management.... and I'm bored at work :rolleyes:
     
    Olander likes this.
  4. guidoponzini

    guidoponzini

    Joined:
    Oct 4, 2015
    Posts:
    55
    When it will be released? I'm working on a project for November and I eould like to implement it
     
  5. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    1. A range for offset and a random rotation could be an nice thing to add. I have added it to my list

    2. While you could spawn trees like this I would not recommend it. The trees will only be instantiated when in the range set in the prefab spawner. You will not get any long distance billboards and on top of this loose the benefits of batching the trees together with the others of the same type while doing instanced rendering.

    3. Same issue as with the trees. You would get houses that just pop into existence. And they would still render as normal gameobjects.

    Lennart
     
  6. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Asset store approval takes about a month now and there is still a bit of work before I can send it. I would guess the end of November as earliest release date.
     
    RobsonFMaciel and ZoneOfTanks like this.
  7. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    I can understand how the prefab spawner system is different. It would still be very useful to have some sort of a group/switch setup though, using the vegetation system, not the prefab system. Logic to determine a random tree within a group.

    I have found a cosmetic bug.
    vegetationstudio.jpg
    patches of the grass are being culled at angles that they can still be seen at.

    I've got saving/loading of resource harvesting in runtime working good. I have a question though. I will be working to implement a floating point error protection shift into VegetationStudio. It seems the masking system uses a global batch even when multiple VegetationSystems are being applied around on different terrains, the masks using a simple Vector3. This means that I shifting the world back to zero will still be using the same masks. So I could wipe the masks and start a new list every shift, but would the noise end up being the same in this case?

    For example, I shift every 8000m, say there is a tree at x1m, z1m, but no tree at x8001m, z1m. If I shift x -8000m, then the game world will be back at x1m, z1m, but my terrains will be using noise offset by x8000. The terrain heightmaps and splatmaps will be very different, but VegetationStudio will be unaware of the actual offset. Can you forsee an easy way to implement this into VegetationStudio, or point me towards the right code to look at? Offsetting an int based noise is usually the easiest, as floats just don't go far enough.
     
  8. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    VegetationStudio supports floating origin. All noise samples etc are relative to the terrain not the world. Just move the terrain. System will autodetect this and update.
     
    Mark_01 likes this.
  9. wood333

    wood333

    Joined:
    May 9, 2015
    Posts:
    851
    1. What might be useful for me would be to have just the tree trunk "colliders" placed/baked and not instantiated, but have the speed tree prefabs instantiate under your system. In my scene, the presence of speed tree trunk colliders does not noticeably effect FPS, but my character facing a field of animated speed tree meshes has a definite measurable impact on FPS.

    2. I have read through this forum, including the explanation of using nav mesh, and what I was really asking about was your experience with colliders instancing inside other colliders during play. For example, should VS instance a tree in a manner such that the tree collider intersects a creature collider, is this really a problem? Colliders block out the exterior, not the interior. Would the ai creature simply walk out of the tree and thereafter be prohibited by ordinary colliders from reentering the tree? For testing purposes, I can pause my scene and move a unity 3rd person controller inside another object, then unpause, and while the controller jiggles, the player controller can easily walk out of the other object with no harm done. Has you team ever observed what happens when VS instances objects within other objects?
     
  10. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    1. There is an option on the colliderSystem component to bake out all colliders to the scene. Press this and then disable the colliders on the trees that spawn run-time. Trees will still render as normal on the same location. Colliders have the VegetationItemInstaceInfo script that can be used to mask out the tree if you need later.

    2. This could happen. There is no raycasting against colliders on creatures etc. This is to slow and does not work with multithreading. If this is a problem is all up to how the AI creature is configured. What moves it, does it raycast against something? are the colliders triggers etc.
    I have not done much testing on this. Maybe some of the beta testers have tried?
     
    ZoneOfTanks and wood333 like this.
  11. wood333

    wood333

    Joined:
    May 9, 2015
    Posts:
    851
    Good news. I think for my purposes I would go this route. Get my scene set up with VS and when the buildings and vegetation are to my liking, bake out all the colliders. This begs the question, what if I mess up my layout and need to redo? Can I rebake out all the colliders? I assume I cannot alter or remove individual colliders once baked.
     
  12. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    The baked colliders are gameobjects in the scene, you can delete individual if you want. Or just delete the parent object and bake again... takes a couple of seconds to generate.
     
    wood333 likes this.
  13. wood333

    wood333

    Joined:
    May 9, 2015
    Posts:
    851
    Excellent, where do I sign?
     
  14. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    515
    At startup I get this though none Vegetation Studio component are available in the scene yet.

    upload_2017-9-28_22-4-33.png
     
  15. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Strange bug. Will send you a PM for more info.
     
  16. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Sent you a message.
     
  17. lanrosta

    lanrosta

    Joined:
    Oct 11, 2014
    Posts:
    26
    Brought here by a link found on the CTS forum. Excellent work and I am very interested in this asset. Will gladly buy it on release. For now though, can I get access to the beta so I can run these same tests please? Keep up the great work Lennart!
     
  18. mons00n

    mons00n

    Joined:
    Sep 18, 2013
    Posts:
    304
    @LennartJohansen are there any docs on the Persistent Vegetation storage component? I can't find any in the manual or on the website and I'm not 100% sure how I should be using it.
     
  19. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    I am still working on the last function of the component. The manual vegetation painting tool. When this is done I will make the component documentation.

    I will update here with progress when the vegetation painter tool is done. It will be in the next beta version.
     
    Alverik and mons00n like this.
  20. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Today's development update.

    I finished the basic functionality on the vegetation painter.
    This is a tool built in the PersistentVegetationStorage component that allows you to paint vegetation on your terrain.

    This painted vegetation can be combined with any run-time spawned rules.



    You can select brushes, sample distance, brush size etc. The placement is smart and follows the rotational rules you have set on each vegetation item. Grass can be set to follow terrains slopes, scale to fit the extra area.



    Here is a small video showing the painter in action.



    Trees, rocks and larger objects you can also edit direct, with exposed handles.

     
  21. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    I'm trying to get vegetation to update after heightmap changes in runtime.
    I'm trying RefreshVegetation() or UpdateVegetationCells() in VegetationSystem and getting
    a MissingReferenceException. perhaps intended. Should I be calling something else?
     
    Last edited: Sep 30, 2017
  22. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    I will make a post tomorrow explaining how to do runtime updates of height and splatmap
     
    malkere likes this.
  23. LennartJohansen

    LennartJohansen

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

    I did some more work on the vegetation painting tool.
    There is better control on brush size.
    • Randomize position
      This will randomize the sample positions. When turned off you paint in the exact position of the white spots.
    • Paint on colliders
      With this enabled you can paint on any collider in addition to the Terrain.
    • Use steepness/angle rules
      This will use the steepness/angle rules set up on each of the vegetation items.





    Here vegetation is painted on a rock with a mesh collider on the terrain.



    And here on a roof with a collider. My painting skills probably needs some improvement but It shows the principle.

    The post on the run-time API will have to wait until tomorrow. Getting late here.
    The painting changes will be in the next beta. Probably Tuesday.
     
  24. NoctisFatehart

    NoctisFatehart

    Joined:
    Jul 30, 2014
    Posts:
    28
    Hello! Is there a way to get into the Beta? I would love to test this out too, since I'm considering buying it on release! It looks amazing!
     
  25. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    I was asked to show a bit of the API to update vegetation for run-time changes to the height and splatmap of the Terrain.

    A scene with VegetationStudio always has a single VegetationStudioManager component. This is responsible for managing multiple VegetationSystems in a single scene. The VegetationSystem component will register and unregister automatic.

    Manual changes to the heightmap or splatmap using the Unity terrain inspector are updated automatic as you paint.


    If you change the height or splat data using the API on the TerrainData object you need to let VegetationStudio know that you have done the changes. If you do not call this API, changes will only update the next time you enter/leave playmode or load a scene.

    There is a set of static functions on the VegetationStudioManager.

    These 3 functions will refresh the Heightmap

    Code (csharp):
    1.  
    2. public static void RefreshTerrainHeightMap()
    3. // this will refresh the heigtmap on all vegetationSystems in the scene
    4.  
    5. public static void RefreshTerrainHeightMap(Bounds bounds)
    6. //for only partial updates you pass the bounds of your changed are. Affected areas are refreshed.
    7.  
    8. public static void RefreshTerrainHeightMap(Terrain terrain)
    9. //This will refresh the VegetationSystem of the terrain
    10.  

    And this controls the splatmap refresh.
    Code (csharp):
    1.  
    2. public static void RefreshTerrainSplatMap()
    3. // this will refresh the splatmap on all vegetationSystems in the scene
    4.  
    5. public static void RefreshTerrainSplatMap(Bounds bounds)
    6. //for only partial updates you pass the bounds of your changed are. Affected areas are refreshed.
    7.  
    8. public static void RefreshTerrainSplatMap(Terrain terrain)
    9. //This will refresh the VegetationSystem of the terrain
    10.  
    if you change both the splat and heighmap call both.
    If you have the bounds of your changed area this is the fastest call since only the changed areas are invalidated and refreshed.
     
  26. antoripa

    antoripa

    Joined:
    Oct 19, 2015
    Posts:
    1,163
  27. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Last update on the painting tool. Finishing today and moving to the next item on the list.

    I have added a new Precision Painting system.
    This allows you to fine place vegetation with a pen point accuracy.



    In addition to the brush that can paint on terrain and colliders this includes an additional mode.
    It allows you to raycast against any enabled mesh in the scene to get a position and normal. This also works for meshes without colliders.

    The painter will build a octree with all mesh bounds in the scene. raycast that tree and then manually raycast the potential meshes to find the hit triangle.

    the ray is projected from the cursor on the screen and not from top as a normal unity detail brush. This allows you to place vegetation in any orientation while in this mode.



    This gives you an accurate position mode and visualization of the normal.

     
    manpower13, one_one, Olander and 5 others like this.
  28. AndyNeoman

    AndyNeoman

    Joined:
    Sep 28, 2014
    Posts:
    938
    A little WIP using Vegetation Studio. I need to redo my terrain heightmap so a few things are hovering but it is looking good. Sorry if you see it in other threads it is relevant in those too due to the assets :).
     
    P_Jong, mwituni, Alverik and 2 others like this.
  29. LennartJohansen

    LennartJohansen

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

    Been working on some requested functionality for the tree billboard system today.
    Vegetation Studio has a built in billboard system for trees. It will render a billboard atlas when you add a new tree to the VegetationSystem Component. It will then manage the billboards and batch these together in up to 10000 trees per drawcall. The amount batched together is based on density and a billboard cell size you can configure.

    All this is done automatic and works for most scenarios.

    I have now extended the "Bake Billboards" functionality.
    What this does is pre generate the meshes that contains the billboard quads. These are saved as normal unity meshes and materials.



    All billboard functionality is still working, selecting the correct image from the atlas, near and far clipping for when you get withing distance of mesh trees etc.

    These billboard meshes are created in the localspace of the assigned terrain and will be saved as a child object of the terrain. mesh and material saved to the project folder.



    The idea behind this baked export is for multi terrain grids. You bake the billboard meshes for each terrain and save this with the Terrain in asset bundles or scenes. Then at async load you load the terrain with the billboard meshes. Trees show up direct with no more loading time than a normal unity mesh and material.

    Since these terrains usually load at a distance far outside grass and mesh trees there is no need to assign a VegetationSystem component to them before you get closer.

    You can then set up a small pool of 4 (depending on terrain size and grass tree distance) VegetationSystem Components and re-use these on the closest terrains as you move around your game-world. Returning the VegetationSystem components as you move out of range.

    I added a "Hotswap" function on the VegetationSystem components in the last beta for this use. It can re-use a VegetationSystem component that has a terrain with the same size. It will then just "move" the internal quadtree to the new terrain location. re use the cell object structure etc. This saves time initializing on a new terrrain.
     
  30. sylon

    sylon

    Joined:
    Mar 5, 2017
    Posts:
    246
    Can't help but get a bit excited seeing this grow over the last few months.
    This week i have decided to go with Unity terrains combined with MicroSplat and replace my own simple instancing system with Vegetation Studio.
    Feels like a weight is lifted, now that i have finally made up my mind and i look forward to trying this out!
     
    MortenGulden and LennartJohansen like this.
  31. SSL7

    SSL7

    Joined:
    Mar 23, 2016
    Posts:
    349
    Awesome work @LennartJohansen ! Can't wait for next beta, and then the final product :D
     
    LennartJohansen likes this.
  32. sylon

    sylon

    Joined:
    Mar 5, 2017
    Posts:
    246
    Hi.

    I was wondering ..
    Is it possible to use VS in a lightmapped scene?
     
  33. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Since the vegetation does not exist as static GameObjects it will not bake into the lightmap. The grass is made as a surface shader and will recieve any normal Unity lighting for dynamic objects. Speedtrees will react to light the same way instanced speedtrees does etc.
     
    Alverik likes this.
  34. sylon

    sylon

    Joined:
    Mar 5, 2017
    Posts:
    246
    Right. Figured as much.

    My trees are all meshes, with custom shaders
    In my current workflow, i place everything as GameObjects so i can bake the scene. At runtime i remove those objects and render them by script.
    I suddenly realized that this could be at odds with your magnificent system.

    Another hurdle to overcome :)
     
  35. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    There is an option to bake out colliders to meshes now. This is used to bake navmeshes.

    If you want a similar function to temporary bake out trees to static GameObjects in the scene it is easy to add. If this helps your light baking. Then just delete them. 1 hour job to make a component with a bake to scene component.

     
    Alverik likes this.
  36. sylon

    sylon

    Joined:
    Mar 5, 2017
    Posts:
    246
    That would definitely solve my issue and get me back on track.
    Thank you for your quick reply.
    You can put me back on the pre-order list :)
     
  37. LennartJohansen

    LennartJohansen

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

    There is now a new component. SceneVegetationBaker. Add that to the same GameObject as the VegetationSystem.


    Select the VegetationItem you want to bake to the scene and press the button.



    You will then get the item baked to the scene, set as static objects.
    Just delete when done.

     
    one_one, Alverik, mwituni and 2 others like this.
  38. sylon

    sylon

    Joined:
    Mar 5, 2017
    Posts:
    246
    Seriously?
    I just finished my coffee in the time it took you.
    Very nice.
     
    Alverik and AndyNeoman like this.
  39. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Not that hard to extend when the framework is working. It will be in the next beta.
    Requests like this is good. Keep asking if you have ideas.

    Lennart
     
  40. LittleMike

    LittleMike

    Joined:
    Jan 12, 2014
    Posts:
    101
    I came over here from the Ultimate Survival thread. Damn, Lennart, this is some amazing stuff. I don't even know if I need this in my current project, but I'm picking this up when you go live with it. It looks that good!
     
    P_Jong and Alverik like this.
  41. BackwoodsGaming

    BackwoodsGaming

    Joined:
    Jan 2, 2014
    Posts:
    2,229
    Once released, I think it will be vital for any project with a lot of vegetation. In my testing on a crappy machine, I've been amazed at the performance gains.. Along with the ability to actually move in a scene with dense vegetation (which I couldn't do before).

    This is another asset that will be high on my list of tools to recommend to other devs.
     
    Mark_01, Alverik and LittleMike like this.
  42. LennartJohansen

    LennartJohansen

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

    Todays development update.

    I have finished GPU frustum culling for all instanced indirect rendered grass and plants in Vegetation Studio.

    Vegetation Studio has an internal cell based culling of vegetation. This works well using the unity CullingGroups API.
    As you move the camera around there will always be some of these cells that is only partial visible by the camera.

    to fix the overhead of rendering extra grass and plants outside the camera frustum I am now culling each grass mesh in the GPU before rendering.



    I set up a test scene for benchmarking with really dense grass to force my laptop to be GPU bound.


    And here is the sceneview of what is actually rendered now after the 2nd level GPU frustum culling.



    The left part of the GPU profiler is with the new culling enabled. Right part without


    The spike in the middle is just unity doing something strange while I recompile the shader.
    This is enabled now for the instanced indirect grass and will be in the next beta release.
     
    Last edited: Oct 7, 2017
    Olander, lawsochi, Baraff and 15 others like this.
  43. LittleMike

    LittleMike

    Joined:
    Jan 12, 2014
    Posts:
    101
    SHUT UP AND TAKE MY MONEY!

    Haha, in all seriousness, the more I read these updates, the more excited I get for release. This looks like it should be a tool in everyone's arsenal. Great job, Lennart!
     
  44. AndyNeoman

    AndyNeoman

    Joined:
    Sep 28, 2014
    Posts:
    938
    The more you use it the better it gets. Really looking forward to the official release. Must have asset imho. I need to start using masks though so I have other biomes but I just can't get away from the total jungle coverage.

    This video shows tree and plant placement. I now have mass ferns/grasses in (video to follow soon) and still getting 30-40fps with realtime global illumination and custom shadows.

    Edit:- Mass ferns included in video now.

     
    Last edited: Oct 9, 2017
    Alverik and LennartJohansen like this.
  45. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    Maybe a stupid question to ask,
    does VS has an option to adjust the distance of each LOD for the trees or the view distance for mesh trees and grass?
     
    Quique-Martinez likes this.
  46. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Hi. I will try to explain how it works.
    You have 3 basic distance settings.
    • Vegetation distance
      This is where you will get grass, plants and objects you are spawning in the scene.
    • Additional mesh tree distance
      This is the additional distance on top of vegetation distance where you get mesh trees and large objects
    • Additional billboard tree distance
      Here the billboard system is in use.


    LODs for trees are set on each individual VegetationItem/prefab.
    LOD distances are read from the LODGroup on the prefab and adjusted for LODBias in the Quality settings.
    On top of this you have a LOD factor you can adjust in the GUI. This is for easy adjustment without having to change the LODGroup settings.

     
    Alverik, AndyNeoman, Mark_01 and 4 others like this.
  47. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    Thank you very much for the detailed explanation!
    Does it mean I set vegetation distance to 100 and mesh tree distance to 200 will make the mesh tree extend to 300 meters far?
     
  48. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    yes, and the LODs used of for the 300 meters is based on the LODGroup in the prefab.
     
    Alverik and Harekelas like this.
  49. Ziboo

    Ziboo

    Joined:
    Aug 30, 2011
    Posts:
    356
    Hello.

    This asset seems to be perfect for what we need in my studio.

    Any ETA for the release ?

    Possible to have access to the beta ? (PM me if you need more info about the studio)

    We also using "Terrain Composer 2", is it compatible with VS ?

    Have a good day

    Thank you
     
  50. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,206
    About TC2 compability, I've been developing a simple integration already, planning on extending it so you can spawn your vegetation with TC2. So yes, at least for release it probably will be possible:)
    Seneral

    EDIT: I'm not the developer of VS, just a beta tester that does the TC2 integration - sorry for confusion lol
     
    Last edited: Oct 10, 2017
Thread Status:
Not open for further replies.