Search Unity

Advanced foliage shader [released]

Discussion in 'Assets and Asset Store' started by larsbertram1, Apr 24, 2012.

  1. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,687

    Version 3.02 is available!



    Version 3.02 is now available – including physically based shading, physically based wetness, image based ambient lighting, advanced multi touch bending, ground lighting and enhanced billboarding for terrain trees


    The advanced foliage shaders gives you the possibility to use all modern features of vegetation shading on imported, handmade models – be it on top of the terrain or any other arbitrary geometry.

    Watch the shaders in action
    all shaders: http://dl.dropboxusercontent.com/u/2...demoscene.html
    touch bending: http://dl.dropboxusercontent.com/u/2...nding_202.html
    ground lighting and manually placed grass objects: https://dl.dropboxusercontent.com/u/...dlighting.html
    tree and billboard shaders: https://dl.dropboxusercontent.com/u/...reeShader.html

    Get them here
    http://www.assetstore.unity3d.com/#/content/3253

    Key Features
    * Optimized for performance: Just 1 material per object = 1 draw call. Support for static and dynamic batching, occlusion and layer based culling as well as LODs. Combine Meshes statically or at runtime to increase performance and draw whole clusters of plants within a single draw call.
    * Unmatched visual quality: The shader not only enhances the visual quality of plants manually placed as game objects but also to your plants placed within the built in terrain engine. Plants are added as detail meshes and support all lighting features except from casting shadows.
    * Some more realism: Apply touch bending to any plant placed as single game objects to let it interact with your player and npcs.
    * Easily setup your models following the step by step instructions.


    Simply paint your plants on top of the terrain or any arbitrary geometry

    Make sure you get the free "Geometry Brush AFS" tool: a very nice and handy tool that will help you to manually place any game object onto any terrain or geometry – originally posted by Matt McDonald, Owner, Chief Creative Officer and President of Heavy Water, www.heavyh2o.com, but optimized for the use with the advanced terrain shaders.
    https://dl.dropboxusercontent.com/u/...1.unitypackage


















    Changelog
    (version 2.04)
    Enhanced billboarding for terrain trees.
    Place terrain trees even on arbitrary meshes and benefit from the built in billboarding
    AFS Foliage Tool improved.

    Changelog (version 2.03)
    Enhanced wind animations.
    Get much more variety when using the AFS Combine Children script - like bending according to the instance’s size.
    AFS Foliage Tool improved.

    Changelog (version 2.02)
    Improved Touch Bending.
    Advanced Grass shader added.
    Advanced Foliage Shader supporting ground based lighting added.

    Changelog (version 2.01)
    Improved Wind Variation.
    Fixed: Specular Power now also works on plants placed within the terrain engine

    Changelog (version 2.0)
    Touch bending added.
    Improved wind bending.
    Specular power added to simulate wet effects.
    Minor fixes and enhancements.


    Old demo (version 1.0)
    http://bit.ly/K0osHC

    The old demo shows some other plant models like maple sapplings, blackberry bushes, weed and nettles all rendered with the advanced foliage shader (both: placed as single game objects and placed within the terrain engine) next to the new grass shader which allows even complex geometry without any restrictions in uv mapping.

    lars


    Hotfix for version 3.01
    (or upgrade to version 3.02)

    if grass disappears on your terrain (which happens if you have multiple terrains or move the one you have from 0,0,0 to any other position) you unfortunately will have to edit and fix the the "AfsWavingGrassTerrainEngine v3" shader:


    find:
    fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * IN.color;
    o.Albedo = c.rgb;

    and replace it with:
    fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
    o.Albedo = c.rgb * IN.color.rgb;

    not perfect but it will make the grass show up again.
    next version will come with a "real" fix. ​

    Attached Images
     

    Attached Files:

    Last edited: Jul 28, 2014
    Gozdek and BrandyStarbrite like this.
  2. MakeshiftPancakes

    MakeshiftPancakes

    Joined:
    Apr 24, 2012
    Posts:
    8
    Looks pretty sweet!
     
  3. fallingbrickwork

    fallingbrickwork

    Joined:
    Mar 16, 2009
    Posts:
    1,072
    Sounds interesting indeed. Can't wait to get to the office and check it out properly

    Matt.
     
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,687
  5. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,517
    Awesome just awesome. Now this isnt imitation of Cryteks shader, but this is one step beyond already especially for Unity users, becouse we can use AO and Cryengine users cant:D Lars one question though....How do you bake AO to vertex color alpha, if wind bending is already using it, or isnt it? Could you please explain shortly how do you bake AO in vertex color alpha with max for example?
     
  6. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,687
  7. Schlumpfsack

    Schlumpfsack

    Joined:
    May 30, 2010
    Posts:
    607
    why are you so awesome?
     
  8. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,517
    Isnt his fault, he was probably born that way:p


    Thanks for AO link, i will defenetly test it somewhen soon.
     
  9. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,687
  10. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,687
    added some more words of explanation to the first post…
     
  11. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,588
    I've been playing with this stuff all night. Integrating it into our sandbox mmo project. And this is what I've come up with!



    Damn Lars you've done it again, this stuff is awesome! It really helps bring the scene to life. :)

    I did some tweaks here and there, specular lighting is scaled down to 0.3 I could have fixed the ferns in photoshop too but they were practically glowing in my setup. I'm not sure 0.3 is the right number but 1.0 is certainly too high for my taste.

    When recording at a fixed frame rate the leaf wave timing got seriously bungled by the SetupFoliageShader.js script. Line 36 should be changed to:
    Code (csharp):
    1. var WindRGBA : Color = Wind *  ( (Mathf.Sin(UnityEngine.Time.time * WindFrequency) + Mathf.Sin(UnityEngine.Time.time * WindFrequency * 0.975) )   * 0.5 );
    So that it uses game time rather than real time. That does the trick both for recording at fixed frame rate and allows people to use stuff like bullet time. :cool:

    I've tossed the docs to Whatevernix who does all our models, can't wait to see the plants he'll cook up with this stuff... :cool:

    I give it both thumbs up, samples work out of the box and they're straight to the point. Showing both usage with terrain and without. After looking at the ferns without shadows I decided to implement it without the terrain too, but I left the code in there so we can use the Terrain version on slower systems. The grass and mountain terrains are rendered with tweaked versions of the first splat in the shader. Mountains uses multiply between scaled layers, grass uses simple addition!

    Cheers,
    UnLogick
     
    Last edited: Apr 28, 2012
  12. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,588
    Just got a mail from Lars asking how the hell I managed to mess up his nice shader. (Well not really but he politely pointed out that something looked a bit off.) Turned out that I was using some of his old resources along with his new shader. *Mental note: always delete old packs when importing new ones!*

    This is how it was supposed to look:


    Don't forget to change it to 1080 HD!

    @Lars: Thanks for the heads up. :)
     
  13. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,687
  14. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,517
    Nice plants you got there man, also very good ground texture.
     
  15. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,687
    thanks janpec!
     
  16. mk1978

    mk1978

    Joined:
    Dec 27, 2009
    Posts:
    276
    Nice plants, ground textures, trees, atmosphere and everything!

    Have you ever considered making a tutorial? I mean that I wouldn't mind paying for tutorial for making this kind of environments.
     
  17. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,517
    Thats what i already suggested to lars on his WIP topic, making tutorial for plant creation, terrain and generaly environment would be very much needed for beginners to plant modeling, becouse after all making good environment is not easy at all. There are already some good costly tutorials out there but nothing for Unity and this shader. So to make win-win situation it would be good to promote your shader with getting some tutorial up.
     
    x_african_warrior_x likes this.
  18. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,687
    @mk1978: i have already written 2 tutorials: one on terrains (pretty old by now… but it still contains some useful information about performance) and the other about the tree creator and i think i have already said all i can as far as unity’s terrain engine is concerned...

    the most important things about terrain creation are:
    - good references
    - good assets
    - and some artistic talent.

    next to that some good tools, as you won’t succeed painting/sculpturing a realistic terrain just with the built in tools. use external tools or at least get the terrain tools from sixtimesnothing or terrain edge: http://forum.unity3d.com/threads/118820-TerrainEdge-3-(need-testers-feedback-ideas-etc). those will help you sculpting the terrain and paint it.
    terrain edge also comes with some shaders supporting bump mapping and uv mixing for better tiling as far as i know.
    another starting point might be the advanced terrain shaders from the asset store (free!).

    as far as the terrain from the images above is concerned: it is a pretty simple one: just 2 terrain textures (plus bumpmapping –*all included in the advanced terrain shaders), 2 different types of trees (30$ on the asset store ;-)) 2 mesh grasses and the new foliage plus foliage shader. plus one directional light, bloom and glow post processing image effect and some ssao.

    lars
     
  19. l0cke

    l0cke

    Joined:
    Apr 15, 2012
    Posts:
    438
    Is this shader compatibile with trees from Unity tree creator?
     
  20. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,687
    no, it is not: trees use 2 materials and use a second uv set to control bending. and why should you use it with trees?
    in case you want enable batching on trees you can but it is a completely different work around.

    lars
     
  21. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,687
    new demo released:
    http://bit.ly/K0osHC

    it shows some new models like maple sapplings, blackberry bushes, weed and nettles all rendered with the advanced foliage shader (both: placed as single game objects and placed within the terrain engine) next to the new grass shader which allows even complex geometry without any restrictions in uv mapping (look out for the clover near the extraction point – just a poof of concept…)

    lars
     
    Last edited: May 9, 2012
  22. Tallenz

    Tallenz

    Joined:
    May 9, 2012
    Posts:
    11
    Created an account just to tell you how awesome you are. Thanks a ton for your time and effort! This is great work and will benefit my project tremendously.

    Tallenz
     
  23. mk1978

    mk1978

    Joined:
    Dec 27, 2009
    Posts:
    276
    Yes, it is actually true that you have already published some tutorials. I would assume that it is more about artistic talent that I am currently missing. Anyway, it is always nice that you publish the web player scenes because it is good to "study" the scenes (materials, placement of the assets, etc.).
     
  24. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,687
    Update
    Bugfix in order to make foliage placed within the terrain engine bend correctly on windows.
     
  25. RickF

    RickF

    Joined:
    Sep 12, 2012
    Posts:
    21
    From original post "Read the docs.http://bit.ly/JkLwD1" This link is broken. Anywhere else I can find step by step documentation? Would love to get our tree model library into unity.
     
  26. dirtybassett

    dirtybassett

    Joined:
    Oct 3, 2012
    Posts:
    58
    Any idea why my tree billboards are white using this shader ?
     
  27. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,517
    Whats your graphic card. I believe this shader requires SM3 and above.
     
  28. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,687
    thanks for your notice. i have fixed the link.

    lars
     
  29. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,687
    do i get you right? when using the shader tree billboards (billboards of trees not using the foliage shader) get white?
    that sounds rather strange.

    would be nice if you could give some more information about your issue.

    lars
     
  30. dirtybassett

    dirtybassett

    Joined:
    Oct 3, 2012
    Posts:
    58
    My mistake, think i got my tree setup wrong because it works fine for unity built in trees. Works great with detail meshes.
     
  31. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,687
    good to hear that the shader works for you and does not corrupt your trees…

    lars
     
  32. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    711
    Hi Lars. I have a couple of questions, just to make sure I understand correctly:

    - Do the shaders work with Unity 4.0?

    - Does this mean I can create models for grass patches, bushes, etc... and then just clone them in the scene and place them manually? So even though they wouldn't be painted on standard Unity Terrain, they would still be procedurally animated?

    Thanks,
    Seith
     
  33. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    711
    Oh. I hadn't realized this project was discontinued... :(
     
  34. copenhagenjazz

    copenhagenjazz

    Joined:
    Oct 2, 2005
    Posts:
    45
    Hi Lars

    Does this shader pack work with Unity4?
     
  35. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,687
    hi seith,

    sorry for my late reply but i haven’t seen your post until now.


    i just made a quick test: yes, they do.

    it is up to you: you can place grass, bushes etc manually or using the terrain engine.
    no matter which way you choose, the shader supports procedural bending, bump mapping, specular lighting and receiving shadows.
    however, only manually placed objects will also cast shadows.

    so in case you do not need the objects to cast shadows placing them within the terrain engine would be the fastest method as far as rendering is concerned.
    but as the shader also supports dynamic and static batching, LOD groups and even combined meshes even manually placed objects can be rendered very fast.

    for these reasons i usually combine both ways: most of the objects i place within the terrain engine then i add some manually placed objects as i want their shadows.
    but of course you can use the shader just outside the terrain engine in case you want to have some plants in a flower pot or some ivy on a wall.

    just have a look at my 2nd demo: http://bit.ly/K0osHC

    lars
     
    Last edited: Mar 12, 2013
  36. SevenBits

    SevenBits

    Joined:
    Dec 26, 2011
    Posts:
    1,953
    This is quite nice.
     
  37. fano_linux

    fano_linux

    Joined:
    Jan 1, 2012
    Posts:
    909
    very nice
     
  38. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,687
  39. SevenBits

    SevenBits

    Joined:
    Dec 26, 2011
    Posts:
    1,953
    Very cool. Just one question: do you use tree creator to make the trees or a modeling program? Because I'd like to be able to use wind zones, etc, in my scene, and those don't seem to work on non-tree creator trees for some reason.
     
  40. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    711
    Great, thanks Lars! Then I'll go ahead and buy the shader pack...

    I'm also interested in SevenBit's question regarding whether or not you can use Unity's built-in Tree Creator and benefit from wind zones. And if that's possible, does it mean any vegetation object manually placed (not through the Terrain system) can be affected by Unity's wind zones?
     
  41. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    711
    Ok, so I followed your instructions (in the .pdf file) and got everything working. Very nice!

    The only problem is my manually placed vegetation objects only appear when I'm about 5 meters away from them. How do I go about changing that? I played with the "Small Details Distance" and "Medium Details Distance" of the FoliageSetupShader script but they don't seem to have any effect...


    UPDATE: Alright, fixed the problem. When I looked into the script I saw the culling layer numbers. It would probably be beneficial to indicate those numbers in the documentation pdf. Maybe in the Wind section (since that's where you mention culling), or even better, have a small paragraph regarding camera culling.

    But so far I really like the whole thing. Great job!
     
    Last edited: Mar 15, 2013
  42. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,687
    thanks!
     
  43. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,687
    i haven’t used the tree creator to model any model shown in both demos.

    unity’s built in windzones only work on trees which have the tree script assigned (from the tree creator), but using the advanced foliage shader you can mimic directional windzones with the provided script. unfortunately you can’t mimic radial windzones right now.
    on the other hand models using the advanced foliage shader should be much cheaper to render.

    not any vegetation object manually placed but any "tree" modeled with the built in tree creator can be effected by wind zones. you do not have to use the terrain engine.
    but it might be very expensive to let’s say render 10 flower pots each containing 10 flowers which are built as 1 tree:
    this would end in 10 * 1 draw calls (when using only 1 material: leaves) or even 10 * 3 draw calls when using real time shadows.
    using the advanced foliage shader would give you 1 or 1 + 10 * 2 draw calls using static batching or 3 draw calls using mesh combining.

    have a look at one of my older posts for details: http://forum.unity3d.com/threads/138929-batching-trees-%96-and-speed-up-rendering

    lars
     
  44. Doyora

    Doyora

    Joined:
    Feb 2, 2013
    Posts:
    12
    Hi, I've been using this for a while and it's really nice. However I'm having a problem in that none of the objects I have this shader applied to are receiving shadows. Any idea what I'm doing wrong? the test scene that comes with the package works fine, and my assets work fine when I add them to that scene. Just not my own one.

    $7vCW3aw.jpg
    this image should show my problem. my objects are casting shadows fine but not picking any up.
     
  45. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,687
    hi there,

    i am glad that you like the package.
    as far as your problem is concerned: have you checked "receive shadows" in the mesh renderer component?

    lars
     
  46. Doyora

    Doyora

    Joined:
    Feb 2, 2013
    Posts:
    12
    Hi lars, I actualy fixed the problem now. I added "#pragma target 3.0" and "fullforwardshadows" to the shader file to make shadows from point lights work. I'm assuming it's much less efficient now, but it's doing what I want so I'm happy :)
     
  47. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,687
    hi doyora,
    sorry for your inconvenience, but most of the time i work in deferred mode… so you did right to add "fullforwardshadows" in case you have point lights (what i should have seen if i had a closer look to your image...).
    nevertheless, what is about going with deffered rendering? in case you have some more point lights in your scene (even if they are just filling lights – especially as your scene appears to be very dark) choosing deferred rendering should speed up rendering.

    lars
     
  48. invadererik

    invadererik

    Joined:
    Oct 31, 2010
    Posts:
    126
    How does the new Advanced Foliage Shader v.2 touch bending (with multiple objects) work? I know before you needed to keep a global shader variable updated, is this still the case? Is there a limit to number of objects ?
     
  49. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,687
    hi there,

    the shader still needs some global vars like wind (direction and speed) and – in case you use it within the terrain engine – translucency color and view dependency.
    touch bending needs much more of course. it is a script/collider/shader based solution and works only with plants placed manually as single game objects.
    but it supports static batching, layer based or occlusion culling and lods to speed up rendering. and it performs very well as far as i can say.
    the number of objects is not limited by the script, but it is limited by your cpu/gpu of course.

    lars
     
  50. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,687
    hi there,

    for all of you who are looking for touch bending: it now ships with version 2 of the advanced foliage shader!

    get it here: http://www.assetstore.unity3d.com/#/content/3253

    or watch the demos:
    terrain engine vs. single game objects:http://dl.dropboxusercontent.com/u/2322017/afs_v2/afs_v2_touchbending/afs_v2_demoscene.html
    touch bending: http://dl.dropboxusercontent.com/u/2322017/afs_v2/afs_v2_touchbending/afs_v2_touchbending.html

    see the first post of this thread to find out more.

    lars