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:
    6,902
    @david: any chance to see some images from what you have done so far?

    lars
     
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    the "advanced foliage shader atlas nobending" has been designed to serve as such: it uses the same lighting functions but no bending.

    but unity's built in lod system will not work with the combine children afs script which i consider to be the best way to speed up rendering as it eliminates all the overhead from may be 100 of game objects… so at least on smaller plants i would always choose this way in cunjunction with early layer culling.

    lars
     
  3. David-Lindsay

    David-Lindsay

    Joined:
    May 20, 2009
    Posts:
    121
    So basically, for optimum performance, you still need to carve up the scene, child the objects to a parent and put the AFS combine script on it. This is pretty much what I did for the scenes on City of Steam, but even after all that work, the difference wasn't massive.

    I get it -static batching isn't perfect. Hmmm... have to think about how to tackle it.

    $Demo_Test_Foliage_1.jpg
     
    Last edited: Oct 13, 2013
  4. David-Lindsay

    David-Lindsay

    Joined:
    May 20, 2009
    Posts:
    121
    $Demo_Test_Foliage_2.jpg

    This scene was specifically for testing the foliage shaders, point lights and deferred vs forward lighting
     
  5. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi david,

    first of all: i could not see your picture in the post – but when hitting "reply with quotes".
    it is a bit dark though…

    anyway: back to performance.
    when using the combine children script you will have to chose the size of your "foliage patches" carefully: if they are too small you will get a lot of draw calls. if they are too big you will waste a lot of polygons which probably will not be visible in the viewing frustrum. also occlusion culling will not work as efficient as it probably could.
    and do not forget: most of the time not poly count is the bottleneck but fill rate. so do not hesitate to add some more polygons to your models if this would help to save fill rate.

    may be the most efficient method would be to:
    - use the combine children script and combine the meshes statically.
    - export the created mesh and generate a low poly version of it (you can simply use the obj exporter script from the wiki as vertex colors are not needed on the second LOD).
    - take both meshes and create an LOD object from them.
    - use the "nobending" shader on the second LOD.
    - use early layer culling

    btw: "static batching" is not really recommended on large numbers of objects:
    "Using static batching will require additional memory for storing the combined geometry. If several objects shared the same geometry before static batching, then a copy of geometry will be created for each object, either in the Editor or at runtime. This might not always be a good idea - sometimes you will have to sacrifice rendering performance by avoiding static batching for some objects to keep a smaller memory footprint. For example, marking trees as static in a dense forest level can have serious memory impact."
    http://docs.unity3d.com/Documentation/Manual/DrawCallBatching.html

    lars
     
  6. David-Lindsay

    David-Lindsay

    Joined:
    May 20, 2009
    Posts:
    121
    Oh, sorry about the screenshot -I didn't want to wait for he day cycle to reach midday cause that takes 6 minutes :p

    Yeah, I still have some weird ideas in my head about combining during run-time, because we had to procedurally build the levels in City of Steam which meant hundreds and thousands of tiny pieces and long loading times. But -it did save on CDN streaming costs, which was kinda the point. 1 level = ~500 KB, so it was really low cost.

    But yeah, I get it -thanks for the help and when there is something real to show I will make some less awful screenshots :)
     
  7. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i am looking forward to see more from your project.
    and just stay in touch – may be we can figure out something together to improve performance even more.
    (version 2.04 will bring some kind of early exit skipping most of the computation of the vertex shader – and i can imagine that for special cases i could add some more optimizations.)

    lars
     
  8. bpears

    bpears

    Joined:
    Aug 23, 2012
    Posts:
    249
    Does this include a tool to mass place terrain models onto a custom terrain mesh, not a unity terrain?
     
  9. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi there,

    it is not part of the package but you can download a modified version of the geometry brush here:
    http://dl.dropboxusercontent.com/u/2322017/GeometryBrushAFS.v1.unitypackage

    it allows you to place vegetation on any game object that has a collider attached.

    lars
     
  10. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    Hi there,

    while i am just finishing the work on version 2.04 of the advanced foliage shaders i would like to give you a sneak preview on one of its upcoming features which is "advanced billboarding" on trees placed within the terrain engine.
    This means better fading between mesh tree and billboard containing:
    - faded wind animation
    - faded real time shadows on leafs and bark
    - faded point and spot lights
    giving you the smoothest transition between mesh tree and billboard you have probably seen in unity so far ;-)

    It also comes with a technique i call "real time shaded billboards" which i have developed together with tomaszek and becoming while working on the Relief Terrain Pack 3.0 demo. This technique will make your billboarded tree receive some kind of "real time shadows" from the terrain or any other given geometry.

    $shaded_billboards.jpg

    Just have a look at the picture attached so see how it looks or test the webplayer:
    http://dl.dropboxusercontent.com/u/...ding/afs_v2_treeShader/afs_v2_treeShader.html

    Please note: When rotating the sun you may have to update the billboard textures manually (hit "4") in case the camera has not rotated all at – as this is the "trigger" to make unity recalculate the billboard textures according to the given lighting situation. But you may also just check "Update billboard textures automatically".

    lars
     
  11. Don-Gray

    Don-Gray

    Joined:
    Mar 18, 2009
    Posts:
    2,278
    Nice idea, looks good, bright trees don't look right in the shade.

    :)
     
  12. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    thanks, but what do you mean with " bright trees don't look right in the shade."?

    lars
     
  13. Don-Gray

    Don-Gray

    Joined:
    Mar 18, 2009
    Posts:
    2,278
    Nothing to do with your shader, Unity's trees look ambient in the shade and distance.
     
  14. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hmm, i hope that the new shaders and "real time shaded billboards" will make them a bit more "acceptable".

    lars
     
  15. Don-Gray

    Don-Gray

    Joined:
    Mar 18, 2009
    Posts:
    2,278
    They look good in the demo.
     
  16. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    thanks!
     
  17. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    And for those who prefer a video instead of the webplayer:



    lars
     
  18. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
  19. Don-Gray

    Don-Gray

    Joined:
    Mar 18, 2009
    Posts:
    2,278
    Pretty nice, the only thing I see that gives away the billboard to mesh change is the shadow!
     
  20. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    you are right,

    billboards do not cast nor receive real time shadows (what is the reason for the "shadowed" billboard script mentioned the page before this), mesh trees do but not during transitions. so i fade in at least the received shadows. may be i find a solution to also fade in the casted shadows later on.

    lars
     
  21. Don-Gray

    Don-Gray

    Joined:
    Mar 18, 2009
    Posts:
    2,278
    Is it possible to have an editable ambient value slider to affect trees in the distance,
    seems they are usually unnaturally ambient.
    Again, not talking specifically about your trees, but Unity terrain trees.
    This way the user could set it according to his scene.
    Just an idea.
     
  22. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    well, the package already supports tweaking the "transluceny factor" on billboards as well as adjusting their contrast… ;-)
    teaking the ambient light is supported when working with "shaded" billboards.

    lars
     
  23. Don-Gray

    Don-Gray

    Joined:
    Mar 18, 2009
    Posts:
    2,278
    OK, will have to take a look.
    Thanks
     
  24. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i guess so ;-)
    it should be up within the next days as i have submitted it 2 days ago.
    but perspectively correct billboards will come a little bit later. i am just cleaning up a little bit and doing some more tests.

    lars
     
  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi there,

    i just assembled a quick and dirty test scene which shows how a "fly" scene might look like (although i have written the shader to mainly support the first person perspective):

    http://dl.dropboxusercontent.com/u/2...der03_fly.html

    - use "wasd" and your mouse to navigate.
    - use "3" to roate the sun and see how the "shaded" billboards might look (do not forget to rotate a littel bit around to force unity to update the billboard textures).
    - use "4" to toggle between perspectively aligned and simply upright billboards. (the billboard shader will always perform advanced shadow and bending fading though, as it is just not the built in one.)

    please note: it is absolutely ok if you get some kind of "extra punch" during the transition between billboard to mesh tree: that is the wind "fading in" which is set to "4"...

    terrain settings:
    – billboard start: 50
    – fade length: 15
    – max mesh trees: 75

    lars


    $billboards_stresstest.jpg
     
  26. Don-Gray

    Don-Gray

    Joined:
    Mar 18, 2009
    Posts:
    2,278
    Interesting.
     
  27. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi don,
    could you be a bit more specific please?
    thanks,

    lars
     
  28. Don-Gray

    Don-Gray

    Joined:
    Mar 18, 2009
    Posts:
    2,278
    Hmm, well, to see the difference between the two types of reaction of the trees.
     
  29. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    and? do you like what you see?
    which one do you prefer?
    well – i do have to admit that on very steep viewing angles the shader falls back to "upright" billboards as those would be just distorted much too much, but you will be able to tweak a threshold.

    lars
     
  30. Don-Gray

    Don-Gray

    Joined:
    Mar 18, 2009
    Posts:
    2,278
    Of course I prefer the more natural way, using the camera perspective.

    :D

    Have confidence!
     
  31. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    you never know… but thanks.
     
  32. Don-Gray

    Don-Gray

    Joined:
    Mar 18, 2009
    Posts:
    2,278
    Well, if you are concerned about it, you could have an option to do either way.
    Maybe you already do.
     
  33. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    yes, i do have.
     
  34. knocks

    knocks

    Joined:
    Jul 1, 2012
    Posts:
    23
    Will the afs Foliage Package v.2 see 2.04? or am i best grabbing the shader package to keep up to date?
     
  35. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi there,
    the afs Foliage Package will probably be updated to version 2.04 of the advanced foliage shaders – but that can take quite a while.
    prio 1 is on the original shader package.
    sorry, but the whole idea of the foliage package turned out to be a failure somehow: due to the whole time consuming process of getting an update live on the asset store it is a rather bad idea to create assets which are related to each other.
    if you would like to get the plants: buy them, send your invoice number to me and i will send you the latest shaders and scripts (which is version 2.03 at the moment). if you are mainly interested in the shaders and scripts i would suggest to get just those as it makes it much easier to get them in sync.

    lars
     
  36. knocks

    knocks

    Joined:
    Jul 1, 2012
    Posts:
    23
    Lets keep it simple, i'll grab the shader package :D
     
  37. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi there,

    i have just updated the simple "fly" demo.
    new in this version are:

    - fading billboards: they just fade out before they get culled (in order to make this visible i have set the "Tree Distance" to "380".
    - dissolving tree shadows: in order to make the shadows casted by mesh trees not to just pop in (as the real time shadow distance is much higher than the billboards distance we won’t get fading in shadows casted by trees) i have implemented some kind of "growing shadows". when used in conjunction with rather high camera movement speeds and soft shadows those might look quite ok (but can be simply disabled if you wish... ).

    what do you think?

    http://dl.dropboxusercontent.com/u/...treeShader03_fly/afs_v2_treeShader03_fly.html


    lars
     
  38. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    Good stuff, really looking forward to this update ;)
     
  39. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i am glad you like it!
    thanks.
     
  40. hike1

    hike1

    Joined:
    Sep 6, 2009
    Posts:
    401
    Anybody know how to get vertex colors out of Blender?
     
  41. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    simply safe as .fbx?
     
  42. bpears

    bpears

    Joined:
    Aug 23, 2012
    Posts:
    249
    Hello again, does the touch bending require a collider of some sort?

    EDIT:
    Also, does the shaded billboards work if I am not using Unity Terrain, but have created trees and their respective billboards in modeling software?
     
    Last edited: Oct 26, 2013
  43. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi there,

    yes it does. how else should i detect the touch event?
    any special reason you are asking for?


    sorry, everything of the advanced foliage shader pack that deals with "billboards" is for the terrain engine only as trees placed within the terrain engine really could need some improvements.
    but if you have manually modeled trees (which shader would yo use one those to make them bending?) and manually modeled "billboards" (how would they look? just a cross with 2 textures?) shadow on that kind of billboards would be calculated automatically if the shader used for your billboards supports pixel lighting and if the shadow distance is set up high enough.

    the big question is to how implement billboards.
    you can either use unity’s built in LODs or have to come up with your own solution.
    i guess using LODs would be ok if your scene does not contain more than e.g. 200 trees = 200 game objects as you have to keep in mind that each single game object will produce some overhead. so having 2000 - 5000 single trees will probably be a big problem.

    may i ask why you do not want to use the terrain engine?

    lars
     
  44. hike1

    hike1

    Joined:
    Sep 6, 2009
    Posts:
    401
    quote
    simply safe as .fbx?
    unquote

    I can do that, but where do I see them in Unity?
     
  45. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    vertex colors are not showed in unity unless you would use a proper shader.
    the advanced foliage shaders do not show vertex colors either as they use them to control bending.

    if a mesh has vertex colors applied you see when slecting it in the project tab so the inspector shows the information about it.
    it will give you a preview, the number of vertices and faces, uv sets and COLORS.

    lars
     
  46. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    upps – somehow my last post has got eaten…

    but version 2.04 is now available on the asset store!

    it comes with:
    - first and foremost: enhanced support for unity >= 4.2 and its new shadow collector/receiver batching features
    - advanced tree shaders giving you much better billboard fading and more variety in bending of adjacent trees
    - simple tree shader which lets you use any foliage as "tree" using the built in terrain engine in order to benfit from billboarding
    - real time "shaded" billboards

    lars
     
  47. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    Apologies in advance for a question that might be ignorant. :)

    When applying the "AFS TreeCreator Optimized Trees..." shader to a leaf material subsequently used in the Tree Creator I get a warning stating that it is not a leaf shader? Did I miss something setting this up?
     
  48. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi there,

    do NOT apply any of the "afs" shaders as "leaf material" (neither on the leaf meshes nor in the inspector when using billboards) or as "branch material" or "break material" in the tree creator component.
    simply use standard leaf and bark materials materails here.

    when done you simply replace the "Optimized Bark" and "Optimized Leave" material with your materials using the "afs" shaders in the "mesh renderer" component.

    or make the changes just globally: then you do not have to change any tree!
    please have a look at the docs.

    lars
     
  49. Casto

    Casto

    Joined:
    Aug 14, 2013
    Posts:
    44
    Hi,

    I've bought this asset and I would like to replace the materials of my trees with yours.
    All my trees are made with Unity Tree Creator so how could I do that?

    Thanks!
     
  50. Deleted User

    Deleted User

    Guest

    Great job! I especially love the real time shaded billboards! This adds so much more depth to the scene. Also the new advanced tree shaders are amazing - thank you.

    Would it be possible to let the billboards react with wind?