Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

[Released] Advanced Terrain Grass

Discussion in 'Assets and Asset Store' started by larsbertram1, Sep 11, 2017.

  1. DirtyHippy

    DirtyHippy

    Joined:
    Jul 17, 2012
    Posts:
    224
    Also is there any reason all this stuff is under /Resources? In my headless builds I dont need anything included in my build with respect to rendering (as my automated build strips all that out). All these files under resources (shaders, etc) will get included in the build unless I rename the resources file before the build and revert it after. I see only one Resources.Load for the wind texture..
     
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,858
    which warnings do you exactly mean?
     
  3. jhughes2112

    jhughes2112

    Joined:
    Nov 20, 2014
    Posts:
    172
    Hey, just checking out your asset. Looks like there are several files that ended up in the standard Effects folder, such as ProjectorMultiply.shader, which upon installation modifies the user's standard packages. This may cause problems for folks, so you might want to move anything in your asset package that shows up under Effects/ over to your product's folder structure. :) I'm looking forward to using ATG!
     
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,858
    thanks for the hint. i will have a look into this.
     
  5. jhughes2112

    jhughes2112

    Joined:
    Nov 20, 2014
    Posts:
    172
    So, I'm trying to use this without saving data before hand, so SavedTerrainData==null, meaning InitCells() gets called. LayerToMergeWith[] is never assigned inside your scripts, so I'm scratching my head what that's supposed to be doing, since the code crashes at InitCells() when it dereferences the null array. I'm basically filling in a few of the parameters and letting OnEnable() call Init() for me. Little help?
     
  6. jhughes2112

    jhughes2112

    Joined:
    Nov 20, 2014
    Posts:
    172
    So, I created an array that was full of zeros that was the right length (number of detail layers), because I have no idea should actually be in there, and it skipped most of the InitCells() code, which seemed fine. However, it looks like v_mat is null as well. The code isn't very defensive about making sure things are set up right after Init() is called. How exactly am I supposed to use it? The test scene worked fine, but I assume it was using pre-saved data because feeding it data doesn't seem to work at all. What do I need to do to feed it data properly?
     
  7. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,858
    you do not feed in data. the script reads it from the terrain.
    so simply create a terrain, add at least one grass prototype (e.g. a simple texture) and paint some grass on top of your terrain.
    add the grass manager, done.
     
  8. jhughes2112

    jhughes2112

    Joined:
    Nov 20, 2014
    Posts:
    172
    Hmm. That's not the behavior I'm seeing. But then, maybe I'm using it differently than you expected me to. I have a GameObject that already has a Terrain on it. In code, I AddComponent<GrassManager>() to the object while the object is disabled, set a couple of values to configure it the way I want it, then when it comes into existence, GrassManager crashes in the various ways I've described. I do not have any of the code running that is in the Editor folder, because I'm not adding the component while running in the Editor. A lot of things are not configured this way.

    What is the right way for it to work seamlessly, as you suggest, when the component is generated in code?
     
  9. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,858
    i have never thought about this.
    but i would probably add the grass manager in the editor and let it grab all information needed.
    the you can do your tweaks and optimizations like merging layers or setting and testing the culling distances.
    when done safe the terrain data and remove the grass manager.

    adding the grass manager at runtime will need you to change the code as init() is called by onenable().
    you will have to make the grass manager wait until the terrain data is assigned then run init and make sure it calls initcellfast() - which will fill all needed arrays from the scriptable object and is way faster then doing it at runtime.
     
    Last edited: Apr 27, 2018
  10. recon0303

    recon0303

    Joined:
    Apr 20, 2014
    Posts:
    1,634
    Hi I seen a review saying this does not work with multi tiled terrains, I wanted to see before I bought. Thanks.
     
  11. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,858
    i have no problems using multiple terrains at all...
     
    recon0303 likes this.
  12. recon0303

    recon0303

    Joined:
    Apr 20, 2014
    Posts:
    1,634

    I figured as it didn't make sense you would, I just seen a review of someone complaining they did. so I like to ask. Thanks for info. May want to reply to it, so others don't think it may...
     
  13. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    How should I approach removing/hiding some grass at runtime? Doesn't have to be something performance friendly - I'm making a trailer which is recorded with fixed time step, so if the only way to do that is to trigger some heavy operation, that's still fine by me.

    To be more specific, I need to remove grass around some exploding vehicles, since dense untouched foliage looks kind of wrong poking through burning metal that just exploded in a sizeable fireball. So, I suppose I need to know how to force an update to grass data used by ATG when I access grass placement through the terrain API?
     
    Last edited: May 2, 2018
  14. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,858
    oh, i just happened to write such a feature – but as it is a piece of custom work i can not share it...
    but what i can share of course are the principle ideas. so here we go.

    • you need some kind of function, which takes a world position and radius as input describing where you want to remove or add grass and in which area.
    • the function converts the world position into terrain position and finally the 2d grid of the grass cells.
      Vector2 PositionInTerrainSpace = new Vector2(Worldposition.z - TerrainPosition.z, Worldposition.x - TerrainPosition.x);
    • next you calculate the effected cells, which is super simple and quite fast.
      // Remap to Position to the cell grid
      PositionInTerrainSpace.x *= OneOverCellSize;
      PositionInTerrainSpace.y *= OneOverCellSize;
      // Remap Radius to cell grid
      float RadiusInCellGrid = Radius * OneOverCellSize;
      // Get the affected Cells – max number should be 4 unless some very big destruction is going on here
      Vector2 NormalizePositionInGridspace = new Vector2( Mathf.Floor(PositionInTerrainSpace.x), Mathf.Floor(PositionInTerrainSpace.y) );
      // Handle cases where we at the edge of the terrain!
      // next check right upper and lower, left upper and lower and upper and lower cells
    • once you have the cells you have to get the effected buckets because buckets are the place where the actual grass density is stored. i did this brute force doing a distance check. small hint: using sqrmagnitude is way faster than using magnitude.
      // Get the cell's pivot in worldspace
      Vector2 CellPivot = new Vector2(CurrentCell.Center.x - CellSize * 0.5f, CurrentCell.Center.z - CellSize * 0.5f);
      // Get the bucket's center in worldspace
      Vector2 CurrentBucketCenter = new Vector2(CellPivot.x + BucketSize * 0.5f, CellPivot.y + BucketSize * 0.5f);
      float InitialBucketYpos = CurrentBucketCenter.y;
      // Get base position of the given cell in the density map
      int OffsetInDensityMap = CurrentCellContent.PatchOffsetX + CurrentCellContent.PatchOffsetZ;
      // Loop over all buckets
    • now you should have everything at hand to access the density arrays of all layers and calculate the new values using any kind of falloff:
      mapByte[layer][tOffsetInDensityMap] = Convert.ToByte( (int)((float)density * fallOff ) );
    • write out the new densities to the density arrays.
    • then it gets a bit tricky as you will have to regenerate the matrix buffers...
    • right now each cell can have (i do not remember exactly...) 3 states: not initialized, currently being calculated and ready to be drawn. so you will have to add 2 new states:
      • dirty but not regenerated yet -> take the old matrices and draw and add the cell to the very first place in the list of cells whose matrices shall be calculated by the worker thread.
      • dirty and ready to update -> pick up the new matrices, update the materialpropertyblock and draw
    in case you have come this far you will most likely come across 2 problems:
    1. grass jumps if a cell gets updated with the new matrices.
    2. the script might error because a layer now might have 0 grass entities
    1. address this issue by editing the worker thread: currently the random is calculated/reset per cell – but now some buckets might be completely empty so random.next might produce totally different results on bucket x if one bucket is skipped then it did before. so calculated/reset per bucket instead by moving it down into the inner loop.
    2. let the worker thread update the number of "Instances" per "GrassCellContent" or dirty the "GrassCellContent" by adding another state. then add safe guards in the grass manager. i added another state and made the grass manager check each "GrassCellContent" before it will queue it like:
    if (CurrentCellContent.state != -1) {
    draw etc...
    }
    this works like charm but takes a few frames to update the grass on screen in case you have a lot of cells which are effected. i hope this will give you a first idea.

     
  15. Kaen_SG

    Kaen_SG

    Joined:
    Apr 7, 2017
    Posts:
    206
    So ATG is not supported in Mapmagic but it has Vegetation Studio support right?
    So if I implement ATG in VS to handle vegetation on a runtime mapmagic terrain, everything is hunky dory yes?

    Have to check before buying. :)
     
  16. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,858
    you can use atg's grass and foliage shader in vegetation studio. everthing else depends on vs.
     
    Kaen_SG likes this.
  17. Wurlox

    Wurlox

    Joined:
    Nov 1, 2015
    Posts:
    50
    Just wanted to leave my thanks for this great asset. Really makes a difference when it comes to grass rendering :)



    I love it!

    Greetings,
    Wurlox
     
  18. Dobalina

    Dobalina

    Joined:
    Sep 6, 2013
    Posts:
    98
    Hey guys, I know missing cells are a known issue for this asset, but I'm confused as to how to address it. In my scene I have an Island in which the character can quickly leave and come back. Upon coming back, all the grass is gone and never respawns, the whole island is empty of grass. The theme of my game involves moderate speeds (nothing neck breaking) and moving far distances. So this missing grass issue is kinda asset breaking for me. I tried larger or small cell sizes and I'd like to not set a massive cache value. Any suggestions?

    I'm on Unity 5.6.0

    @larsbertram1
     
    Last edited: May 11, 2018
  19. PatrickLipo

    PatrickLipo

    Joined:
    Mar 14, 2015
    Posts:
    36
    Hi there! I pickup up ATG because of the recent sale and tried to set it up in the newly-released 2018.1... However just playing with the Quickstart scene in a blank project, when I put the grassmanager on the terrain and hit play, the grass disappears and I see periodic black squares. Something was weird with the terrain since it had no texture either, I had to apply it manually. Again this is just a blank project, with or without the ATG deferred shaders. Do I just need to be patient and wait for a 2018.1 compatibility release or do you suspect that I did something wrong?
    upload_2018-5-10_9-22-12.png
     
  20. Zaki_X

    Zaki_X

    Joined:
    Jul 5, 2016
    Posts:
    55
    @PatrickLipo - I bought ATG today and had a bit different, but still issues with Unity 2018.1. I didn't care about them though as I thought that Unity 2018 was a "beta" to me :rolleyes:. I've tested ATG with 2017.3 and demo worked and looked simply gorgeous. I have been blown away by quality of this shader. Transluency and reflections mixed with a couple of postprocessing effects left me speechless. I keep adding more and more of grass as it looks so bloody good :D. Unity's standard grass is simply a joke. I have to learn now how to create foliage with ATG and how to spawn it with Vegetation Studio.

    @larsbertram1 - If I would like to get a shader of ATG's quality for trees would AFS be a solution? That is what you told me once (If I remember well).
     
    Last edited: May 10, 2018
  21. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,858
    i think you will have to wait for a 2018 compatible version.
     
  22. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,858
    that depends on what kind of trees you have.
    afs supports tree creator trees only.
    in case you have manually modeled trees the custom tree importer should give you very nice results.
    in case you have speed trees then you are stuck.
     
  23. PatrickLipo

    PatrickLipo

    Joined:
    Mar 14, 2015
    Posts:
    36
    Welllll the 2018 beta's been around for a number of months, and since I really need the shader graph I didn't think it absolutely reckless to download it once it hit final (I have Perforce in case of catastrophe). Since ATG is a fairly new product I assumed it would have prompt support. Did you have any thoughts how long an update will take?

    I bought ATG on faith that it would help me with my isometric view (Unity's grass rendering has always been terribad for me). Frankly I haven't even seen a real interactive example of your tech running as of yet, and if you can point me at one, it would save me downloading a second copy of Unity. :p
     
  24. Zaki_X

    Zaki_X

    Joined:
    Jul 5, 2016
    Posts:
    55
    nextgen speedtrees for Unity 2018 should look way better than these old that we all know. I was thinking about using trees from NatureManufacture or creating my own set with Blender/3dsmax or Unity Tree Creator. Buying a good set seems to be a better solution. I'll see what will work best. Creating all set of trees by myself could take weeks though.
     
    Last edited: May 11, 2018
  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,858
    Welllll i once jumped onto a beta (unity 5.0) which simply was horror because whenever a new beta came out (every 2 or 3 weeks) you could spend at least two days fixing things that broke.
    i have no eta yet but i just tested my current dev branch in unity 2018.1 which works fine as far as i can say.
    so if you send me your email address (maybe in a pm or via email: larsbertram69@gmail.com) and your invoice number i could send you a package of the current dev branch.
     
  26. Zaki_X

    Zaki_X

    Joined:
    Jul 5, 2016
    Posts:
    55
    I've bought ATG, AFS, VS and Tropical forest pack. I'll have to learn how to efficiently combine all these assets.
     
  27. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,858
    good luck!
     
  28. PatrickLipo

    PatrickLipo

    Joined:
    Mar 14, 2015
    Posts:
    36
    Nah, I appreciate it but it sounds like things are coming along for an update so I can wait. I was just all psyched to use this new package and I hadn't heard a soul talk about 2018 on this thread... just worried that something catastrophic had happened with the update that invalidated the whole package (for example I bought a shader graph system in the fall and then everything went nuts :p). Putting money into the asset store can be a bit of a game of roulette, and something being on sale sometimes doesn't guarantee its viability. o_O

    I totally understand the insanity of trying to keep up with Unity. Thanks, and I eagerly await the next update!
     
  29. Imperatoss

    Imperatoss

    Joined:
    Mar 24, 2018
    Posts:
    51
    Hey, i just want to ask when approximately the patch will be released?
     
    PatrickLipo likes this.
  30. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    so..... did you ever get this to work?
     
  31. Imperatoss

    Imperatoss

    Joined:
    Mar 24, 2018
    Posts:
    51
    Have the same problem, when will it be solved?
     
    PatrickLipo likes this.
  32. zoltanBorbas

    zoltanBorbas

    Joined:
    Nov 12, 2016
    Posts:
    83
    Hey there!

    I am interested in your product but i am not sure if it is for me. I am making an rts game, i have the terrain procedurally generated with grass and foliage placed so i made a nice RTS camera with pane, rotate, tilt, zoom and adjust height to terrain elevation which all has one tiny but crucial issue, that in play mode the grass draw distance (Detail Distance) barely fills the view with grass even at the lowest zoom distance. As the screenshot bellow shows at a modest view angle the issue becomes even worse. I am looking for a solution that would allow the filling of the field with grass to far enough that culling would not be that painfully obvious.

    Please note the terrain is 7500x7500 units and camera zoom is between 100-1000.

    Would ATG be suited for this purpose?

    Thank you for your time.

    upload_2018-5-25_14-54-8.png
     
  33. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,858
    that is quite difficult to answer...

    first, atg allows further drawing distances than the built in grass – but of course this will cost performance.
    second: having a single terrain with a size of 7500x7500 may not be the best practice as you will have to create a lot of grass cells. splitting it up into 3x3 terrains would lift some work from unity's culling groups.

    coming back to the grass drawing distance: your screen shoot looks a bit weird. not only that is is pretty dark but grass looks super huge compared to the trees in the background.
    the grass texture seems to be way too dark compared to the grass detail texture painted onto the terrain. so of course fading out grass will be very obviously. you may make it way smoother simply by adjusting the grass' color.
     
  34. zoltanBorbas

    zoltanBorbas

    Joined:
    Nov 12, 2016
    Posts:
    83
    Hi there!

    You are totally right about the scene being weird, yes the grass been up scaled and ambient lightning was set to be black, which are not reflecting in any way how it is intended to look like. Pardon me for the misleading screenshot, never the less at only 100 meter height barely half the screen is filled with grass which is due to the maximum detail draw distance (250) of Unity grass solution.

    Can ATG draw at least twice as far?

    Also did i understood correctly from the documentation that ATG does not do camera facing bill-boarding at all?

    Grass field with no bill-boarding looked very bad from a top down RTS camera vantage point.

    Thank you for your response.
     
  35. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,858
    yes, but that is expensive.

    yes, no billboards. they simply look too odd.

    nope.
    simply "adding a texture of grass and map it to a single quad" looks odd.
    you may add a much more lively 3d mesh instead. then grass looks way more interesting even at steep viewing angles.
     
  36. Kaen_SG

    Kaen_SG

    Joined:
    Apr 7, 2017
    Posts:
    206
    @larsbertram1

    I'm having some issues using ATG and AFS in the same scene (instanced indirect via Vegetation Studio) not using the grass manager. Would be great if there was a tutorial.. or documentation somewhere on how to do this. I mainly bought ATG and AFS just for use with VS so it would be great to have more support for that. I only see half a page on VS in ATG documentation :(
     
  37. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,858
    what kind of issue do you have?
    in case vegetation studio takes over the rendering afs and atg are just shaders.
    the setup of the materials does hardly change no matter if you use the grass manager (atg), place foliage as single game objects (afs) or vegetation studio.
     
  38. Kaen_SG

    Kaen_SG

    Joined:
    Apr 7, 2017
    Posts:
    206
    My issue is that everyone wants to be the king.... i mean.. everyone wants to be used as the built-in deferred custom shader/reflection etc.... i mean ... everyone! Like AFS, ATG, Uber, etc.... they all want to be king.... I know AFS has a flag to handle uber integration... but ATG does not... and if I use ATG grass shader on the grass BUT switch the custom shaders to AFS for example.. the grass fails to render properly in VS (or elsewhere for that matter).

    upload_2018-5-27_19-27-34.png
     
  39. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,858
    i see.
    all my shaders use different subsets of the most complex deferred lighting which is defined by Lux Plus.

    afs: translucent lighting
    atg: translucent lighting + specular grass lighting
    lux+: translucent lighting + specular grass lighting + skin + aniso + area lights + diffuse only

    uber covers only translucent lighting. so atg grass does not have a compatibility mode.
    and in case you use atg along with afs you should assign the atg deferred lighting and reflection shaders.
     
  40. Kaen_SG

    Kaen_SG

    Joined:
    Apr 7, 2017
    Posts:
    206
    Ok... So I did not fully understand what you meant... but you mentioned Lux+ so I went and tried it. Seems like Lux is compatible with ATG and AFS lighting/translucency.... and using it as the custom shader allows me to use ATG and AFS in the same scene with no issues in editor.... however... after I build them into binaries... I lose translucency on the foliage somehow (ATG Foliage shader).

    Both binaries/scenes are using the EXACT SAME "02 Full Demo" from the ATG asset.

    The only differences are that one build is using "ATG as the custom/reflection shader" and the other build is using "LUX Plus as the custom/reflection shader"

    ATG used as "Custom/Reflections/DepthNormal" in Editor (Grass/Foliage Looks OK)
    upload_2018-5-30_21-58-5.png
    upload_2018-5-30_21-58-57.png


    LUX Plus used as "Custom/Reflections/DepthNormal" in Editor (Grass/Foliage Looks OK)
    upload_2018-5-30_21-54-37.png
    upload_2018-5-30_21-55-20.png

    Continued in next post as image limit reached.
     

    Attached Files:

    Last edited: May 30, 2018
  41. Kaen_SG

    Kaen_SG

    Joined:
    Apr 7, 2017
    Posts:
    206
    However, after building them into Win64 binaries for testing... here's how they look.

    ATG Win64 Binary
    upload_2018-5-30_22-6-10.png
    upload_2018-5-30_22-6-34.png

    LUX Plus Win64 Binary
    upload_2018-5-30_22-7-42.png
    upload_2018-5-30_22-8-45.png

    Transparency on ATG Grass looks fine however Transparency on ATG Foliage looks opaque/broken.
    These are exactly the same scenes with just the Custom/Reflection/DepthNormal Shaders switched and built into Win64 Binaries.

    The Win64 Binaries are included here if you would like to test this yourself. Built with 2017.4.3f1 LTS as shown in the earlier screenshots
    https://drive.google.com/open?id=1vaYcI2MS1g-qg-pTrpm8ACdbkZklOHjG
     
  42. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,858
    to me it looks as if lux somehow ignores translucency...
     
  43. Kaen_SG

    Kaen_SG

    Joined:
    Apr 7, 2017
    Posts:
    206
    But it works on ATG Grass Shader Base... (although it appears a bit discolored) how come it doesn't work on ATG Foliage Shader at all?
     
  44. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,858
    hmm, i saw this in your executables. but when i ran out a build from my lighting test scene lighting is fine and looks the same as in editor. but that is 5.6.3....

    left build / right editor
    lixlighting.PNG
     
  45. Kaen_SG

    Kaen_SG

    Joined:
    Apr 7, 2017
    Posts:
    206
    Could this be a 2017.4 issue?
    Are you using ATG Foliage Shader on the fern? (because I am not using Lux shaders on the grass/plants)

    Could you maybe put ATG/Lux Plus in a 2017.4 project and do the same steps I have. "Lux Plus custom shaders/reflections/DepthNormals" and run the "02 Full Demo" from ATG. And build that into Win64. If that works fine on your end... maybe it's something I did.
     
    Last edited: May 30, 2018
  46. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,858
    yes.
    i do not think so as the shader compiler only changed in 2018.
    but who knows...
     
  47. Kaen_SG

    Kaen_SG

    Joined:
    Apr 7, 2017
    Posts:
    206
    Is there anything else I can try then?
     
  48. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,858
    you could try 5.6.5
     
  49. Kaen_SG

    Kaen_SG

    Joined:
    Apr 7, 2017
    Posts:
    206
    I have v5.6.1 installed.. i'll try that.. but it doesnt help me much coz many of my assets require 2017+
     
  50. Kaen_SG

    Kaen_SG

    Joined:
    Apr 7, 2017
    Posts:
    206
    upload_2018-5-31_5-44-45.png

    on 5.6.1.... again it looked ok in editor.... is there some setting i'm missing?