Search Unity

[Released] Advanced Terrain Grass

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

  1. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    I'm having a strange problem: I changed the Dry Color on a grass material, but at runtime, it still uses the previous color setting, even if I refresh the grass. But then if I go to the Grass Manager on the terrain and click on the material in the inspector to check the color -- then when I refresh the grass, it changes to the correct color. Most odd. All I'm doing is clicking on the grass material n the Grass Manager inspector. Actually come to think of it, I'm clicking on the material for a different grass, not the one that I'm trying to check. But somehow that tells Grass Manager to use the color from the material instead of....some cached color setting, I guess?

    Any suggestions on how to make it recognize the color to begin with? (I've got Freeze Prototypes enabled, and am using the correct method to refresh the grass. Unity 2018.2.14)

    And in a build, there's no way to select the material, of course, so I'm stuck with the previous color.

    EDIT: Actually, it is the material of the first prototype in the Grass Manager that I have to click on in the project to trigger the colors to be changed when I refresh the grass.

    thanks!
     
    Last edited: Dec 14, 2018
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    if you have freezed size and color then the grass manager should not change the dry and healthy colors at all when hitting "get prototypes".
    and i have not been able to reproduce this problem so far.
    any more info i would need?
     
  3. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    I can show you on Skype if you have time.

    It really does seem like it is using a cached color. If I adjust the Dry Color on the material, it does not change in the game until I click the first prototype's material -- which then alters the color, and from then on, color changes appear instantly in the game, but that is not helpful because I can't do that at runtime. So in effect, I'm unable to change the grass colors at all....

    EDIT: I've confirmed this by changing the Dry Color on the material, then pressing Play...and the color is still what it was before. It's just not reading the color from the material at all.

    EDIT2: So it seems I have this problem only in my main game scene where the terrains are loaded (and unloaded) in additive scenes. I don't have it in a setup scene with all the terrains there at runtime. So that's odd. More confirmation that it's using cached data in the main scene: The wind settings are old/incorrect until I select the first prototype's material, then they update based on the material's actual settings.

    So does that help diagnose the problem -- the fact that it only happens with additive scenes? (I have not done the Save TerrainData option in grass manager -- tried that once and grass simply didn't render at runtime, and it didn't seem necessary anyways.)
     
    Last edited: Dec 15, 2018
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    dirty fix provided via skype.
     
  5. VictorKs

    VictorKs

    Joined:
    Jun 2, 2013
    Posts:
    242
    Does ATG pick up grass from Vegetation Studio? Or do I need to spawn directly on the terrain? And are the two assets compatible?

    I need ATG for its advanced lighting features which look really awesome but how do I go about it like do I use VS for Trees and ATG for Grass?
     
  6. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    Version 1.1 now is available.

    Change Log

    # Grass Manager Script & Editor: Editor preview added.
    # Grass Manager Script & Editor: Safe guard for maxBucketDensity removed resulting in less memory consumption.
    # Grass Manager Script & Editor: "CullingGroup Distance Factor" added, which helps fixing popping in grass instances.
    # Grass Manager Script: Improved random generation.
    # Grass Manager Script: Improved height map sampling.
    # Grass shaders: Shadow caster and soft merge fixed.
    # Grass shaders: Added Depth Prepass variants - which may significantly improve performance. Please have a look at the docs to find out more.
    # Grass and folaige shaders: Added support for VegetationStudio Professional.
    # ConfigTerrainGrassShaders Script: Added which configures some proper fading values right when you load the project.
    # SetupATGCulling Script: Removed.
    # Grass Manager Editor: Improved preview thumbs.
    # BOTD Assets Demo added.
    # Documentation updated. Please read it carefully.
     
    gecko likes this.
  7. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    you can use the ATG shaders along with VS. in this case VS would spawn the grass and render it. if you want to use ATG for rendering you will have to "paint" grass distribution or use other tools such as terrain composer or gaia.
     
  8. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    How do I select the DepthPrepass shaders? They are not listed in the shader pulldown on the material.

    Oh, there's an error on the shader (shown in the inspector panel):

    syntax error: unexpected token '(' metal unityInstancing.cginc:188

    On 2018.3f2, MacBook Pro.

    EDIT:
    And now I've got another problem -- when I load a scene with Grass Manager on terrains, Unity locks up with the spinning disk and these two entries in the Console over and over and over again. Any idea what's going on?I deleted the ATG scripts folder, then reimported it, but the same thing happens.

    Max Bucket Density: 16
    UnityEngine.DebugLogHandler:Internal_Log()
    UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    UnityEngine.Logger:Log(LogType, Object)
    UnityEngine.Debug:Log(Object)
    AdvancedTerrainGrass.GrassManager:Init() (at Assets/_AdvancedTerrainGrass/_Scripts/GrassManager.cs:938)

    (Filename: Assets/_AdvancedTerrainGrass/_Scripts/GrassManager.cs Line: 938)

    Max Instances per Layer per Cell: 4096
    UnityEngine.DebugLogHandler:Internal_Log()
    UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    UnityEngine.Logger:Log(LogType, Object)
    UnityEngine.Debug:Log(Object)
    AdvancedTerrainGrass.GrassManager:Init() (at Assets/_AdvancedTerrainGrass/_Scripts/GrassManager.cs:944)

    (Filename: Assets/_AdvancedTerrainGrass/_Scripts/GrassManager.cs Line: 944)
     
    Last edited: Dec 17, 2018
  9. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hmm, i haven't checked the new editor preview feature with more than 2 terrains in a single scene.
    how many do you have?

    you may simply get rid of this misbehaviour by commenting "[ExecuteInEditMode]" at the top of the grass manager script.

    i will have to look into this, sorry.
     
  10. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    I have 64 terrains, and commenting out that line solved it, thanks!
     
  11. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    well, 64 terrains in one scene will make unity initialize all 64 terrains as soon as you open the scene: read in the height maps, read in the density maps, ...
    as long as compute is deactivated unity should be able to get this job done at least – however: it will take a while.
     
  12. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    yeah, in the game scene, the terrains are loaded in additive scenes, so only 9 at a time. This is just my setup scene.
     
  13. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    Version 1.101 fixing the metal error in the DepthPrepass shaders is on its way.
     
    gecko likes this.
  14. AndyNeoman

    AndyNeoman

    Joined:
    Sep 28, 2014
    Posts:
    938
    Hi @larsbertram1 Is ATG working with vegetation studio? I have imported the latest store version, selected ATG/VS/Grass base shader but my grass is now purple. IS there other setup required? IF I changed shader to VS shader prefab works so its not that.
     
  15. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    it works fine for me and vs pro.
    simply try to reimport the atg vs shaders. they should not be purple at all.
     
  16. AndyNeoman

    AndyNeoman

    Joined:
    Sep 28, 2014
    Posts:
    938
    Reimported and still not working. Now they are just blank. Is there anything else you do other than select the VS ATG grass shader. I am having no issues with any other shaders, including your CTI shaders which I use for plants.
     
  17. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    so no purple and no error?
    then you should be fine. you may try to add the atg wind script to your scene tho.
     
  18. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    I'm also having trouble with the ATG shaders in VSP. For me, the grass simply doesn't render with the ATG/VS grass base shader. In the prefab preview window (in 2018.3), the grass is transparent when I switch to the ATG/VS shader, and doesn't render at all via VSP. If I switch to VS grass shader, then it does render. I can see that VSP is *trying* to render it, as the FPS drops significantly when using Instanced Indirect (due to poor Mac implementation), but I can't figure out why it won't render. I've got the ATG update from last week and latest VSP. Any suggestions?

    thanks
     
  19. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    have you edited the grass material and checked "Ignore Fading (VS Pro)"?
    vsp seems to have dropped fading out grass and does not provide proper inputs as far as i know. so you have to disable fading to make the grass show up. it works nicely in the vsp version i checked it which was one of the latest betas provided by a a client :)
     
  20. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    Oh, right! That fixed it, thanks!

    Fading out: That's where grass gets less dense in the distance, right? (Not alpha fading)
     
  21. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    fine.
    nope, less density in the distance is a unique atg feature. fading in vs meant scaling down the grass instances towards the max draw distance - resulting in more or less the same visual result as alpha fading (but better performance because of less fill rate being used).
     
    gecko likes this.
  22. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    have you edited the grass material and checked "Ignore Fading (VS Pro)"?
     
  23. inferie

    inferie

    Joined:
    Mar 23, 2018
    Posts:
    39
    Hi, is there any compatibility problem with other grass/tree assets like "Meadow Environment"?

    Thanks in advance.
    AB
     
  24. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    missing vertex colors, missing textures - i really don't know.
    but adding vertex colors and creating the needed textures (translucency, gloss map) isn't any rocket science at all :).
     
  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i had a look at the "Meadow Environment": vertex colors seem to be just fine. so all you would have to set up were the special textures (translucency, gloss map) – which actually is quite easy :)
     
  26. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    Hi, I just bought the asset and testing it with the quickstart scene.
    But as soon as I added the grass manager to the terrain, this error shows up:

    NullReferenceException: Object reference not set to an instance of an object
    AdvancedTerrainGrass.GrassManager.Init () (at Assets/_AdvancedTerrainGrass/_Scripts/GrassManager.cs:868)

    I checked the script the null variable is an array, and it is never assigned with a value.
    Using unity 2018.2.20f1, linear color space, deferred rendering. And I've already assigned the deferred shaders in the graphics settings
     
  27. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    you can ignore this error. it does not do any harm – but will be fixed in the next update.
    it is filled by the editor script. but due to the new "Draw in edit mode" it might not be set right at the beginning.
    hitting "update grass" fixes this in editor.
     
  28. inferie

    inferie

    Joined:
    Mar 23, 2018
    Posts:
    39
    Oh thanks.
    A couple of questions.. is 2018 version of unity supported?
    I'm planning to integrate it with this stack gaia/cts maybe Vegetation Studio.
    Will it work?
     
  29. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    2018 should just work fine.
     
  30. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    ok, thanks for the explaination!
    One more question:
    I see in the doc says that the system does not support runtime generated grass.
    I'm using MapMagic to generate terrains in runtime, does it mean it will not work even if I add a grass manager to each terrain after it's generated? The system will not work with runtime generated terrains?
     
  31. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    that might actually work – but should be rather slow. the code that reads in the grass density maps and the terrain height map is not really "optimized" nor multithreaded.
    best would be to make map magic directly write into the data format as needed by atg. so no map magic -> terrain -> atg, but rather map magic -> atg. unfortunately i never had time to look into this.
     
  32. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    What kind of data structure does atg use for grass density and terrain height map? I can write my own output node for atg if needed. But mapmagic output data in threads, will need atg to be initialized before the terrain is generated so I can add data to it through threads.
     
  33. Gua

    Gua

    Joined:
    Oct 29, 2012
    Posts:
    455
    I want for the player to be able to dynamically spawn object on terrain. Can I dynamically remove ATG grass underneath it?
     
  34. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    the height map is a super simple (1D) float array:
    private float[] TerrainHeights;​
    when it comes to the density maps things get a bit more complicated. they are stored in a jagged array (prototpye or layer --> density (1D))
    private byte[][] mapByte​
    please have a look at the public void InitCells() function which reads in the density maps at start and creates the grass cells and cell contents. it also initializes some values like maxBucketDensity which is needed to calculate the size of the temp arrays and buffers used by the worker thread and the compute shaders.
     
  35. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    Last edited: Jan 2, 2019
  36. Gua

    Gua

    Joined:
    Oct 29, 2012
    Posts:
    455
    Why is ATG so dark compared to unity grass? Is this normal?

     
  37. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    it might be connected to healthy and dry color. then you should be able to fix it easily.
    if i look at your healthy and dry colors actually unity's grass look too bright. so when i pick your healthy color and multiply it on top of a grass texture i get a way darker result than what unity draws on the terrain:

    grass_colors1.jpg

    unlike unity grass however atg does not use simple lambert lighting – which of course also will change the brightness.

    but to make sure: switch to deferred (in case your camera does not use it), then select the normal preview in the scene view. grass normals should "fade" smoothly with the normals of the terrain.

    btw.: you are using different mix and max sizes for height and width – but atg only supports uniformly scaled instances.
     
  38. Gua

    Gua

    Joined:
    Oct 29, 2012
    Posts:
    455
    I do use deferred. So the correct approach is to roughly tweak health colors for each grass type in atg settings and try to make atg grass look approximately how it is rendered by unity? Is that the correct approach?
     
  39. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    the correct approach is to adjust healthy and dry colors so it looks good in preview or play mode: do not care about unity's grass rendering at all :)
    btw.: make sure you check freeze size and color in the grass manager.
     
  40. Gua

    Gua

    Joined:
    Oct 29, 2012
    Posts:
    455
    Got it. I care about Unity grass, because most of the time this is what I will be looking at. Since preview of ATG grass doesn't work when Game window is not visible. So I need it to look as close as possible to what will player see. Also ATG preview changes position of my main camera making changes to Player prefab instance which I don't like. I can even see light from a flashlight that is parrented to my main camera in scene view



    I also care about Unity grass colors because, I've spent a lot of time trying to match atg grass colors manually, but currently I like the look of Unity grass colors much more and for some reason I'm not able to achieve that look with ATG. Unity grass rendering gives more vibrant colors and seem less flat.

     
  41. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    as i mentioned before: unity's grass colors seem to be way off regarding healthy and dry colors.
    this is a small but not game breaking limitation i think :)
    it should reset the camera position properly if you exit preview mode.
     
    Last edited: Jan 3, 2019
  42. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    no way, sorry. if so you are doing something totally wrong.
     
  43. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    but i am open to discuss a better workflow.
     
  44. Gua

    Gua

    Joined:
    Oct 29, 2012
    Posts:
    455
    I just don't have space in unity interface to have game view constantly open. That's why when I will work in editor I will usually be looking at unity grass. Also having both scene view and game view opened, creates a noticeable hit on performance.

    It doesn't
     
    Last edited: Jan 3, 2019
  45. Gua

    Gua

    Joined:
    Oct 29, 2012
    Posts:
    455
    One new issue that I have with ATG that doesn't happen with unity grass. Is that it strangely reacts to spotlight under certain angles and positions. Making some parts of grass look very dark.

    My game


    Modified atg test scene
     
  46. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    please check the normals (either using scene view or game view and the frame debugger). unlike unity grass atg bends the normals in the wind, which here might cause the dark lighting.
    the amount of bending can be defined per material.
     
  47. Gua

    Gua

    Joined:
    Oct 29, 2012
    Posts:
    455
    Yeah. Setting bend normal to 0, makes this darkness go away. Is there any other workaround to not sacrifice grass movement?
     
    Last edited: Jan 4, 2019
  48. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    bending the normals only influences lighting. not the movement.
     
    Gua likes this.
  49. Gua

    Gua

    Joined:
    Oct 29, 2012
    Posts:
    455
    If you do take feature requests for future versions. Then I would love to see a simple method to remove grass underneath the object. Maybe even a component that works similar to Nav Mesh Obstacle but for atg grass.
     
  50. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    we will see.