Search Unity

[Released] Advanced Terrain Grass

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

  1. Zaki_X

    Zaki_X

    Joined:
    Jul 5, 2016
    Posts:
    55
    Hi Lars,

    I'm looking for the best solution for grasses and foliage (shader with transluency/fake transluency- deferred rendering). I've been browsing this thread and AFS' threads. From what I understand none of this solutions work with billboard type of grasses. Am I correct? So do I have to use prefabs of grass patches in order to get decent results? Shall I choose AFS or ATG? I assume that AFS replaces regular grass shader, but lets me use other solutions like RTP, CTS, GAIA etc.

    -Mike
     
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    yes, i do not like billboarded grass so i have never looked into it.
    you can use simple textures. but that would make the grass being rendered as simple quad -> most likely wasting a lot of fill rate. next to that: a simple quad will give you only a quite weak density per instance. consider having a a custom mesh with 4, 8, 12 planes instead: you will need only 1/4, 1/8 or even 1/12 of instances to create the same visual density. and drawing less but more complex instances should give you better performance.
    atg plays nicely with gaia. rtp or cts do not effect grass rendering at all. so i would go with with atg – as afs does not speed up rendering whereas atg most likely will. however atg will fail in case you use lightprobes or lightmaps: using indirectinstanced rendering does not support this right now.
     
    Zaki_X likes this.
  3. nbac

    nbac

    Joined:
    Jul 7, 2015
    Posts:
    267
    slowly i am figuring out how the merging is done. but how big can those arrays be. and is the order of the layers represented in the array like this: i merge layer 6 and 7 into layer 1 .. like in the demo so. the array first texture is layer 1 second texture is layer 6 and third is layer 7. if there is a fourth texture in the array it will be skipped?! as soon as i add layer 8 and merge it in 1 the fourth texture is used.
     
    Last edited: Jan 18, 2018
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    theoretically: 256.
    yes.
    yes, as no instance points to it.
    yes, that is the regulat behaviur of texture arrays: if your array only contains 3 textures and you try to sample the non existing 4th layer the shader will always fall back sampling the highest available texture – which is texture layer 3.
    all this is nothing specific to atg. it is just the way texture arrays work in any shader.
     
  5. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,526
    I'm trying it out on apple tv4k and get the following error in xcode:
    no errors in unity

    Code (CSharp):
    1. InvalidOperationException: Instancing is not supported.
    2.  
    3.   at UnityEngine.Graphics.DrawMeshInstancedIndirectImpl (UnityEngine.Mesh mesh, Int32 submeshIndex, UnityEngine.Material material, Bounds bounds, UnityEngine.ComputeBuffer bufferWithArgs, Int32 argsOffset, UnityEngine.MaterialPropertyBlock properties, ShadowCastingMode castShadows, Boolean receiveShadows, Int32 layer, UnityEngine.Camera camera) [0x00000] in <filename unknown>:0
    4.  
    5.   at UnityEngine.Graphics.DrawMeshInstancedIndirect (UnityEngine.Mesh mesh, Int32 submeshIndex, UnityEngine.Material material, Bounds bounds, UnityEngine.ComputeBuffer bufferWithArgs, Int32 argsOffset, UnityEngine.MaterialPropertyBlock properties, ShadowCastingMode castShadows, Boolean receiveShadows, Int32 layer, UnityEngine.Camera camera) [0x00000] in <filename unknown>:0
    6.  
    7.   at AdvancedTerrainGrass.GrassCellContent.DrawCellContent_Delegated (UnityEngine.Camera CameraInWichGrassWillBeDrawn, Int32 CameraLayer) [0x00000] in <filename unknown>:0
    8.  
    9.   at AdvancedTerrainGrass.GrassManager.DrawGrass () [0x00000] in <filename unknown>:0

    Anything that I'm doing wrong? Apple TV is supposed to support instanced shaders
    im running unity 2017.3 p2
     
  6. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    actually i do not know as i do not own an apple tv. as far as i can say it runs on metal (as i developed it using a mac book pro). but according to the error message instancing is NOT supported on apple tv.
    so i would call it a unity bug...
     
  7. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,526
  8. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    that is a pretty old page (unity 5.4).
    atg needs at least 5.6. and supports metal on os x.
    the docs of 5.6.3. list metal on ios to support instancing as well. but atg uses drawmeshinstancedindirect which might not be implemented properly by unity. so i would file a bug report.
     
  9. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,526
    Yes I got confirmation its a unity bug, It will be fixed in a patch release.
     
  10. JohnTomorrow

    JohnTomorrow

    Joined:
    Apr 19, 2013
    Posts:
    135
    Are there any plans to get ATG to work with MapMagic at runtime generation?
     
  11. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    not at the moment.
     
  12. Keysto

    Keysto

    Joined:
    Oct 9, 2014
    Posts:
    4
    Hello
    I'm trying to vertex paint the alpha and the color, but that does not seem to be working in 3Ds Max, or maybe I'm doing it wrong. Could anyone please post the workaround or a tutorial?
     
  13. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
  14. Keysto

    Keysto

    Joined:
    Oct 9, 2014
    Posts:
    4
  15. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
  16. Keysto

    Keysto

    Joined:
    Oct 9, 2014
    Posts:
    4
    Hello, how to paint vertex to make the stem bend. I noticed that alpha value on your nettle slightly increases to the top. But it doesn't work for my models. upload_2018-2-20_18-26-7.png
     
  17. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    actually that is the whole trick: set alpha to 0.0 at the bottom (no bending) and to somthing > 0.0 at the upper parts.
    what does not work for your models?
    how do they look like?
     
  18. Keysto

    Keysto

    Joined:
    Oct 9, 2014
    Posts:
    4
    I noticed that if i paint stem separately (alpha value of leaves = 0) it works but if i export both leaves and stem painted tha plant just expanding. Stem movements were unnoticeable even if the alpha difference from the bottom to the top of a stem was high. What am I doing wrong?
     
    Last edited: Feb 20, 2018
  19. AndyNeoman

    AndyNeoman

    Joined:
    Sep 28, 2014
    Posts:
    938
    Hi @larsbertram1 , Ive just added the ATG package to go with the AFS and the the tropical pack you do the shader for (CTI) and there seems to be some conflict. I didnt notice any information in the docs but the import replaces the CTI deferred reflections/shading and turns all my trees/foliage purple. If I overide and stop the replacement some of the grasses appear white.

    I really just want ATG for VS integration but when I assign my meshes the VS shader they disappear.

    Is there a way to make ATG work nicely with the tropical pack and VS?
     
  20. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hmm, i would apply just a single gradient from bottom to top as otherwise your plant may break apart.

    you may check the wind settings on the wind script and on the material your plant is using.
     
  21. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    when using the latest cti shaders along with the tropical forest pack the atg deferred lighting and reflection shaders should give you proper results for both grass and trees.
    you definitely have to use the atg shaders.
     
    AndyNeoman likes this.
  22. Darkmonk

    Darkmonk

    Joined:
    Nov 3, 2010
    Posts:
    50
    Hi,

    Im having some issues with the grass disappearing, about 75% of my terrain works fine but other parts the grass either does not appear OR all grass disappears, I have the Debug option on so i can see when it needs to init some cells but when im in an area where there is no grass it does not init the cells :( any idea what might stop them from initializing? its always in the exact same locations as well. here is a gif of the grass disappearing when i look left and right. http://www.onyxdigitalstudios.co.uk/Temp/GrassIssue.gif
     
  23. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    it does even stop drawing already initialized (and visible) cells...
    so have you checked if checking "ignore visibility" fixes this behaviour?
    unfortunately there are some serious issues as far as unity's culling groups are concerned.

    and have you checked the console for any errors? grass disappears right when the number of visible cells switches from 10 to 11.
     
  24. Darkmonk

    Darkmonk

    Joined:
    Nov 3, 2010
    Posts:
    50
    Thanks for the quick Reply :)

    Ive just found the problem and its fixed everything :)
    When i added the grass manager to the terrain it had not automatically setup 1 of the prototypes correctly, it was missing a Mesh object for some reason, only 1 was missing out of 9 different grasses I had assigned so not sure why this 1 did not have a mesh, I assigned the atg BaseQuad to it and now all grass draws correctly :)
     
  25. AndyNeoman

    AndyNeoman

    Joined:
    Sep 28, 2014
    Posts:
    938

    Thanks, I removed the CTI shaders and then the AFG are working ok. I am not seeing grass at the moment but i will work through the docs first to see if it is my setup error. I have just added the nettle and fern to VS to test and changed their shader to VS grass and nothing shows currently.
     
  26. AndyNeoman

    AndyNeoman

    Joined:
    Sep 28, 2014
    Posts:
    938

    Still having a problem. As I understand it for VS all you need to do is add the VS grass or foliage shader to the grass prefab and then add to VS. I have done this (and added deferred and reflections from AFG) but the grass does not appear. Camera is mainCamera. I sure it's me missing something silly but there does not appear to be anything to miss.... Trees and foliage using
    AFS and CTI shaders are working fine. Even grass prefabs using my AFS shader works fine. just the AFG my setup seems to not like.
     
  27. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    great!
     
  28. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    nope, you have to use the atg for vs shaders – otherwise you will not benefit from advanced lighting and bending of course.
    next to that the models from the atg package do store bending information in a different way compared to vs – so the vs grass shader does not work properly on these meshes.
     
  29. AndyNeoman

    AndyNeoman

    Joined:
    Sep 28, 2014
    Posts:
    938
    Sorry, that'ts what i mean. I have added the ATG for VS shaders but the preview image is blank and the grass does not show.
     
  30. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    sorry, i can not confirm this. which version of unity do you use? gpu?
     
  31. AndyNeoman

    AndyNeoman

    Joined:
    Sep 28, 2014
    Posts:
    938
    unity 2017.3. GPU is 660TI. It appears to be a shader issue because the grass is visible if I change shader to VS included grass shader instead of AFG grass shader.
     
  32. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    i will have a look into this as soon as possible.
     
  33. AndyNeoman

    AndyNeoman

    Joined:
    Sep 28, 2014
    Posts:
    938

    I have kinda of fixed it. Deleted shader cache and then reimported AFG and it is appearing in VS now. I am not getting previews showing up in the inspector on the materials but they are in game so no biggie. It is an outstanding asset btw. The lighting matching my trees and plants really joins the scene together.

    I am going to try and add rain effects like I have from your AFS shader and if a manage that at decent fps it will be perfection. :)

    Thanks for a great looking shader!
     
  34. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    i am glad you made it work.

    thank you!
     
  35. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    @larsbertram1
    I'm looking into making some terrain-based environments for cutscenes and looking up ground cover rendering brought me to your asset. Looks rad and seems to fit my needs visually.

    How does one go about making some terrain layers auto-filled with detail objects, as on your demo video? Is that a function of standard terrain system I overlooked, a solution your asset has introduced, or just a result of painstakingly moving your brush over kilometers upon kilometers of surface area (please don't say it's the latter :D)?

    I'm not sure if this question is precisely about your asset, as I'm not entirely familiar with the state and scope of standard terrain system - sorry if it isn't.
     
    Last edited: Mar 4, 2018
  36. AndyNeoman

    AndyNeoman

    Joined:
    Sep 28, 2014
    Posts:
    938
    Hi @larsbertram1 I don't know if you have plans to add some kind of rain effect to the shaders but i'd like to request the feature if possible.

    I have played around with adding myself from other shaders with rain but although i got it to work well in the rain it always seems to effect the grass when dry with strange effects.
     
  37. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    actually i painted it all manually. but you can fill your terrain using procedural tools like terrain composer or gaia – as
    atg simply reads in the grass distribution from the terrain.
    it does not have any custom authoring tools.

    concerning your 2nd question which you seem to have deleted: atg uses drawmeshinstancedindirect.
     
  38. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    i do not think that rain effects (rain drops) like in afs will come as they are simply too expensive and do not look very convincing on structures like grass or ferns. a simple wet effect however might come in future releases.
     
    AndyNeoman likes this.
  39. AndyNeoman

    AndyNeoman

    Joined:
    Sep 28, 2014
    Posts:
    938
    Yeah, I agree. I got it working like afs but the benefit is not the same because the structure is small. A darkening and specular effect would be really helpful for the scene though.
     
  40. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    fine that we agree :)
     
  41. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    @larsbertram1
    Just got the asset, really liking the implementation so far! Had two questions, though.

    1. Do I need to plug any custom lighting/reflection shaders into deferred rendering if I'm already using AFS deferred lighting/reflection shaders? I'm guessing you are probably using exact same wrapping and translucency functions and exact same deferred buffer layout as you did in AFS, but the documentation doesn't cover that case, so it doesn't hurt to double check.

    2. What might be the reason for one of your grass prototypes turning white in Play mode? It looks correct in edit mode, so it's not a case of a missing texture asset. That prototype seems to be using 01_Grass texture and continues to sample the alpha channel from it, but it somehow manages to lose albedo. Not sure how to debug this, since there is no way to inspect renderer state directly here.



    Update: After reloading the project today, this scene (full demo included with the package) no longer renders any grass in play mode. Other two scenes continue to work as before (quickstart has no issues and wind demo has exact same issue with same grass turning white). Reimporting the package changes nothing, full demo continues not to render any detail in play mode. Again, since these are not traditional inspectable renderers, I'm not sure where to start debugging this. Got any ideas? :)


     
    Last edited: Mar 7, 2018
  42. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    you have to assign the atg deffered lighting and reflection shaders.

    you have not assigned the atg shader, see above.

    hmm, the debug stats show: 0 visible cells. so most likely the culling groups return 0. you may try to check "Ignore visibility" and see if any grass shows up in play mode.
     
  43. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    So ATG replacement shaders have a superset of AFS replacement shader features, and I can continue using your AFS vegetation surface shaders when ATG takes over deferred rendering? I assume translucency packing, method of vegetation material identification and other vegetation related stuff is the same between AFS and ATG deferred replacement shaders.

    Out of curiosity, what did you have to change from the way AFS used to do things? Can't help but wonder what exact difference can create such an interesting side effect of "one grass object won't render albedo at all" while everything else continued to work perfectly, including translucency and all the other nice stuff deferred replacement shaders provide. :)

    Swapping the shaders seemed to help - Scene view shows nothing (as expected and mentioned by your docs), but Game view started rendering all grass correctly.
     
    Last edited: Mar 8, 2018
  44. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    yes, atg adds the possibility to get some specular reflections on grass. translucency is handled the same way though.
    and to answer your next question: atg uses a feature i introduced with lux plus which lets you control specular intensity in the deferred lighting shader. this is where the specular mask of the atg grass shader comes into play as it prevents grass from getting fully highlighted (due to their normals which are aligned to the terrain) and creates the illusion from more or less plausible specular reflections while keeping the nice soft shading.

    strange, as the shaders are not involved into culling... but i am glad it is working for you again :)
     
  45. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    The system is working great so far! Got a couple more questions, though.

    1. What is the significance of the following warning, which is spammed (a few dozen times at once, usually) from time to time in Play mode? I'm using Unity 2017.3, maybe something changed about the way compute buffers should be handled recently.

    Code (csharp):
    1. GarbageCollector disposing of ComputeBuffer allocated in C:\Work\Unity Projects\PhantomBrigadeCinematics\Assets\Packages\_AdvancedTerrainGrass\_Scripts\Classes\GrassCellContent.cs at line 94. Please use ComputeBuffer.Release() or .Dispose() to manually release the buffer.
    2. UnityEngine.ComputeBuffer:Finalize()
    2. Am I understanding correctly that pretty much every single change to Terrain should be accompanied by hitting "Save TerrainData" button on the Grass Manager? Documentation led me to believe TerrainData can be automatically updated on level load, but it doesn't seem to be the case. Not critical, I just hit it every time I edit detail splat maps and detail list, but it might be a good idea to add a warning about it for newcomers - failing to generate terrain data after changing detail list results in a null reference exception when you start play mode, with grass not loading at all, which can be confusing to some. The workflow can probably be streamlined by hooking to Edit Mode OnDestroy or other Edit Mode unloading/Play Mode loading event and updating the terrain data in there.

    3. Since grass manager is not managing the shaders in materials (which I'm thankful for, too many third-party systems mess with project assets without your explicit input :D), it might be worth warning users about inappropriate shaders being used on detail objects. For example, for a while I was stumped by white flowers never appearing in Play mode - until I realized they used a material set to array-driven shader from your demo scene while detail settings were not using soft merge (which caused a different texture map to render when ATG never accessed slice index on that grass type). A simple shader name check and EditorGUILayout.HelpBox calling out incorrect shaders could help catch cases where soft merge is enabled but shader is not array-driven, and vice versa, preventing confusion. :)
     
  46. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    that should not happen at all. compute buffers have to be disposed manually – which usually gets handled by the release cell function.
    i do not recommend to use baked terrain data – unless you are more or less finished with decorating and sculpting the terrain.
    otherwise: yes, whenever you change the heightmap (sculpting) or paint some grass you have to rebake the data.
    i will look into this. thanks for your feedback.
     
  47. DirtyHippy

    DirtyHippy

    Joined:
    Jul 17, 2012
    Posts:
    224
    I've been playing with ATS grass prefabs in VS. I assigned the deferred ATS shaders, and duplicated the grass prefab and its material, assigned the VS shader to the new prefab, and dropped it in as a grass prefab in VS. That works fine and it looks correct. However, with no ATS wind component I receive no wind, so I dropped in the ATS wind prefab (and removed the existing windzone and re-assigned the VS wind zone to the ATS prefab). However, the grass appears to translate on the X-Z plane by the wind rather than pivoting.

    What am I doing wrong?
     
  48. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    that sounds as if the bending information stored in the vertex colors of the mesh and the chosen "Vertex Color Mapping" in the material do not match.
     
  49. DirtyHippy

    DirtyHippy

    Joined:
    Jul 17, 2012
    Posts:
    224
    Duh, yeah that was it. Thanks!
     
  50. DirtyHippy

    DirtyHippy

    Joined:
    Jul 17, 2012
    Posts:
    224
    Is there any way you could remove all the warnings in ATS and AFS? Your stuff is great, but every release I have to go in and pragma or comment that stuff out. Some warnings are important and the minute you start ignoring warnings is the minute they become noise and worthless. It would just take a few minutes of your time and then in the next release, all gone!

    Thanks!