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
    hi casto,

    2.3.1. Assign the shaders manually
    - Create 2 new materials and using the "AfsTreeCreatorBarkOptimized" respectively the "AfsTreeCreatorLeavesOptimized" shader.
    - Find and assign the textures of your tree which are generated by the tree creator.
    - Find the prefab of your tree, click on the root node and replace "Optimized Bark Material" and "Optimized Leaves Material" (on the mesh renderer component) with the new materials.


    2.3.2. Assign the shaders globally
    In case you do not want to edit each tree prefab manually you can assign the shaders globally.
    Do so by editing the shader you want to replace the default "tree creator shader":
    - Open the shader in Mono and rename it by editing the first line, e. g.:
    Shader "AFS_v2/AFS Tree Creator Bark Optimize" {
    rename it to:
    Shader "Hidden/Nature/Tree Creator Bark Optimized" {


    Doing so you will simply overwrite the built in shaders and all models will automatically use the tweaked shaders.
    Please note: Renaming the shaders like this will make them disappear from the dropdown menu in the material inspector: "Hidden…".
    But you can still assign them to a custom material by dragging them in the project tab onto your material.
     
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    thank you.

    no, that is not possible: there are just a single quad…

    lars
     
  3. Casto

    Casto

    Joined:
    Aug 14, 2013
    Posts:
    44

    Thanks Larsbertram!

    I think I completely missed something because I cannot find any AfsTreeCreatorBarkOptimized shader nor AfsTreeCreatorLeavesOptimized. I re-downloaded and re-imported all the package to be sure to have everything...
     
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    just have a closer look they should be there…
    you may also compare your folder with the content shown at the asset store.

    $Bildschirmfoto 2013-10-31 um 01.14.22.png
     
  5. bpears

    bpears

    Joined:
    Aug 23, 2012
    Posts:
    249
    does this tool allow you to disable billboarding following of camera?
     
  6. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hmm, this "tool" allows you to ENABLE billboarding following the camera – as built in billboards do not get rendered according to the camera angle but are always rendered "upright" (will be available in version 2.041 currently under review).

    have a look at the image attached which shows the difference between the built in billboard shader and the new version:

    $billboards_orientation.jpg

    does this answer your question?

    lars
     
    Last edited: Nov 2, 2013
  7. bpears

    bpears

    Joined:
    Aug 23, 2012
    Posts:
    249
    Yes it does. This will be nice to have the option to mess about with. So yeah, this is on my shopping list :)
     
  8. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    Fine!
    i hope version 2.041 will be up within the next days (already waiting for approval for 5 days now...) and i am looking forward to see what you will do with it.

    lars
     
  9. im

    im

    Joined:
    Jan 17, 2013
    Posts:
    1,408
    aye its on sale ;)
     
  10. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574
    Just bought the package, and got 3 errors upon importing into project :


    Shader error in "Hidden/TerrainEngine/Details/Vertexlit": include callback failed at line 24
    Shader error in "Hidden/TerrainEngine/Details/Vertexlit": syntax error at line 36
    Shader error in "Hidden/TerrainEngine/Details/Vertexlit": syntax error at line 37



    PS, I am still on Unity 3.5.7, OSX 10.6.8
     
  11. Deleted User

    Deleted User

    Guest

    awesome o-o thanks!
     
  12. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi there,
    unfortunately i have to admit that anybody should get those errors as there is one cginc file missing in the package currently live on the asset store…
    i am sorry about that.

    but this only effects the shader which replaces the built in terrain engine vertex lit shader.
    as it does not cast shadows (due to the limitations of the terrain engine) you will probably not use it anyway: using the "regular" foliage shader in conjunction with the combine children afs script will give you plants casting shadows rendered at about the same speed (if not even faster).
    and using the geometry brush will let you place your plants just like using the terrain engine.

    version 2.041, which is currently under review, should bring back the missing file.
    so either wait for the official update (which i suppose will be available within the next few days) or drop me a pm.

    sorry,

    lars
     
  13. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    thanks!
    i am still stunned by this shader myself ;-)
    now it is time that you lower the billboard distance and save up to several hundred draw calls!

    lars
     
  14. bpears

    bpears

    Joined:
    Aug 23, 2012
    Posts:
    249
    Lars, will I be able to not use 'upright' billboards and still use your shader though, so that they receive shadows and things still? If the upright part is just a script, I think I could alter it as needed. But for shader code I don't know what I'm doing. I just figure if billboards are all made to be upright it might look silly where the real model is angled(during transition)? Either way, I'd like to be able to toggle the upright and camera follow. Can't wait to try this out!
     
  15. bpears

    bpears

    Joined:
    Aug 23, 2012
    Posts:
    249
    Woops nevermind, I misread and thought the new shader was gonig to make billboards always be precisely straight up and down.
     
  16. larsbertram1

    larsbertram1

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

    the new shader will make billboards be perfectly aligned to the camera angle like shown in the pictures above.
    but you will be able to simpley turn of this feature (although i can not imagine why someone should do this…) using the new setup interface (v. 2.041):

    $Bildschirmfoto 2013-11-03 um 18.48.43.png

    lars
     
  17. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574
    Question, if the included version is slower than the "regular" foliage shader, maybe there is room for optimization? ;)

    Anyway, sounds good, thanks for the support.
    I will wait for the Asset Store version. :)
     
  18. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    well, i do not think so.

    but why is it eventually slower?
    shader itself: because the shader has to calculate the tangents needed by normal mapping and not provided by the terrain engine.
    terrain engine: the terrain engine creates geometry on the fly which is good for very large environments (memory savings) but takes time on the cpu.

    and in general: terrain engine vs manually placed meshes:
    all patches generated by the terrain engine have the same size giving you the same amount of precision on any part of the terrain. but probably you will not need much precision on most parts of your terrain (just imagine a great plain filled with grass) but just on some very small and special parts (like the grass in the middle of the path shown in this demo: http://dl.dropboxusercontent.com/u/..._v2_groundlighting/afs_v2_groundlighting.html).
    setting up the terrain’s detail resolution to fit your needs on the path will give you a ridiculously high number of draw calls on all of your terrain. whereas adding the the grass details and other plants just around the path using the combine children afs script will cause ONE single draw call.

    my personal conclusion: set up the detail resolution very low (giving you a precision of may be +- 1m or even +- 2m) and add all absolutely precisely placed plants as game objects using the combine children afs script.

    lars
     
  19. bpears

    bpears

    Joined:
    Aug 23, 2012
    Posts:
    249
    Awesome, thanks. I just like having the option, as I may go with thicker billboards for trees. More like low poly models I suppose. Since some trees can be very asymmetrical/lopsided, and having it rotate to the camera could make it look weird since the low poly billboard and regular model wont match up because of rotation, in that case. But I may just end up leaving it on anyway, but having the option is nice to try it out. Purchased it btw :)
     
  20. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hmm, sorry but it looks like you have missed something about unity’s billboards:
    they are no "lowpoly" models – however the displayed billboard texture almost always fits the mesh tree viewed from the same viewing angle as far as shape is concerned. but just give it a go.

    lars
     
  21. bpears

    bpears

    Joined:
    Aug 23, 2012
    Posts:
    249
    Oh, I guess I should have mentioned I'm making my own sort of billboards in modeling program. So.. now that I think about it it doesn't really apply does it. Is there a way to assign custom billboard(or low poly) to camera follow? If not, that's fine, it's easy to script.

    I'm also wondering though, for regular poly trees, does this tool/shaders support fbx models? or only Unity trees made in tree tool? If can do fbx, can the models meshes already be combined?
     
    Last edited: Nov 3, 2013
  22. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    the billboard shader will only work with the built in terrain engine, sorry.
    but if i were you, i would just give it a go and see if it already fits your needs (may be you have to wait some more days until version 2.041 is available…). i am pretty sure that using the built in terrain engine / trees / billboards will be much faster than a custom made solutution unless you put a lot of effort in your tree / billboard system.
    i can only speak for myself but since i have the new billboard shader i am very pleased with what i can do with the terrain engine.

    the tree shaders are made to replace those of the tree creator. so – unless you know how to tweak your models accordingly (set up 2nd uv, adding vertex colors) – they will probably not give you the desired result on custom modeled meshes.
    setting up bending for trees might be a very complex and cumbersome process…
    you may try the foliage shaders though. they only need vertex colors but do not seperate between primary and secondary bending.

    lars
     
  23. bpears

    bpears

    Joined:
    Aug 23, 2012
    Posts:
    249
    Well, glad I asked! Maybe I will use the tree creator after all then...

    Does it generate a billboard for Unity trees made in tree creator even if you don't use a Unity terrain?
    Thanks for good product support :)
     
  24. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    nope, billboards (textures and "meshes") are created by the terrain engine.
    you are welcome!
     
  25. bpears

    bpears

    Joined:
    Aug 23, 2012
    Posts:
    249
    To be more clear, what I mean is:
    If I'm not using the Unity Terrain, but I am using this tool/shaders, and Unity trees, will the billboards be generated still or..? Since the Unity trees would be using a billboarding shader no matter what they're placed on?
     
  26. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    unfortunately: no.
    the whole billboarding is handled by the terrain engine.
    if you place a tree (no matter if it is modeled using the tree creator or not) you won’t get any billboarding at all.
    in this case you would have to set up your own system.
    you may use the built in LOD system but i doubt that it can handle – let’s say – a thousand trees a moderate costs.

    lars
     
  27. larsbertram1

    larsbertram1

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

    it is xmas time!
    version 2.041 is online giving you perspectively aligned billboards.

    so go and get the latest update.

    lars
     
  28. Deleted User

    Deleted User

    Guest

    Thanks!!! killer feature :)
     
  29. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    thanks!
     
  30. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Any Chance to some of these Really Awesome features from Advanced foliage shader to the Mobile?

    Cheers.
     
  31. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hmm, which features exactly do you mean?
    and i guess most of them will just be too expensive to render…
    others (especially lighting features) will not make much sense as you will probably use lightmaps.

    but you will get the basic features for free when downloading my mobile foliage package:
    https://www.assetstore.unity3d.com/#/content/3460

    lars
     
  32. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574



    Still the same error Lars, after updating it to 2.041
     
  33. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hmm, you should definitely NOT get any errors any more.
    the shader "Hidden/TerrainEngine/Details/Vertexlit" includes the following files:
    #include "Includes/FoliageLightingTerrainEngine.cginc"
    #include "TerrainEngine.cginc"
    #include "Includes/CustomBendingVertexLit.cginc"


    the custom cginc files:
    "Includes/FoliageLightingTerrainEngine.cginc"
    "Includes/CustomBendingVertexLit.cginc"
    are part of the package located at: "Shaders/Includes".
    At least that is what the "Package Content" window on the asset store shows.

    so please check that you have both files.
    then select the "advancedFoliageShader for Terrain Engine v2.04" in the project tab and chose "reimport" from the context menu (rmb).

    does that help?

    lars
     
  34. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574
    Very strange, I just reload the project and re-import AFS now there is no problem at all!

    Anyway it fixed itself :) Danke!
     
  35. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    Bitte!
    Sometimes it is a bit strange which assets get recompiled and which not…

    And please let me know how you like the new billboards!
     
  36. larsbertram1

    larsbertram1

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

    as billboards now look much prettier i am thinking about some more possibilities to make the terrain engine more flexible.
    first result:

    free positioned terrain trees
    no matter if you use modern terrain shader suits like the color map ultra shader or rtp3 which let you place manually modeled geometry onto the terrain and blend both seamlessly i think it would be a great addition to be able to place "terrain trees" on top of any kind of manually added geometry like big rocks, cliffs or overhangs.so i started to work on a little script and it turned out that this will let you place "terrain trees" more or less anywhere while still taking benefit from advanced billboarding and shaded billboards.

    free positioned terrain trees: all trees are placed using the built in terrain engine and support billboarding and wind.

    $afs_free_positioned_trees.jpg


    lars
     
  37. Project-Mysh

    Project-Mysh

    Joined:
    Nov 3, 2013
    Posts:
    223
    Hi Lars,

    I have problems with touch blending when I enable DX11. In your demos, the grass looks normal, but the branches go crazy. Is this a known problem?
     
  38. Project-Mysh

    Project-Mysh

    Joined:
    Nov 3, 2013
    Posts:
    223
    Problem solved, the problem disapears when i close entry Unity and reload all project.
     
  39. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    This is really cool : )
    Great job as always : D
     
  40. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i am glad you have solved it!
     
  41. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    thanks!

    and here is another screen shot showing: trees placed on top of manually added geometry and trees placed below manually added geometry (the terrain):


    lars
     

    Attached Files:

    Last edited: Nov 7, 2013
  42. Project-Mysh

    Project-Mysh

    Joined:
    Nov 3, 2013
    Posts:
    223
    Your shader is amazing lars, very good quality-performance!!
     
  43. Becoming

    Becoming

    Joined:
    May 19, 2013
    Posts:
    781
    Hey! Congratulations to get the awesome AFS 2.041 out!! Perspective correction and shaded billboards are really really important for modern games!!

    Freely placeable trees are an awesome idea!! I have another suggestion for you:
    When there are a lot of trees in the scene, the treecolliders are a performance issue. Also, the capsules are sometimes not the best solution as they wont really fit the most tree shapes. So my idea would be to place tree colliders dynamically and only in a certain range of the player. Having a compound of primitive colliders(to better fit the shape) assigned to specific treetypes that get placed on the trees when you come close to them. Scaling should happen automatically...

    What do you think?

    Anyway, AFS rocks :)

    ATB,
    Peter
     
  44. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    That looks really great, Lars! Although I'm not working on vegetation at the moment it's really cool to see you improving your asset... :)
     
  45. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi there,
    thank you a lot. and i am pretty glad to read that you get great performance.
    not to mention the quality…

    lasr
     
  46. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    thanks peter,

    and i will probably have a look into the collider issue.
    lars
     
  47. larsbertram1

    larsbertram1

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

    thank you.
    i hope you are making great progress and i am looking forward to see the next update on tale of a ghost!

    lars
     
  48. tomato_comet

    tomato_comet

    Joined:
    Oct 17, 2013
    Posts:
    18
    I tried the demo. It seems great. I need a little clarification on its capabilities.

    In the bend demo, the small broad leafed tree bends, but the leaves clip through the capsule. Is this adjustable? Are there colliders on the meshes that I could adjust for each plant leaf?

    About the mesh import process - Can I do the following: Import a static, unanimated, unrigged, do-nothing tree model from Maya, for example, and with your shader within Unity, select portions of the tree to bend by touch and sway in the wind? Is it that simple? Or must the imported model be setup in a certain way to be adjustable by this shader?

    In short, there are some pretty plant models on sites like Squidoo. They are not animated or anything. I would like to use those professional plant models in Unity. Would Advanced Foliage Shader add bend and wind affects to them?
     
  49. larsbertram1

    larsbertram1

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

    thank you!



    afs touch bending does not work with bones and a complex e. g. rope physics simulation.
    it simply uses one collider as trigger, most calculations are done within the shader.
    so you can’t ad more touch bending triggers to one single game object but would have to split up your plant into several objects. those would be batched statically if untouched giving you a rather good performance but of course each game object will simple generate some overhead.





    just to make it clear: the advanced foliage shaders do NOT need or use animated or rigged models.
    all bending is done within the vertex shader controlled by vertex colors that must be baked into the model.
    you can use the afs foliage tool (part of the package) to adjust already baked vertex colors, you can even use it to set up primary and secondary bending from scratch, but if you would like to use all supported bending features you will have to at least tweak vertex color red and green within your 3d app (and probably bake ambient occlusion to vertex color alpha). the whole process of how to set up your models is described in depth in the documentation.





    i think with a little work in your 3d app adding edge fluttering and different "animation" phases to different parts or branches and using the afs foliage tool to set up primary and secondary bending you should be able to use those models within unity. and it should take you may be 5 – 10 min to make the basic setup. of course you can spend hours tweaking it…


    lars
     
  50. Project-Mysh

    Project-Mysh

    Joined:
    Nov 3, 2013
    Posts:
    223
    Hi Lars,

    First of all thank you for your support in this thread, but i want to make a petition to you. There is full documentation in your shader pakage, but for some people like me, we will appreciate if you did a video tutorial to see how all this shaders and scripts can be implemented to get unique enviorments. Is this possible? ( like 10 min video showing how to implement correctly shaders, and whats the best way to optimize the vegetation ).

    Thank you very much for these incredible shaders!