Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Advanced foliage shader [released]

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

  1. lifeon

    lifeon

    Joined:
    Jun 14, 2017
    Posts:
    3
    Hey, little baffled by some shadow and wind bending issues right now with afs
    Unity version 5.6.1f1 , - - AFS Setup prefab in scene, light set to linear, custom internal shaders added in graphics, have re-generated lighting multiple times
    I wanted to switch some tree creator trees to the afs versions of the shaders, and I referenced the included conifer on how to set up the materials and components, but the shading was replaced with something harsh and I can't figure out how to change it and nothing in the manual points to what I've done wrong. The wind will also appear correct if I am outside play mode and have a particle selected, but in play mode it doesn't move, meanwhile the conifer and the other tree do have wind.


    Left tree is using the original tree materials, unity's normal tree creator stuff
    Middle tree is the same materials set to be afs shader but appearing with harsh light and no wind in play mode
    Right tree is the included conifer which does have it's wind effects in play mode still

    Middle tree's components


    example of the wind working in scene but not play mode

    edit: gif broke https://i.gyazo.com/a6d0fcfc9aa04ae608b4255090c1408c.gif
    ...Help? Is there some button I missed pressing?
     
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    the screen shoot from the inspector tells you the reason why your tree does not bend in play mode:
    it is set to be statically batched. uncheck this and it should bend in play mode as well.

    regarding the harsh lighting: it looks as if the tree does not get any ambient lighting. so you may try to lower the ao in the tree creator settings.
     
  3. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    what kind of integration do you think of?
     
  4. DrInternet

    DrInternet

    Joined:
    Apr 6, 2014
    Posts:
    106
    Having more shaders compatible with Vegetation Studio. As far as I understand from documentation and your posts there is just one foilage shader for now. What about bark or leaves shaders?
     
  5. LaireonGames

    LaireonGames

    Joined:
    Nov 16, 2013
    Posts:
    705
    Hey folks,

    I am looking to add texture arrays into this (worth looking into btw!) so I can use one material for multiple variants of grass with different textures. However when I try to change the input struct to support xyz for UVs (needed by texture arrays) I get this error:

    "Shader error in 'AFS/VegetationStudio/Foliage Shader': cannot implicitly convert from 'const float2' to 'float3' at line 338 (on d3d11)"

    Any ideas? To see for your self change line 101 in the non instanced foliage shader to:

    float3 uv_MainTex; or float3 uv_MainTex : TEXCOORD0;

    I couldn't spot anywhere obvious I was missing to change, guessing its in an include file
     
  6. lifeon

    lifeon

    Joined:
    Jun 14, 2017
    Posts:
    3
    ohhhh Thank you!
     
  7. Yuki-Taiyo

    Yuki-Taiyo

    Joined:
    Jun 7, 2016
    Posts:
    72
    Hello,

    I've just bought AFS yesterday and I wait to know how to use it properly before giving a review. Everything of it feels quite like "all over the place" and "left as it is" (for example I don't know what the demo scene is supposed to show). It would be nice to make it more presentable because it looks messy in the surface, yet I'm sure it's an excellent asset in the depths.

    I'm encountering some issues, yet I have to say I haven't red the user manual enough from now.

    1) I can't get any physics "out of the box" from the plants. Can someone explain how does it works ?

    2) The AFS shaders doesn't work anymore after restarting Unity. There are no wind effect and translucency anymore.

    3) How can I change the vertex colors / wind strenght on the plants ?

    4) I see there is an Uber integration. What can I gain from it as I already own Uber ?
     
    Last edited: May 11, 2018
  8. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    you are welcome :)
     
  9. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    hmm, there is no non instanced foliage shader anymore, is there?
    but my first thought: uv_MainTex is some kind of "predefined macro". so i assume that you can not simply set it to float3.
    you would have to rename it to e.g. myuv_MainTex and set it manually in the vertex shader.
     
    LaireonGames likes this.
  10. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    i appreciate this decision very much!
    and you are probably right when you claim that it is difficult to get the benefits at a glance: afs has evolved over 5 years now and combines a lot of different solutions i have developed over the years.

    in case you want any interaction you have to use touch bending. this needs you to place all plants the player should be able to interact with as single game objects. the touch bending demo would be the right place to start from.
    brief introduction: all plants which the player should be able to interact with need a collider and the touchBendingCollision script attached to. the player and npc need the touchBendingPlayerListener script.
    i have never heard of such an issue...
    edit the vertex colors in your 3d app or using the included foliage tool.
    afs ships with its own deferred translucent lighting shader. so in case you already own uber and use it you will have to use the uber deferred lighting shader. in this case you can make the afs shaders output proper translucency values so you can use afs shaders whose lighting finally is rendered by uber.

    please refer to the docs to find out more.
     
  11. LaireonGames

    LaireonGames

    Joined:
    Nov 16, 2013
    Posts:
    705
    It looks like there is so far as I know. Info looks good thanks will try it out later
     
  12. Yuki-Taiyo

    Yuki-Taiyo

    Joined:
    Jun 7, 2016
    Posts:
    72
    Okay, I just thought Touch Bending was for touch screens, lol... So I have to test that.

    In fact, I got the shaders to work by opening a AFS demo scene, but they don't work if I start my scene directly.

    Edit : I copy-pasted the AFS Setup object in my scene and the shaders work from here.
     
    Last edited: May 11, 2018
  13. LaireonGames

    LaireonGames

    Joined:
    Nov 16, 2013
    Posts:
    705
    Ahh I see part of why it wasn't working. I was editing: VS_AfsFoliageShader but didn't seem to have an effect in the inspector, changed to the instanced once and changed the name and now its working.

    2 things I learned:

    I forgot to add this line to the vert shader (right after initialise output):

    o.vuv.xyz = v.texcoord.xyz;

    Also needed the tag:

    float3 vuv : TEXCOORD0;

    Now its finally happy :D I hope... gotta make an array now to test this
     
  14. Necka_

    Necka_

    Joined:
    Jan 22, 2018
    Posts:
    488
    Hi there,

    I'm working on converting a bunch of my trees to Mesh with AFS Foliage Shader (the VS version actually as after many tests I managed to get a huge boost in performance with Instanced Indirect trees - from 80 fps with regular trees, 150 with instanced and almost 300 fps with instanced indirect.)

    So I did a few trees which was ok but I can't manage to do the bushes (from the same creator). The leaves just disappear.

    Here is the bush:

    Image 001.jpg
    Image 002.jpg

    Then I use the converter
    Image 005.jpg

    And got this as a result:
    Image 006.jpg
    Image 007.jpg

    I'm sure I'm doing something wrong but I've tried many things and can't get it.

    I think I got the leaves when I use only Vertex color but then the branches goes all out like crazy bending up and down out of the bush.
     
  15. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    hmm, it is quite difficult to say anything concerning our bush problem. so these are just some random thoughts.
    - you set texture split to: two by one - although it should be one by one as far as i can say. just have a look at your combined normal/rans/smoothness texture: it is split 2:1 whereas the ablebdo seems to be split 1:1.
    - modeling the "trunks" out of real geometry does not look very efficient for this model: you waste a lot of vertices and triangles just for these super slim somethings... actually your bush looks more like some kind of grass.

    nevertheless the script should be able to convert the generated mesh.
    does it throw any errors?
    how does the mesh look like if you assign e.g. the standard shader or set alpha cutof to 0? do both parts (bark nd leaves) show up?
     
  16. LaireonGames

    LaireonGames

    Joined:
    Nov 16, 2013
    Posts:
    705
    Any idea why this is happening when I disable variance (the random dark patches):

    https://drive.google.com/open?id=1E6dzwI6VIWB6nqnZ56cq_yOfiVwlbrBl


    So in this image I have a random rotation applied and we can see dark patches. They are a bit random so in the next image it might make more sense


    https://drive.google.com/open?id=1czEdw3RvmCTweXl40i5qd3dNBdl-VKAN


    This is the non rotated version and its predictable when this happens but can't figure out how to fix it :p I have made my own shader and only use the vertex bending/animation components. The shader renders as I would like before I add your vertex stuff but as soon as I add it, the colours change as well.

    Any idea why?

    This was taken from the instanced foliage shader, but its effectively only using FoliageBendingInstanced includes file along with the AfsFoligeBendingGSFull vert method in my shader. I can also recreate this within the Foliage shader but made my own shader to make 100% sure I wasn't missing anything.

    Edit: pictures didn't want to work :/ so using links to my drive instead
     
  17. kepesh

    kepesh

    Joined:
    Dec 29, 2017
    Posts:
    92
    Hi,

    Is there any way to get grass to bend with contact with objects?
    This is by far the best looking grass shader but my game doesn't work without grass bending.

    Thanks
     
  18. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    you will have to add it yourself, sorry.
     
  19. vividmesh

    vividmesh

    Joined:
    May 14, 2018
    Posts:
    1
    Any plans to support the new LW or HD pipelines?
     
  20. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    when they are out of preview: yes.
     
  21. LaireonGames

    LaireonGames

    Joined:
    Nov 16, 2013
    Posts:
    705
    Any thoughts on my post?
     
  22. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    oh, sorry.
    i thought i already answered – but my answer got lost and never sent.

    in case you use a custom shader based upon the foliage shader you have to keep in mind that this shader does lighting according to the vertex normals.
    so it will never give you smooth lighting as you might expect from grass – unless you tweak the normals of your model manually and make them all point upwards.

    actually it does not look as if you have disabled color variation.
    but to say more i would have to know
    - how your shader looks like
    - how you place grass on your terrian: usind the combine children script, as single game objects, ...
     
  23. LaireonGames

    LaireonGames

    Joined:
    Nov 16, 2013
    Posts:
    705
    No worries it happens.

    Huh interesting, never thought to try that (making all normals face up) but will give it a try

    Colour variation is 100% disabled. Removed it from the shader entirely (but did keep the variables to turn again later, so unless the includes read them it should be disabled. Regardless, I even set the values to both be white so its not on)

    The shader itself is nothing special, its variation is using texture arrays instead of textures.

    The model is the part that will no doubt be the cause, its a single mesh of all the grass you see in the screenshots. So its a voxel game and if its a grass block then its mesh data is fed into a chunk which is rendered with this shader.
     
  24. LaireonGames

    LaireonGames

    Joined:
    Nov 16, 2013
    Posts:
    705
    Sweet that did the trick! Setting normals to:

    Code (CSharp):
    1. o.Normal = half3(0,0.5f,0);
    Did the trick :D Could of course do this as a texture as well but quick and dirty way to check :p Was driving me nuts since I was eliminating specular components and still get a shiny effect as well so I knew it was linked.

    Anyway thanks for the help, really appreciate it
     
  25. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    320
    Before I acquire this from the store...
    Does the grass shader here receive lights? I'm looking at options of course...but light affecting it's colors are a must for me.

    As the built in one is not affected by the local light...nor does it cast shadows.

    I looked at your other package for foliage but this one includes the bending and touch features which makes it more attractive for me.
     
  26. led_bet

    led_bet

    Joined:
    May 5, 2015
    Posts:
    83
    Hey! I'm really impressed with all the features of AFS. Used it a few times to render medium to far away foliage in background scenes. Working with it now in some forest levels. Is there any integration with lux's parallax or tessellation features? I'd really like to enhance the silhouette of nearby tree trunks with some surface irregularity.
     
  27. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    yes, grass is light in realtime.
     
  28. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    sorry, the afs tree shaders do not support tessellation.
    the problem here is that tessellation will most likely create cracks at uv seems.
    but in case you may spend some time on reworking the tree models you could have a look at my custom tree importer which supports tessellation.
    https://assetstore.unity.com/packages/tools/modeling/custom-tree-importer-21079
     
    led_bet likes this.
  29. Dreamaster

    Dreamaster

    Joined:
    Aug 4, 2014
    Posts:
    148
    Is this asset the only way to get Global Illumination to work with Tree Creator trees?

    OK I finally figured it out. Old Tree Creator trees don't have "Light Probes" turned on by default in their mesh renderer settings. Turn it on... profit.
     
    Last edited: May 28, 2018
  30. led_bet

    led_bet

    Joined:
    May 5, 2015
    Posts:
    83
    Great, thanks for the reference.
    How does the tree importer and afs work together, if at all?
     
  31. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    the custom tree importer lets you "import" either a) trees which are compatible with the tree creator ones or b) trees which use lods and real time lit billboards just like speed trees.
    while b) uses its own shaders a) might use the afs tree creator shaders.

    but as you are looking for tessellation you would have to choose b).
     
  32. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    Hello @larsbertram1

    I have a problem that I do not know if it is normal or how to solve it.

    I try to make a compilation of my scene that has vegetation with AFS 5 but the compilation is always blocked in (Packaging asset - sharedassets0.assets). And the compilation does not advance.

    I have tried with my own scene and with an example that you have in the examples (LOD Groups Demo) and the compilation is always blocked in the same place.

    In some of the tests I have done I have been waiting for up to 40min before removing it. Although to remove it I had to close Unity from the task manager because Unity is blocked and does not respond.

    I have tried other scenes without putting their asset and everything compiles perfect and fast. But the moment I vegetate with AFS in my scene or just compile with the one that you have called example (LOD Groups Demo), it blocks and never compiles.

    I'm using Unity 2017.1.1f1

    Can you give me a solution?

    I await your response, greetings.
     
  33. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    not really.

    i just made a build from the "LOD Groups Demo" scene which actually took a while - like 3 min on my core i7 laptop using unity 5.6.3.
    if you open the task manager you will see that unity creates a lot of shader compilers instances which actually run at full speed. so the lod version of the foliage shader creates a lot of variants which all get compiled out.
    that simply takes a while.

    it works fine in unity 5.6.3. and should do in 2017.1 as well. i can't check 2017.1 right now as i do not have it installed.
    so just let it run over night.
     
  34. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    Well, I'm going to try what it tells me and I'll try to try another version of Unity to see if the same problem happens to me, because I do not see it normal what happens to me ... I have an i7 too, 32gb of Ram ... etc etc. ... that is to say that I have a good pc ....
    Apart I do compilations sometimes with quite heavy scenes and I never had this problem ....
    I have done a lot of tests to isolate the problem and realize that what happened through the AFS

    I mention something in these days ... Greetings and thanks for the response.
     
  35. jamesnw

    jamesnw

    Joined:
    Mar 23, 2013
    Posts:
    51
    If I wanted to use this on a spherical planet (where UP is NOT always Y, obviously), would there be any issues?
     
  36. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    wind is not spherical. and billboards will most likely break too.
    unless you do the mapping to the sphere after all the vertex animations.
     
  37. unity_dev3194

    unity_dev3194

    Joined:
    Apr 17, 2017
    Posts:
    79
    AFS_distant.PNG AFS_distant.PNG
    Hey there, lovely asset -- great replacement for SpeedTree (the lack of PBR support has been killing me). I'm having a problem that you could maybe help me with. The example trees you included look amazing up close, but look terrible from afar. I'm not sure if that's a result of me setting things up wrong? I would really appreciate any pointers.
     
    Last edited: Jun 28, 2018
    Lex4art likes this.
  38. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    at far distances the trees are just regular old style unity billboards
    although i think that they do not look too bad.
     
  39. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    Hello @larsbertram1

    One question ... Where is the prefab "Grass SingleSided Pre" that says in your manual in point 15 of "Quick Start Guide"?
     
  40. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    this might have been removed or renamed over the years...
    try "Grass Prefab" instead.
     
    ftejada likes this.
  41. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    ok. Thank!!
     
  42. RPowers

    RPowers

    Joined:
    May 14, 2015
    Posts:
    122
    Hi. I'm having some issues getting the leaves to render property. When I have my leaves use the Nature/afs tree creator leaves shader they display white pixels around the leaves (see attached). Also, the white pixels only show up when certain meshes and shaders are behind the leaves. For example, they show up when my water and village house objects are in the background and don't show when the sky or terrain is behind. Swapping the leaves shader to Nature/tree creator leaves work fine, no white pixels visible. Any ideas as to why this is happening? I just updated afs to the most recent release and I'm using Unity 2017.3. Thanks
     

    Attached Files:

  43. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    i will have to look into this.
     
  44. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    i did a quick test in Unity 2017.4.1f1 on win 10 and dx11 using the "Foliage Shader Overview Demo" scene.
    i placed a giant cube below the trees and assigned a dark transparent material to it as i assume that your water is transparent as well. in order to be able to spot any "cracks" in the depth texture i removed the skybox and replaced it with a single strong color.

    neither forward nor deferred showed up any of your "white" pixels which i think is the skybox coming through :(

    so some more information about your scene would be great.
    which rendering path do you use, forward or deferred?
    which platform and api do you use?
    anything else you think might help to track down the problem?
     
  45. RPowers

    RPowers

    Joined:
    May 14, 2015
    Posts:
    122
    I think the water asset I'm using is causing the problem, sorry about that. I'm seeing the same effect happen on the terrain in some places, so it's not just the trees. It just happens to be way more obvious in the leaves of the trees. My terrain also uses a custom shader, so it could be that the water I'm using isn't friendly with other shaders besides standard. Anyways, thanks a lot for looking into it!
     
  46. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    ah, i see: artifacts from refraction and depth based water coloring.
     
  47. Frozmat-Games

    Frozmat-Games

    Joined:
    Dec 17, 2012
    Posts:
    25
    Hello. Сan anybody help me with this? First two pictures from the demo scenes "Foliage Shader Overview Demo" (normal) and "Foliage Shader Overview Demo rainy" (broken). Only one scene from this asset works (Foliage Shader Overview Demo) and no matter what I do shader looks completely wrong. New scene, reimport - doesn't not help.

    I'm using Unity 2017.4
     

    Attached Files:

  48. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    i guess so :)
    "Untitled-5-2.png" and "Untitled-5-3.png"shows up wrong colors as the camera uses deferred but you do not have assigned the afs custom deferred lighting and reflection shaders.

    just do so following the description in the docs and everything should look fine:

    In case your camera uses deferred rendering you also have to assign the Afs deferred lighting shaders in Edit -> Project Settings -> Graphics:
    - Under the Built-in shader settings change Deferred to custom, then assign the Afs_Internal-DeferredShading shader.
    - Also change Deferred Reflections to Custom and assign the Afs_Internal-DeferredReflections shader.
     
    Frozmat-Games likes this.
  49. Frozmat-Games

    Frozmat-Games

    Joined:
    Dec 17, 2012
    Posts:
    25
    Hello. I need help, again.)
    Is there are step by step instruction on how to properly setup a tree modeled in 3ds max so that it works with AFS? I paint model with vertex colors like "Banana tree" in demo, but no matter what I do, bending is all over the place. And the second question is - what to do with the normal map? I have an normal map, but why in demo all normal maps are green and pink? Why PSD?

    I'm really sorry, but this is all just counterintuitive.)
     
    Last edited: Jul 15, 2018
  50. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    the banana should be called "banana plan" instead of tree, as trees a quite complex and usually made out of 2 different materials: bark and leaves.
    anyway – in case you manually paint the vertex colors you have to chose a proper "bending mode" in the foliage shader which most likely will be "vertex colors". in this case:
    - red stores the phase variation,
    - blue the secondary bending,
    - green edge flutter and
    - alpha stores main bending.

    i am not sure about 3dsmax and vertex color alpha, but a lot of other 3d apps (like blender) does not really let you paint it, so i recommend to simply ignore it in 3dsmax and use the foliage tool to add it right inside of unity.
    blue also is a bit tricky as it is supposed to be a smooth gradient. here again you may simply rely on the foliage tool.

    in order to add some phase variation you should paint vertex color red: choose a main branch and all its sub branches and leaves and assign e.g. red = 0.2. then select the next main branch and all its children and assign red = 0.5, ...
    next you would paint edge flutter into green: select the complete tree and set the green channel to 0.0. then select the outer vertices of your leaves and add some green here like 0.2.
    finally you would import your model, assign the foliage tool and add primary and secondary bending.

    but in case you want to manually create a really complex tree i highly recommend to use the custom tree importer.

    afs uses combined normal/translucency/smoothness textures:
    https://docs.google.com/document/d/...Y5H46FtpSDM1UQdRk/edit#heading=h.qyhixri8rbec
     
    Frozmat-Games likes this.