Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

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,848
    that is due to lighting: single sided geometry does not give you "correct" translucent lighting without hacking the deferred lighting shader.
    but the deferred foliage shaders use single sided geometry btw… faking some kind of translucent lighting.
     
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    well, your alpha values should be correct. you may use grass importer script to check if this helps.
     
  3. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    888
    I see on you screen shot that you use Texture repeat and not clamp. That's a mistake anyway.
     
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    well, not really. but there should be some border around the different textures in case you use a texture atlas in order to avoid pixels bleeding from one texture into another (i suppose you have been writing about the pixel artifacts at the top of the grass...)
     
  5. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    888
    Hi Lars,
    some questions:

    A) Terrain_Details_AfsNTS
    Can I have only one Combined normal texture for the whole foliage?

    B) I want to place different grass areas. Lets say we have a larger filed where the grass should be disabled at distance 500m and some other high density inner city stuff that should be disabled at 100m. Is this possible?

    C) Does the fade out grass with .alpha in your shader has any performance advantage?
     
    Last edited: Apr 19, 2016
  6. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    yes, only one combined normal.
    Nope, not when using the terrain engine as it only offers one single draw distance parameter for all details.
    if you used manually placed and combined chunks of grass it would be possible as you could place those on different layers. but you would have to add a culling and streaming system and duplicate the grass shader to support different fading distances.
    btw. draw distances of 500 m will most likely kill your frame rate.
    compared to – what? it simply fades out the grass.

    lars
     
  7. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    888
    I want to duplicate the Shader and including a property (distance multiplier) and duplicate AfsWavingGrass.cginc + AfsWavingGrass.cginc also. Then changing logic a bit to override all effects at larger distances. If this requires another draw call it doesn't matter. I will try this.

    If I place meshes manually, then the mesh exist for the engine (to render), no matter of setting .alpha in the shader to 1 or 0. But, if there is no performance advantage between alpha 1 and 0, then I will set alpha to opaque for all grass meshed I have set manually (and combined for sure).

    It would be interesting to know, if there is a noticeable performance difference between alpha 1 and 0 on the whole surfaces on large grass Mesh-Combined arrays. So in my opinion you fade the meshes are set manually with alpha, to have a conform visualization with the terrain grass?

    1) Unfortunately the shadowed areas become reflective on your terrain, while set lightning to Directional Specular. It's a Unity bug?

    2) Does your Combine Utility take care of max vert limit?
     

    Attached Files:

    Last edited: Apr 21, 2016
  8. artistpetemac

    artistpetemac

    Joined:
    Sep 8, 2014
    Posts:
    19
    Hi Lars and AFS family,
    I've encountered a PS4-only bug. I have a mix of grass planes and custom modeled flowers among my detail meshes. In the wind the custom meshes are "skating" as if their vertex colors were all white. They are animating correctly on the PC. I don't see any shader compile errors or anything. Any Ideas?
    -Pete
     
  9. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,523
    When they are screwed up like this are they shaded like the AFS detail or the original AO detail?
     
  10. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    I have gotten myself confused, so let me start with the basics.

    I have a terrain with Speedtrees on it. Can I just add the Advanced Foliage Shader script to my hierarchy and gain the benefits of AFS?

    Or do I need to modify the Speedtrees to use AFS specifically?
     
  11. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    that is not the grass but the grass texture on the terrain. and the terrain uses a built in shader. so it is a unity bug :)
    it does not... you will get an error if you reach the limit. so you will have to distribute your grass over several parent objects.
     
  12. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    not really... does the built in grass shader for the terrain work on ps4?
    lars
     
  13. DenisLemos

    DenisLemos

    Joined:
    May 1, 2015
    Posts:
    769
    Hi!

    I have some problems and maybe your asset is the solution!

    My scene will have multiple biomes and day/night cycles, so I have bought several packages vegetation of Asset Store. The problem is that each developer creates their assets in different way.

    Some packages come with LOD trees and other packages come without LOD!

    I bought these days this tropical vegetation package that is very good and I recommend it to everyone.
    https://www.assetstore.unity3d.com/en/#!/content/49391
    The author of this package already reported that in the next update, all the trees will come with LOD and shader that supports night scenes. I will use these shaders also in other packages that the trees come with LOD, then this problem is solved.

    My big problem is with the packages that trees come without LOD, because I need to use them as regular trees. The problem is that the shader "Nature/Tree Soft Occlusion Leaves" not ...
    * Not support night scenes;
    * No receive shadows;
    * The billboard trees do not draw to the depth buffer;

    I'm using the Unity5.3.4 and when I switch to the shader "Nature/Tree Creator Leaves" trees work in night scenes, but ...
    * Continue without receiving shadows;
    * The billboard trees no longer work;

    So I wonder if ...

    * Can I use your shaders as regular trees with the packages that I bought in the Asset Store?
    * Your shaders support night scenes and receive shadows?
    * The tree billboard draw to depth buffer? Because I use my own sky system and the fog scattering is an image effect and works in the same way that "GlobalFog".

    Thank you and I'm sorry for asking so many questions!

    Denis Lemos
     
  14. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    hi denis,
    afs tree shaders only support trees which are modeled using the built in tree creator...
    yes.
    not out of the box as like the built in billboards they use alpha blending.
    but it is quite easy to make the billboard shader use alpha testing instead.

    lars
     
    DenisLemos likes this.
  15. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    Have you looked at the new gpu instancing stuff in unity 5.4 beta?
     
  16. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    yes. instancing will come to afs pretty soon :)
     
  17. docsavage

    docsavage

    Joined:
    Jun 20, 2014
    Posts:
    1,015
    Hi @larsbertram1, I have been mentioning this fantastic asset a bit lately on a few of the threads I follow. I have been impressed with the new GUI that Nathaniel from terrain composer has implemented with TC2. Do you think it would be possible to make a similar GUI to aid in the use of AFS. Maybe even ask Nathaniel if it is possible to integrate AFS into part of the terrain creation process and even use the same gui just with a different color code to show that it's the AFS asset being use at that stage? Just dropping in prefabs assign a tag to let it know what is being created and let the system do the rest.

    Thanks

    doc
     
    magique likes this.
  18. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    hi there,
    i am not very familiar with terrain composer and only had a quick look on the old version, but i am pretty sure that also the new version of terrain composer let you spawn any kind of game objects – including plants using afs shaders.
    so i do not see the "need" to add this functionality to afs too. it all started with just a bunch of shaders and already has grown too much i have to admit.
    so i am glad that there are other developers providing tools to e.g. distribute plants auomatically :)

    but if ther eis a talented c# programmer out there who is interested in developing a quad or oct tree based distribution, streaming and culling system for plants and greeble i am more than interested to support this project.

    lars
     
  19. docsavage

    docsavage

    Joined:
    Jun 20, 2014
    Posts:
    1,015

    Thanks for the reply @larsbertram1,

    I was thinking more of a more visual interface system for using AFS but I see it's probably overkill.

    Re the streaming/culling system etc have a look at Tree Manager System by ElroyUnity. He is changing it to uNature for version 2 and I mentioned AFS in that thread. It works a bit different but he said he is open to suggestions for the new version. I am not affiliated in any way but he has included me in the beta test and he seems like a top bloke. Have a look here - http://forum.unity3d.com/threads/co...actable-trees-multithreading-and-more.401139/

    doc.
     
    Last edited: May 13, 2016
  20. Marked

    Marked

    Joined:
    Feb 24, 2015
    Posts:
    32
    I am sorry if it was asked before but is it possible to change the single sided deferred shader to work with " speed tree " fading LOD system ? Or it doesn't work that way.
     
  21. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    that does not work just out of the box: you would need LODs. and you would need billboards…
    however – my custom tree importer does support speedtree like fading lods :)
    https://www.assetstore.unity3d.com/en/#!/content/21079

     
  22. Marked

    Marked

    Joined:
    Feb 24, 2015
    Posts:
    32
    Thank you for a fast answer !

    Ah yes , I already bought the custom tree importer and it's a great tool. :))
    But I would really like to have the fading also on the AFS deferred shader.
    What I am doing at this moment is combining all the grass meshes in a single mesh and I use a LOD group to disable them.
    And would love to have the fading on them so they could fade in smoothly with out just popping :)
     
  23. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    unfortunately i guess, there is no way to achieve this without having proper LODs and billboards.
     
  24. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,523

    What about just alpha cutout increase fading at a specified distance like the grass detail shading. Can enable and set the distance in the Setup AFS and the 'unique' AFS shader cutout alpha increases at that number. Than the LOD pops a little after that distance. Not as good a solution as using CTI but can still work.
     
  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    unity's LODs switch based on "screen size" – not distance. and fading between 2 LODs like you described would need both LODs to be rendered during the transition using the cross fade feature.
    that might "reduce" the need of both LODs having the same bending values although it still would be fine. last but not least the billboard...
    the custom tree importer already addresses most of this – the foliage shaders do not. so it would be way easier to start from cti than starting from afs.
     
    Marked likes this.
  26. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,523
    Not fading between LODs but just fade out in general. All the LOD would do is remove the mesh a little further than the set fade distance. Not a solve all like CTI but kind of a cheat for smaller foliage. So groups of foliage can be combined in Unity and still fade away at a distance.
     
    Marked likes this.
  27. tombombadil1988

    tombombadil1988

    Joined:
    Feb 21, 2015
    Posts:
    20
    Hey Lars,

    I'm using your shader on an iOS Project running at 60fps with many trees using your shader. However if the camera zooms into one of the trees the fps will drop to 35fps. It doesn't matter how many trees are in view but which percentage of the cameras field of view is filled with your shader. This seems odd to me.

    Best, Tom

    Bildschirmfoto 2016-05-19 um 14.17.05.png
     
  28. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    well, that should be easy then :)
     
    Marked likes this.
  29. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    hmm, "which percentage of the cameras field of view is filled" sounds as if it would be a quite heavy pixel shader – which it is not.
    have you tested your scene using the built in shaders too?
     
  30. tombombadil1988

    tombombadil1988

    Joined:
    Feb 21, 2015
    Posts:
    20
    Yes. There is a slight drop in fps (2-3) when I use the standard shader.
     
  31. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    that is really pretty odd.
    are we talking about bark or leaves?
    or both?
     
  32. tombombadil1988

    tombombadil1988

    Joined:
    Feb 21, 2015
    Posts:
    20
    Just the AFS Foliage Shader used on ordinary single mesh.
     
  33. Marked

    Marked

    Joined:
    Feb 24, 2015
    Posts:
    32
    Ah yes , it's a good solution for only using the small ground details but in my case I also combine my "trees" with the same shader to improve performance.
    So for example I have combined grounds plants in one single mesh and combined " trees" in a different mesh. What would be interesting for me is to fade out the small plants faster then the trees to nothing. Right now it works but I just have that popping for the grass plants since the fade out pretty soon. That's why I taught " speedtree" fading would look more natural.

    Anyway thank you guys for thinking with me ! I will try to search for a different fading solution.
     
  34. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,238
    Is a Unity 4-compatible version available, or should I use as Foliage Package v2 instead?
     
  35. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    you will have to use v2, sorry.
     
  36. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    hmm, pretty strange. the pixel shader is quite simple in case you have set "rain" to 0.0, have you?
    so right now i do not have any explanation, sorry.
     
  37. tombombadil1988

    tombombadil1988

    Joined:
    Feb 21, 2015
    Posts:
    20
    Yes rain is set to 0. I will poke around a litte more.
     
  38. bome99

    bome99

    Joined:
    Sep 14, 2009
    Posts:
    119
    Hi got a question.

    My touchbending shader makes all the shadows on my gameobject totally black?
    I'm using deferred rendering.

    Is there a quick way to fix that?
     
  39. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    the afs touchbending shader does not do this… at least not in the officially supported unity versions.
    some more details?
     
  40. bome99

    bome99

    Joined:
    Sep 14, 2009
    Posts:
    119
    The Changelog says
    version 4.02

    Running unity 5.3.4f1

    Just updated from the store, do I have to update unity?
     
    Last edited: May 23, 2016
  41. bome99

    bome99

    Joined:
    Sep 14, 2009
    Posts:
    119
    It doesn't seam to have any thing to do with the scenes light settings.


    Grass02.jpg


    Grass.jpg
     
  42. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    i just checked the included touch bending demo which works fine (unity 5.3.4 / os x).
    you may have to sync touch bending and regular material.
    btw: the color for specular reflectivity looks strange as it should not be black…
     
  43. bome99

    bome99

    Joined:
    Sep 14, 2009
    Posts:
    119
    ok, yeah I can see it works in the demo scene, I have no idea why my version doesn't work. Can be the mesh I use? I only have alpha values on the verteices
     
  44. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    could be the mesh and its vertex colors, yes.
     
  45. lanceeric

    lanceeric

    Joined:
    May 24, 2016
    Posts:
    2
    When the AFS optimized tree shaders get created the textures become really low res, and the leaf texture resets to default tiling.

    How do I stop this from happening?
     
  46. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    unity won't create tree textures bigger than 1024x1024 – no matter which shader is assigned.
    i am not aware of this – probably because this is pretty much what most trees need…
    nevertheless you should be able to edit the material and adjust tiling to your liking.
     
    lanceeric likes this.
  47. lanceeric

    lanceeric

    Joined:
    May 24, 2016
    Posts:
    2
    Thank you, thats what I thought. One more though: when using the simple tree shader with a manually created tree mesh, the bark texture becomes black.
     
  48. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    right out of my head: vertex colors?
    indeed the shader does not distinguish between bark and leaves: it is all one.
     
  49. devstudent14

    devstudent14

    Joined:
    Feb 18, 2014
    Posts:
    133
    Hey, just purchased AFS. I'm a little worried that I made a mistake. I bought the asset because I wanted to add leaf movement and translucency to my custom trees. I don't use speed trees or terrain trees.

    Can this asset be used on non-terrain trees? If so, where is the documentation that outlines how to add movement and translucency to leaves?
     
  50. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    that should be absolutely fine. just use one of the "regular" foliage shaders.