Search Unity

[Released] Advanced Terrain Grass

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

  1. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    585
    Lars, in respect to this forum thread where everybody talks about the (hopefully coming) new terrain system, would you mind sharing your crystal ball thoughts on it? Do you think your shaders will always work with a new terrain system? Or will Unity break it in such a way that we have to rethink just everything? Or do you expect just internal changes without much changes on the "outside"? I'm in the process of creating my "ideal setup" which includes Lux Plus (for skin shader and just everything at all. :) ), hoping I can create something enduring. I think your thoughts on this would help me. Thanks.
     
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i do not think that a new terrain system is coming in the nearby future.
    and as nobody knows how it will look like i can't say anything about possible compatibility issues, sorry.
     
    OfficialHermie likes this.
  3. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    585
    Whenever you say "today's update" (I see that you write this often), you mean the version that you submitted today or the version that can be downloaded today?
     
  4. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    585
    You mean you have the "allround solution" in the pipeline already?
    Then I would like to purchase this instead of another single asset, please. :)
     
    Last edited: Nov 27, 2017
  5. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    no, i have not.
    but afs and atg as well as cti are compatible with lux plus.
    and afs and cti are compatible with atg.
    as far a deferred shading and lighting is concerned.
     
  6. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    585
    Thanks. I trust you very much. Purchased.
     
  7. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    585
    Would you mind sharing a screenshot of your settings? Looks really great!

    How did you get the light to not look overly bright?
     
    Last edited: Nov 28, 2017
  8. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    @hermie i just read your review. thanks for the 5 stars :) but it seems that you had some problems regarding fps.
    please keep in mind that we can't draw 20 single grass prototypes per patch as fast as the terrain engine does as latter combines all into one single mesh (spike!).
    atg addresses this issue by introducing merged and soft merged layers.
    if you use this feature widely – combined with 2 step culling – your initial fps should be (nearly) back but without the spikes on the CPU.

    Edit: I had a customers terrain using 8 prototypes used a simply mixed all over the terrain. Built in grass ran at about 240 fps (and some heavy stuttering), after switching to atg i had only 180 fps left. Using soft merging layers i finally got stable 360 fps.
     
    Last edited: Nov 28, 2017
  9. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    585
    I changed my review once I noticed that I simply need to invest more time into using ATG.
    Thanks for the hints, I will keep them in mind when I find the time to learn how to use ATG.
    I was expecting a drop-and-enjoy effect.

    Do you think it would be good idea to create a video that shows how to apply ATG to one of the most used nature assets (MK4 Nature) which uses a massive amount of different gras / flowers?

    mknature1.png

    I'd profit a lot from it, and I guess others will, too.
     
    Last edited: Nov 28, 2017
  10. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    simply set e.g. layer 2: merge into: 1, then check: soft merge, layer 3: merge into: 1, ...
    finally create the needed texture array, set the material of layer 1 to use the array shader and assign the texture array. done.
     
  11. zmaxz

    zmaxz

    Joined:
    Sep 26, 2012
    Posts:
    143
    I update to ATG1.04 ,my grass color change to white.
    How to fix it ?
    Unity 5.6.3p3 Rendering Path: Deferred
    ATG104.jpg ATG103.jpg
     
  12. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    585
    Does anybody have a good solution for "uneven" textures? ATG (or better: Unity's 2D texture creator) requires that the texture size must be of the same and with the same width / height. The textures in MK4 Nature Pack are not all 1024x1024, but some are 256x512, some are 256x256... Perhaps I will in some days laugh about this problem.

    I can resize 512x512 to 1024x1024.
    But I don't know what I should with textures that are for example 256x512.

    Can somebody help with an advice?
     
    Last edited: Dec 1, 2017
  13. MarkusGod

    MarkusGod

    Joined:
    Jan 10, 2017
    Posts:
    168
    Slap another 256 pixels to the top?:)
     
  14. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    585
    So that the "original" texture is located bottom left? Or where should the original texture go?
     
  15. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i guess you are talking about merging layers and creating texture arrays for that.
    so in case you have several grass prototypes using 256x512 you may consider only merging these together as they will most likely use an upright oriented rectangle to be drawn instead of a quad. extending these texture to 512x512 and using a quad would be a waste of fill rate.
     
    OfficialHermie likes this.
  16. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    585
    When I follow your info and your tutorial, and I assign the Grass Array Shader, it always shows the very first texture of the Texture2DArray.
    I've recorded a video here:



    Please take a look rather at the end. There you can see how the texture should be something with red leaves, and when I assign the Grass Array Shader, it shows the very first texture instead of the one with the red leaves.

    What am I doing wrong here?
     
  17. Aubrey-Falconer

    Aubrey-Falconer

    Joined:
    Feb 13, 2008
    Posts:
    438
    Greetings @larsbertram1! I am experimenting with ATG in a MapMagic-runtime-generated terrain context. I am currently subscribing to MapMagic's OnApplyCompleted delegate, and adding a new
    AdvancedTerrainGrass.GrassManager component to each terrain tile immediately after it is generated. This approach doesn't work during runtime, with GrassManager throwing a number of "ArgumentNullException: Argument cannot be null." errors in it's DrawGrass method.

    I am assuming that some form of manual GrassManager init is needed - but don't see an example of what this might be in the GrassManagerEditor code. Do you have any suggestions for me?

    I also use a floating origin system, and noticed your documentation note that "ATG currently does not support to reset the world’s origin and move terrains around to handle floating point issues". What would I need to do to make this work? If necessary, it would be workable for my use case to destroy and recreate all ATG vegetation in scene after shifting the origin even if that involves a performance penalty.
     
  18. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    the init function creates all the grass cells, copies and merges the grass density maps from unity's built in format to my own super simple 1d byte array. it also copies the height data from the terrain in a custom array – in order to get rid of all the garbage you get when calling unity's built in functions like getinterploatedheight or getdensity and make it possible to do all the hard work on a worker thread.
    you will have to call the init function, whenever a new terrain is ready – but unfortunately that is super slow and takes up to several seconds – the reason why you may bake that data in the editor.
    it might be much faster to bypass unity's terrain and get the data directly from map magic.

    you will have to move all spheres of the associated culling group to the new positions, so culling will work properly.
    as well as update the cell's and cellcontent's center position (as they are used by the bounds passed with the drawmeshindirectinstanced command and influence culling as well).
    finally you would have to either recalculate the matrices... (super expensive as we are talking about >100.000 matrices here) or tweak the shader:
    just introduce a global float2 value: GlobalShift.xy. that will be set by script for all terrains and contains the distance to the original pivot. then in the vertex function of the grass shader you finally add this to the vertex position v.vertex.xz += GlobalShift.
     
  19. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i will always show the first texture of the array as unity's preview sphere does not contain any information about which layer to show.
    depending on the mode you have selected (random, bysize, softmerged) the shader expects certain inputs or calculates the layer itself based on position or size. but all these are always the same in the preview window, hence you always see the same texture.

    but watching your video i might have spotted some other basic misunderstanding:
    if i saw it right you merge all upper layers into layer 1. in this case only layer 1 (the very first one all others get merged into) needs the array shader. all other materials simply are not used at all. so it it worthless setting these up.

    i hope this helps to get things clear.
     
  20. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    585
    I did it now as you said, but FPS stays basically the same.

    Just to make sure I've follow your last advice correctly, I've set the shader of the no-longer-needed materials to something fancy so that I could see if they're still used and if I made any mistakes.
    They aren't used, so I guess I did it correctly.

    Do I need to do anything else?
     
  21. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    what are your fps? compared to build in grass?
    next you could setup 2 step culling.
     
  22. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    585
    I've recorded 2 more videos:

    1) Here you see how I merge the layers:

    2) Here you can see I've set the now-unused shaders to use the StandardShader without alpha, so if one of these would still be used, it would look weird right away (which it doesn't, so I think I did it correctly):


    My current FPS is around 90 while it was around 150 FPS with built-in grass.
     
  23. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    that is bad. so all i can think of is using 2 step culling more aggressively: skip more instances at far distances.
     
  24. Aubrey-Falconer

    Aubrey-Falconer

    Joined:
    Feb 13, 2008
    Posts:
    438
    Thanks @larsbertram1! Your information on the init and culling systems are exactly what I was seeking to learn. I may have a chance to write a custom MM vegetation output node over the next few weeks. If I do, I'll be delighted to share it.
     
    JohnTomorrow likes this.
  25. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    585
    Just a quick side note: Lars, can you make it so that those layers that are not merged with other layers are shown in a different color? Or some color structuring that quickly shows what is assigned to what? I spend so much time double and triple checking if I've set up everything correctly.

    Edit:
    Nevermind, I found my own solution: Proper naming like "1024x1024_grass9_OnLayer1" for a material.
     
    Last edited: Dec 5, 2017
  26. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    585
    I've tried the culling and Fade Length, but I only get the original FPS when I set the Cull Distance to 20 (which gives me like 5 metres of sight).
    The grass looks more beautiful than ever, but having 80-90 FPS without anything else going on in my scene on my not-so-bad computer doesn't really "help".

    Do you have any other ideas?
     
  27. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    have you already checked different "buckets per cell" – so that the cell size gets smaller or bigger?

    you may send me a stripped off version of your terrain. then i will have a look into it. all i would need is the rough terrain (height and size and all its settings – no textures needed) but including the grass. latter most likely just consists of a bunch of textures so either send them, obfuscate them or replace them by some simple textures containg just a color.
     
  28. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    @hermie,
    thanks for the package i had a look into your setup and came across several issues.
    • you have assigned a "saved terrain data". this will make most changes you do in the settings of the grass manager to have no effect. so in case you are tweaking these to find the best ones do not assign any saved terrain data and generate a new one when you have found the best settings.
    • cache distance was set to: 826m – that will kill your memory! set it to e.g. cull distance + cell size.
    • texture arrays have not been created properly.
    • texture mixmode on layer 5 and 8 was set to: random instead of softmerge
    so first i started to make atg look more or less like the grass rendered by unity's terrain engine by fixing the arrays and materials. i also had to change dry and healthy colors because they were pretty dark on the layer which all the others got merged into.

    then i raised the number of buckets per cell to 32x32 or even 64x64 and tata: fps were back.

    unity's built in grass gives me about 125fps.
    without any further tweakings atg runs at 170fps.

    raising the clip threshold from 0.3 to any higher number might give you even more fps.

    but the most important thing to speed up rendering would be to skip that flat quads.
    you do not have to repaint the terrain or anything. just replace the quad in the mesh settings of the atg layers by a simple mesh wich consist of e.g. 4–8 quads slightly spreaded over an area of maybe 20x20 cm. this will allow you to divide the density set in the grass manager by factor 4–8 while getting more or less the same visual impact and final density.
    doing so will make the gpu draw less but somewhat more complex instances which is just fine.
     
    Last edited: Dec 5, 2017
  29. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    this is the built in grass:

    terrain_hermie.PNG


    this is atg:

    atg_hermie.PNG

    actually atg grass looks denser – so you might even lower the density in the grass manger settings – however it does not let you match the "low" density of the terrain :(. even if set to 0.03 the grass looks more dense as the one rendered by unity while the fps go up to 210.
     
    Last edited: Dec 5, 2017
    OfficialHermie likes this.
  30. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    sorry i have missed thius one.
    does the problem still exist?
     
  31. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    585
    1) Should I press "Save TerrainData" each time I changed some settings?
    2) What do you mean by "Cell size"? Do you mean "Buckets per Cell"? If so, it would be Cull Distance (of let's say) 80
    + 32x32 Buckets per Cell = Cache distance 112?
    3) Can you explain what you mean by "Texture arrays have not been created properly"? I checked it for half an hour.
    4) Where do I set the Texture Mixmode?
    5) I don't understand your last sentence "Replace the quad" at all. Can you clarify? Sometimes your explanations are too simplistic (for me).
    6) When I set Grass Density to 0.03, the grass completely disappears for me.
     
  32. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    @hermie
    1) no you should safe it only when you are absolutely done – as it takes some while as well.
    2) cell size is the size of the cell in meters x meters. the script will prompt the cell size undr the "buckets per cell" dropdown.
    3) atg and built in grass did not really match. but that may have been caused just by the wrong texture mixmode. i recreated the arrays anyway just to make sure. for this reason i prefixed the texture names using 01, 02, 03 according to their layers so their order in the array will be correct: the export to array script will sort the selcted textures alphabetically.
    4) in the material
    5) now you draw all grass instances using a single quad (the default atg quad). but that is quite inefficient because you draw a lot but super simple instances (amd proposes to use instancing with something like meshes which contain 400 + vertices – you have 4). you could simply replace the quad in the grass manager inspector per layer and apply more complex mesh which might contain 4 or 16 or even 32 quads covering a little bit of space. doing so would you allow to lower the density in the grass manager which means that you draw less but more complex instances – which should be fine.
    6) for me it disappears at 0.02. 0.03 is the lowest possible value. but even if 0.05 worked for you you would not see much difference. i guess i will have to rework the script.
     
  33. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    simple example

    left: your current instance – just a single quad
    right: a bit more complex grass mesh consisting of 4 quads. using this instead of the single quad will either increase the visual density by factor 4 – or let you decrease the draw density by factor 4. latter would be the way to go as it most likely faster to draw 25.000 instance with 4 quads than 100.000 with just a single one.


    Bildschirmfoto 2017-12-05 um 20.04.05.png
     
  34. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    585
    Let me go through it one by one, please.
    You've renamed my textures to sort them alphabetically, but you left some out. Why didn't you rename them all?
    renamed1.png
     
  35. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527


    I love how the grass in this video moves, is it possible to achieve someting similar with ATG?
     
  36. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i renamed all i found on the terrain. maybe i have missed one or two.
     
  37. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i guess so, yes. a bit tricky will be the extra high frequent shiver when the gust runs through the grass – but atg already offers some kind of variation in frequency. it is a bit rough but super cheap to render.
     
    Lars-Steenhoff likes this.
  38. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    585
    "All I found on the terrain" means you took a look at the inspector under "Grass Manager" where "All Protoypes" are listed and then you went from there, right?
    Please be a little more precise. "All I found on the terrain" isn't really helpful.
     
  39. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i most of the time use the "single prototype" view as it gives you direct access to the material as well.
    but actually i looked at the all the prototypes that were listed in the atg manager, yes. 15 if i remember correctly.
     
  40. UnrealUnitySwinger

    UnrealUnitySwinger

    Joined:
    Dec 5, 2017
    Posts:
    2
    Could ATG be used with Awesomium Vegetation Studio or how could I get your nice foliage shaders to work in Vegetation Studio? I hope there's a way. Your shaders look the best.
     
  41. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527

    Thats cool, I'm mainly interested in the wind kind of effect.
    With use of a wind texture perhaps, like its done in the blog post here

    http://ellenack.com/2016/11/05/grass-geometry-shader/
     
    Last edited: Dec 5, 2017
  42. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    atg uses a wind textures which gets update each frame and reacts to your wind zone (strength, direction).
     
    Lars-Steenhoff likes this.
  43. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    585
    When I click "Single Prototype", I don't see the layer number.
    Can you make it so that one can see the layer number?
    Currently I can only view it in "All Prototypes" mode.
     
  44. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    right now atg shaders only work with atg. but i might think about writing a specal version for vegetation studio as well (although these will be less performant :) ).
     
    jdraper3 likes this.
  45. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    no problem
     
  46. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    585
    I will post ABSOLUTE NEWBIE (!!!) video tutorials here that show the entire process of my ATG setup along with MK4 Nature Pack (because I liked it, but I hated the speed).
    I'm a total newbie at this, so you'll see all the mistakes that I make. I hope it helps somebody.

    I will update this post when new videos have been uploaded:




     
    Last edited: Dec 8, 2017
  47. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    no, it's not way faster. In any way. I bought it because this was the promise (on this forum) but it is not true at all. If you use unity grass, the only advantage you get with ATG is that you remove the cpu spikes. That's good enough for most of us. But I guarantee it won't run faster than unity grass because Unity internally collect all grass and draws super fast. No script in the asset store can do that with billboard grass (unity grass) and trust me I've been hunting all assets (spent over $200 this month) testing every single one of them. Nothing runs faster than Unity grass.

    You only gain speed if you are NOT using unity grass. Meaning, if you are drawing 3d meshes. In that case you will increase speed because this system collects based on distance from camera and visibility and draws only those using instancing.

    Also, it does not have touch bending and although in the forum is said to "i'm looking into it" on private its been said that it won't be looked into for who knows how long.

    So to summarize to help everyone and avoid unnecessary bad reviews on the store because people didn't get what they expected:

    1) If you use Unity grass (billboards), get this asset if you have issues with CPU spikes. Otherwise you won't have any benefits. Speed is always faster with unity default system in that case.
    2) If you need touch bending (objects hitting a particular area of grass, etc...) you are out of luck until some announcement from the author.
    3) On the positive side: if you are using 3d meshes as grass, this package will speed it up noticeably if you have a gpu that supports instancing even more.
     
    Last edited: Dec 8, 2017
  48. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    how was the FPS improvement? a summary please, since i can't watch videos on my cellphone speed :)
     
  49. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    585
    I'm still in the process of recording the videos and showing what needs to be changed. Lars demonstrated in private that with tweaks it does improve the FPS very much. The problem is that Nature Package is not an easy asset to work with. That's why I'm recording the videos so that people can see what needs to be changed for such a "difficult package". Other packages might work easier with ATG, but I want to tweak THIS asset. I think it's a good learning experience. Lars helped me nicely in private.
    In fact, he gave me a complete walk-through over how MK4 designed his Nature Package and what wasn't done well in aspect of speed and thus needs to be changed to get good speed.

    As I said, I still need to record the videos.

    To be honest, I expected the asset to do all the work for me. But I quickly noticed that I need to engage my brain to get the desired results. On the other hand, it's a good learning experience. Unitys terrain engine isn't smart enough yet to figure out the best settings by itself, that's why you need to set some settings yourself. This (just like the Unity terrain itself) isn't a drop-in-and-you're-done asset. Lars, correct me if I'm wrong.
     
    Last edited: Dec 8, 2017
  50. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    that statement is a bit misleading.
    atg is faster as far as cpu usage is concerned.
    when it comes to rendering we are most likely limited by fill rate and bandwidth. as latter is concerned unity's built in grass might outperform atg if you do not set it up properly.
    as you have said: in case we are fill rate limited no script can speed up rendering as it is just the gpu that slows down grass rendering.
    i am looking into it. but i am not spending much time on that.
    touch bending is no core feature of atg nor has it been announced or advertised in any way – despite that "i am looking into it". there are a lot of other core feature i personally rank as more important to be revisited and which really touch the system itself. touch bending does not do at all. it is fully disconnected from what atg does right know and can be implemented by anyone in any way.
    but what i mentioned in our PRIVATE conversation was the fact that atg is not what one would call a financial success. i do not really gain any money from it. and now vegetation studio has entered the arena, is featured and sells like sliced bread. i could simply add more and more features but that won't change the whole story.
    atg already is faster than vs when it comes to grass. it uses way less resources (memory, gpu and cpu power) and offers more advanced bending and lighting. but who cares?
    so i will spend a decent amount of time improving the core and see how the race will develop before i get into adding completely new features.
     
    jdraper3 and Lars-Steenhoff like this.