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
    right now afs only lets you paint single grass instances onto custom meshes using the free geometry brush which is included in the package.
    you should combine these single instances into several patches of e.g. 15x15m size using the combine children script from the package.
    unfortunately adding a lot of these patches to your scene will increase mesh memory dramatically.
    so unless you use some kind of streaming/pooling solution you should not add too many of these patches.
    i am working on a solution which will store these patches in a more compact way so you should be able to add more manually placed grass without running out of memory.

    meanwhile you could have a look into the critias foliage system:
    https://www.assetstore.unity3d.com/en/#!/content/99233
    it offers something similar to what i have mentioned above. right now it only supporst speedtrees and speedtree grass but i am working on afs support which will come pretty soon.
     
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi there,
    i have just submitted version 5.06 which brings basic support for the Critias Foliage system whih lets you place grass and foliage everywhere without massive overhead or mesh memory usage.
    i also fixed issues concerning unity's new mixed lighting mode – so baked shadows will just work.
    i hope update 5.06 will be available within the next days.
     
    zmaxz likes this.
  3. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi there,
    version 5.06 now is available.

     
    Baldinoboy likes this.
  4. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    Whoa-- so is this Critias support just for AFS grass, or for tree (tree creator) trees too?
     
  5. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    Hello! Any tutorial on how to use this asset ? What kind of bushes, grass & trees can it be used with? Is it like prefabs or just a shader ? Gena friendly?
    //
    M
     
    Last edited: Oct 19, 2017
  6. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    critias foliage support is only added for the foliage shader and a (new) grass shader.
    unlike speed trees (…) tree creator trees already are pretty fast, so they would not really benefit from using critias. not to mention that billboarding would not be supported.
     
  7. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    afs comes with shaders for foliage (like fern and smaller bushes), grass (for grass and flowers) and improved tree creator shaders which support pbs and way better billboard transitions.
    foliage and grass can be placed manually as game objects and combined into patches using the included combine children script, can be placed and rendered using the critias foliage system or the built in terrain engine.
    i think using gena to spawn grass, foliage and trees should not be any problem.
    the package comes also with some other scripts like the foliage tool, which lets you set up your vegetation models right in unity: bending information has to be baked to vertex colors and/or uvs and the foliage tool minimizes the work you have to do in your 3d app to do so.

    find out more here:
    https://docs.google.com/document/d/164MTEnV_-krBdMr-20QhPttY1bY5H46FtpSDM1UQdRk/edit
     
  8. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151

    Great! I just bought it and it works great with my grass and bushes (that have meshes)... But trees... When it gets converted it looks like this .. Why is it all black?
     

    Attached Files:

  9. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    what was your tree originally before you converted it?
    a tree creator tree?

    why did you convert it?
    it seems to have a rather fat trunk – which will look a bit odd if it uses the folaige shader for both leaves and bark.
    simple trees are fine for bushes or trees which do not have a fat trunk as bark rendering will use wrapped around diffuse lighting...

    in order to find out why the tree is just black you may:
    • look through the textures. do they look odd?
    • switch to deferred and go through albedo, normal and spec buffer. does any of these look odd?
     
  10. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    I tought it would look and behave better and more beautiful with afs... but I leave it be.
    Bushes works kind of well.. I´ll figure it out =)

    Btw, spawning with gena works great and the combine optimization afterwards =)..

    Is this usable with tenkoku dynamic sky like out of the box or do you know how? .tought about the wind.. because tenkoku controlls it.
     
  11. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    The linear setting do screw things up in game window when I edit because gaia and tenkokus assets dosent obviously like it.. everything is streched out... works fine when i hit play tough
     
  12. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i do not own the tenkoko dynamic sky.
    but afs does not do anything in case you switch between gamma and linear except from the fact how billboard lighting is handled by the rendertexture shaders. everything else is simply handled by unity – or other assets which do something according to the color space.
     
    mattis89 likes this.
  13. jjobby

    jjobby

    Joined:
    Nov 28, 2009
    Posts:
    161
    Hi, the document said that if I use combined foliage then I don't need instancing. But from my testing, I still need to enable instancing in the material of combined foliage. Or else it would bend incorrectly. Is this a bug or document error? By the way, I'm still using version 5.02
     
  14. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    might be an error in the docs.
     
  15. JMeer

    JMeer

    Joined:
    Mar 3, 2017
    Posts:
    29
    We have just updated to Unity version 2017.2.0f3. And the shadows of the AFS/Foliage shader seem alot darker. I have made a comparison screenshot, made in a empty scene with default lighting settings. We are using a simplified diffuse approach for the shader. In our game we have disabled reflections in the lighting settings but you can see reflections here because of the default settings.

    Got any ideas? Thank you for your time!

    Palmtree_wrong.jpg
     
  16. Game-Armada

    Game-Armada

    Joined:
    Apr 29, 2013
    Posts:
    66
    After learning this tool, modifying the vertex colors, adding some extra tweaking properties to shaders, made my prefabs compatible for terrain painting, I have put together this test scene today:
    forest_v01.jpg
     
    osss, Baraff, coverpage and 4 others like this.
  17. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    lighting in 2017.2 looks as if it came frome the other side? have a look at the trunk!
     
  18. JMeer

    JMeer

    Joined:
    Mar 3, 2017
    Posts:
    29
    Same scene, same tree, same light, same settings. But other Unity version. Had my colleague take a screenshot with the older version of Unity. I tested the new version of Unity today, because of the upgrades for VR performance. But downgraded back, and it's working again. I will do more testing this weekend.

    Yeah it seems like that in some way, but the shadows on the leaves kinda match up, except for the trunk. I also suspect it might be missing a render pass.
     
    Last edited: Oct 20, 2017
  19. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    strange. i just opened the latest version of afs in unity 2017.2 yesterday and could not see any noticeable difference.
    i have been testing it just a few minutes ago (using forward as i expect that you use it due to vr) and had a look at the included foliage shader overview demo: everything here looks fine.


    as far as lighting is concerned: looking at your screen shoots i doubt that the lighting setup of both matches.
    while 2017.1 seems to have a directional from the left, 2017.2 seems to have a directional light from the right – at least on the trunk. but the lihgting of the leaves does not make much sense to me here...

    do you use real time lighting? or anything baked?

    lighting.jpg
     
  20. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    that looks insane!
    is there any chance you make a video of a fly through?
    and what kind are your trees of? tree creator trees? i doubt those are speed trees due to the translucent lighting and specular highlights.
     
  21. JMeer

    JMeer

    Joined:
    Mar 3, 2017
    Posts:
    29
    The directional light is somewhat from the left. On the second screenshot it is from the same direction. No lightmaps. Its the standard directional light you get when creating a new scene. I went back to 2017.1.0. All ok. Updated to 2017.1.2 still all ok. Im at home this time. So Unity is running on another system. I made a Checkout to our SVN and went to 2017.2. But now the darker shadows are back. Il test it in a new project without VR and keep you posted. Thanks for checking!
     
  22. JMeer

    JMeer

    Joined:
    Mar 3, 2017
    Posts:
    29
    I did some testing in a completely new project. Imported our asset and texture of the palmtree and i have found something interesting! PalmtraaBananaComparison.jpg

    I inserted a 'Banana Atlas single sided UV4 Prefab' and the Palmtree to create another screenshot comparison. On the left we have the scene in Unity 2017.1.2. On the right we have the same scene in Unity 2017.2. As you can see our palmtree is having the darker shadows, but the banana is doing just fine! The model of the Palmtree seems to be fine, so i compared the Materials, and i have found the following:

    Our palmtree is not using a Normal (GA) Trans(R) Smoothness(B) texture, but the Palmtree is. So i used the Terrain_Details_Afs texture from the Banana Atlas single sided UV4 Prefab, and put that texture in the Normal (GA) Trans(R) Smoothness(B) slot of the Palmtree material, resulting in the correct lighting and look.

    It seems the new Unity doesn't work well with an empty Normal (GA) Trans(R) Smoothness(B). We are only using diffuse textures mostly in our project, the Normal (GA) Trans(R) Smoothness(B) is not really required, and because of VR, we love to benefit from any performance improvement we can get.
     
    hopeful likes this.
  23. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    yes, that explains it – although no unity version should handle that as unity has no default or fall back texture for a Normal (GA) Trans(R) Smoothness(B) texture.
    and in case you do not use it i would recommend the comment it out in the foliage shader.
     
    JMeer likes this.
  24. JMeer

    JMeer

    Joined:
    Mar 3, 2017
    Posts:
    29
    hehe that simple! That fixed it thanks!
     
  25. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    Hello! I got this strange thing... my grass dosent look right.. ? bluegrass.png


    Edit: It was the "Intensity Multiplier" that made it look like that... I dont understand that option, it only makes objects and outdoor terrain glow and look like that.... :S
     
    Last edited: Oct 23, 2017
  26. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    it looks as if the grass is neither added using the terrain engine nor that you use the combine children script to bake in the terrain's normals. in this case grass rendering will look odd by design :(
     
  27. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    Its a prefab mesh.. should I add those to the terrain engine?
     
  28. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    either add it to the terrain – or use the combine children script to bake in the normals.
     
  29. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    Okay. But the combine script makes the touch bending not working?
     
  30. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    oh no, it does not.
    so if you want to place the grass mesh manually you will most likely have to edit the normals in your 3d app.
    make all of them mostly point upwards. that is what you need to get a smooth grass lighting.
     
  31. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    I use gena to spawn them.. when I then use the combine script on the parent of my grass childs, the collider disaapears and touch bending is a no go.
     
  32. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    as i wrote earlier: in case you want to use touch bending you must not use the combine children script – but keep all instances a separat game objects.
    fix lighting on these using the method described in my previous post.

    but please keep in mind, that using separate game objects will not allow you to populate your entire scene with touchable grass...
     
  33. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    Okay thank you! I get it now. My grass looks terrible if I add them to terrain engine and paint them that way on my scene... so for me it works with Gena and combine script (on those that dosent need to be touchable).. last question, they moce with your shader, but can i make them static? I know they "move" but not really like a car or player..
     
  34. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    the move in the wind? and their pivots are moving as well?
    in this case you have missed to add proper vertex colors which control bending.
    add vertex color alpha = 0 to the lower vertices that shall not bend in the wind.
    or use the grass model postprocessor to do so: https://docs.google.com/document/d/...Y5H46FtpSDM1UQdRk/edit#heading=h.bf6u68oztuuz
     
  35. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    Yes their pivots move.. vertex color alpha, is it at adjust vertex colors? Wich on rgb or a?

    I guess a is alpha but pivots still move when i set it to 0...

    Nevermind, I reverted it back (I had probably messed it up) and made it vertex colors legacy. Works now :) looks a bit black from certaimän angles but I guess I need to bake and combine.. maybe read the documents more....
     
    Last edited: Oct 24, 2017
  36. Game-Armada

    Game-Armada

    Joined:
    Apr 29, 2013
    Posts:
    66
    Hi!
    I have noticed that my grass (painted detailes, grass meshes) color changes when building the project. (seems like it looses the translucency effect)
    I haven't found any documentation about building and setup.
    Tried to put the shaders to the always include list but not helped.
    Please advise! editor.jpg build.jpg
     
    Last edited: Oct 26, 2017
  37. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    Yes. It would be nice with some tutorial..
     
  38. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    Hi! I saw this has been updated...I´m allready using this asset in my project...how can I update without anything breaking?
     
  39. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    The documentation says the trees can't be lightmapped because uv2 is used for bending. But Unity supports 4 uv sets now, can we lightmap trees now somehow?
     
  40. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    Hello! Can I use occlusion solution that came with this asset? .. or is it enough with Unitys Occlusion culling system?
     
  41. ChinChiaYeh

    ChinChiaYeh

    Joined:
    Sep 14, 2016
    Posts:
    23
    Hi, Can I use Dry and Health noise for grass without Combine child AFS script?
    I need the Dry and Health noise but I don't want to combine grass.
     
  42. Game-Armada

    Game-Armada

    Joined:
    Apr 29, 2013
    Posts:
    66

    I really need some help here :( anyone else experienced this ?
     
  43. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    unfortunately you can't as dry and healthy colors have to be baked to vertex colors.
     
  44. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    the package does not ship with any occlusion system i were aware off. but it is fine to use unity's built in one.
     
  45. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    light mapping trees still is not supported.
    it would break instanced drawing, do not work on billboards and simply is not supported by unity – regardless of the uv channel: enlighten or the progressive light mapper simply do not see trees placed using the terrain engine.
     
  46. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i just have checked a buld of the included foliage shader overview demo – which looked the same in editor and build although i did not even add any manually included shader at all (tested on win 10, dx11, unity 5.6.1 using deferred lighting).
    according to your screen shoots only the grass lighting seems to look different.
    is grass added using the terrain engine or manually?
    which rendering path do you use, forward or deferred?
    are you sure that the setup script is present in the scene you you made the build from?
     
  47. Game-Armada

    Game-Armada

    Joined:
    Apr 29, 2013
    Posts:
    66
    Let me do some tests and get back to you!
     
  48. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    That may be so, but I am using it as a mesh tree, on mesh ground. So it should be possible. And no worries, I actually got it to lightmap,
     
  49. Game-Armada

    Game-Armada

    Joined:
    Apr 29, 2013
    Posts:
    66
    Hi again!
    I am using deferred rendering from camera and linear color space.
    Attached a clean project file with the mesh grass. I have removed the AFS5 folder to create a small .zip so I could upload it here.
    The problem still persist, in unity editor (even in game window and play mode), everything works fine, but when building the mesh painted detail grass on the terrain, it looses the translucency effect at all. :(
    (with AFS_prefab, terrain selected, grass texture added, too..etc..)
    Win10, Auto Api (dx9 and dx11), Unity 5.6.3f1
     

    Attached Files:

  50. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    thanks for the test project.
    well, you should never upload a n asset from the asset store here :)

    actually i could reproduce your problem. you are using the vertexLit shader and in fact the "SetupAfs" script contains a little stupid bug which you may simply fix yourself:

    - open the "SetupAfs.cs"
    - find line 217: "InitPID();"
    - move it up to line 204 so "InitPID();" gets called before "afsSetupTerrainEngine();"

    that's all.