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,900
    simply adding the suffix should automatically trigger the script...
     
  2. cowtrix

    cowtrix

    Joined:
    Oct 23, 2012
    Posts:
    322
    Hey lars, I've got a problem with the billboards not matching the trees very well with a fresh install of the latest AFS. Any ideas on what could be causing this?

     
  3. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hmm, i can not really see anything on your screen shoot, sorry
     
  4. cowtrix

    cowtrix

    Joined:
    Oct 23, 2012
    Posts:
    322
    Sorry lars, probably should have clarified a lot more.

    These are all exactly the same trees - and yet the billboards are significantly lighter than the meshes. If we compare the shot with the in-built shaders, there is no colour change, like so:

    This is the desired effect for me. Whereas with AFS, the billboards are significantly lighter:


    Edit: Ah, more information I probably should have included. This is is gamma space - the billboards look accurate in Linear, however unfortunately Linear is not an option for us right now as it breaks far too many things.
     
    Last edited: Jul 6, 2015
  5. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    @cowtrix: well, gamma is not supported as well as linear i have to admit.
    what ambient mode do you use? skybox, gradient, solid color?
     
  6. cowtrix

    cowtrix

    Joined:
    Oct 23, 2012
    Posts:
    322
    We're currently driving our ambience and reflection maps from the Time Of Day plugin, which seems to be setting the Ambient Source to the skybox settings (although it might be doing some magic in the middle there).

    It may interest you to know that the effect remains even if I revert the AFS billboard shader, which would seem to indicate to me that it's the actual billboard texture generation where something is going wrong.
     
  7. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    ambient light from skybox is not supported by the built in billboard rendertex shaders as far as i know.
    so i am bit confused by your statement that unity’s shaders give you better matching results.

    afs billboard rendertex shaders support skybox, gradient and color. but it has to compute its own SH lighting which might not 100% fit the skyboxes and ambient lighting generated by your plugin.
    however the demo scene which comes with the package works nicely – in linear and gamma color space.
    would you check this too, please?
    might just be that i have not committed the latest version.

    lars
     
  8. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    I'm finally interested to buy to asset when I see all the goodies.
    I know it can allow to put grass on any geometry, however does this works with detail textures (not detail mesh) ?

    I mean I will convert my terrains (unity builtin) to standard meshes, is it ok to place grass textures on top on these meshes as if it was Unity's builtin terrain (and keep wind effect) ?
     
  9. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    nope, you will have to have a simple quad for you grass at least. however having tighter modeled geometry will help you to reduce fill rate and is highly recommended.
    that should not be a problem unless you have a huge amount of grass meshes which have to be kept in memory all the time. in this case some streaming and pooling solution might be needed.
     
  10. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    In fact I already have the grass meshes (they were speedtree grasses) but I ran into issue with it, I think it's related to speedtree. I noticed that if I replace them with detail textures there's way less drawcalls. (please look at this post: http://forum.unity3d.com/threads/ho...ld-i-target-for-pc.329525/page-2#post-2193267)

    Is 1 hundred of grass meshes in the frustum a huge amount ?
     
  11. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    all speed tree objects are rendered as "trees" – so each object causes about 3 draw calls.

    well, that is how the terrain engine handels grass: it combines hundreds of grass meshes into one single patch.

    and that is more or less how the advanced foliage shader package handles grass: it lets you combine single meshes into clusters or patches – either at runtime or statically.

    no, especially not if you cluster these into e.g. 5 or 6 patches (do not put all grass meshes into a single cluster as doing so would make culling less effective. instead create several patches each of 16x16x16m size e.g.).
    you will get into trouble if you have a very huge level containing several hundreds of grass patches: each cluster needs some memory to store the unique mesh. for this reason streaming gets important.

    lars
     
    jimmikaelkael likes this.
  12. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Thank you for your advices, finally bought your asset :)
    It was quite easy to convert my grass from speedtree to use AFS grass shader and keep the exact same appearance and I'm already happy just with that.

    Do you suggest to use LODs for combined grass patches or is it generally a bad idea for grasses ?

    For my speedtree trees I'm currently unable to convert them with the foliage tool. I've read the docs so I'm proceeding as follow:
    - I make a new prefab with the LOD0 component of my speedtree,
    - I add the AFS foliage tool component to it,
    - I hit "Save Mesh" button as it is suggested but then the tree disappear as soon as the new mesh is saved.

    Is it possible to convert a speedtree tree to use AFS shaders and keep the same look ?
     
  13. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    i would prefer to use layer culling – unless you have different "combined" meshes for different lods.
    sorry, there is still a bug in the tool. send me your invoice number and i will give you the latest version.
    not really. bending is handled completely different. lighting too. at least if you do not use the deferred single sided shader.
     
  14. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    I could have different combined meshes for LODs as I use my own editor script to combine things, and it can take care of combining LODs as well. I wanted to know if it was a good or bad practise for things using the AFS grass shader.

    I've sent you a PM.
     
  15. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    i have not tried it yet – but it should be ok to use lods.
     
  16. savedgamesinc

    savedgamesinc

    Joined:
    Jun 29, 2015
    Posts:
    2
    Hello,

    Totally digging the plugin, I'm using the touch bending. I'm having an issue where after a little while of it working in the scene, trees start disappearing on touch with the two errors below:

    CompareApproximately (SqrMagnitude (q), 1.0F)
    UnityEngine.Quaternion:Euler(Vector3)
    touchBendingCollisionGS:Update() (at Assets/Advanced Foliage Shader v4/Scripts/Touch Bending AFS v4/touchBendingCollisionGS.cs:161)


    Quaternion To Matrix conversion failed because input Quaternion is invalid {nan, nan, nan, nan} l=nan
    UnityEngine.Matrix4x4:SetTRS(Vector3, Quaternion, Vector3)
    touchBendingCollisionGS:Update() (at Assets/Advanced Foliage Shader v4/Scripts/Touch Bending AFS v4/touchBendingCollisionGS.cs:162)

    Is this a known issue or is there a fix? Thanks!

    Michael
     
  17. savedgamesinc

    savedgamesinc

    Joined:
    Jun 29, 2015
    Posts:
    2
    So I think I found my problem - In my project I toggle between FPS and Strategy mode, which turns off the player, then back on. That appeared to be jamming up touchBendingPlayerListener.cs by making Player_NewSpeed == NaN. I added this after Player_NewSpeed is set (around line 40) and it acted as a quick fix:

    if(float.IsNaN(Player_NewSpeed)){
    Player_NewSpeed=0;
    }

    Michael
     
  18. Avonaeon

    Avonaeon

    Joined:
    Apr 17, 2012
    Posts:
    48
    Hey Lars,

    I've hit a bit of a brick wall that I don't really understand. I have a prefab (On the left in the image below) placed manually in a scene, and the same prefab, placed as a detail mesh (Set to vertex lit) on the right. They use the same material obviously and the shader is the AFS/Foliage shader v4. The mesh is a single mesh, no submeshes or anything like that, but for some reason 2 of the leaves are disappearing when placed as a detail mesh. The top leaf is also separated from the stem, exactly like the two other leaves, but for some reason only one of the them is rendered.

    EDIT: Bonus info; If I lower the alpha cutoff under Terrain Vegetation Settings in the Setup Advanced Foliage Script, the leaves reappear, but are white and green/purple and obviously don't have transparency. Picture: http://i.imgur.com/i8ZpdmL.png



    Do you have an idea as to what I'm doing wrong?

    Thanks
     
    Last edited: Jul 15, 2015
  19. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    that could have many reasons.
    here are some of them:
    - please check the "dry and healthy" color in the detail settings (terrain engine).
    - have you assigned several detail meshes to the terrain?
    - do they all share the same texture atlas?
    - are the uvs layed out according to the texture atlas?
     
  20. Avonaeon

    Avonaeon

    Joined:
    Apr 17, 2012
    Posts:
    48
    While they were layed out according to the atlas, some leaves were layed out with an offset. So instead of being [0.25,0.5], some leaves were [1.25,0.5]. I'm using ultimate unwrap to vertex colour and laying out the UVs like this makes it way faster to color, but I guess I can't do that.

    Anyway, thanks for helping.
     
  21. Avonaeon

    Avonaeon

    Joined:
    Apr 17, 2012
    Posts:
    48
    Hey Lars, sorry to keep bothering you, but I have a new issue now.

    When using lightmapping, all vertexlit detail meshes placed with the terrain engine become complete dark in shadow. Detail meshes rendered with grass appear fine.

    http://i.imgur.com/MZgdRjd.png

    Is this a known limitation, or is it a bug?
     
  22. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    i can not confirm this:
    Bildschirmfoto 2015-07-17 um 12.40.22.png

    ferns are added as detail meshes using the vertex lit shader (using directional lightmaps).
     
  23. Lasse-Loepfe

    Lasse-Loepfe

    Joined:
    Mar 28, 2014
    Posts:
    29
    Hi,
    I must be doing something wrong converting tree creator trees using the Foliage Tool.
    1) create a tree
    2) add the foliage tool
    3) save the mesh
    4) assign the combined textures (using examples from the afs package)
    ->screenshot before
    5) press "convert trees"
    -> the tree dissapears (screenshot after)

    thanks for your help
    Lasse
     

    Attached Files:

  24. kloogens

    kloogens

    Joined:
    Jul 1, 2015
    Posts:
    116
    I have a general question about the AFS tree creator Leaves shader.

    I notice that it requires a total of six maps.

    RGB
    Normal
    Gloss
    Translucency
    Shadow offiset

    I start getting confused at Gloss.
    3. Gloss (A) - So I am assuming you could use the Alpha channel of the normal map if you want to correct?


    The last two slots Translucency and Shadow both requires alpha channels?
    So I would need two additional texture both with alpha channels? I find in confusing because why wouldn't you use different channels of a same texture.


    For example

    Why not use a single texture for Translucency and for Shadow and use the R channel for the Translucency and the B channel for Shadow?

    Or am I not understanding something here?
     
  25. ArsKvsh

    ArsKvsh

    Joined:
    Dec 13, 2014
    Posts:
    17
    Hello Lars,
    Look at this, please: http://answers.unity3d.com/questions/1005704/fix-black-squares-over-tree-foliage-when-using-blu.html
    The problem happens (since Unity 5.1 or so) both with standard tree shaders and with AFS. But notice that for AFS it happens only with leaves. I found that the issue is related to shadows (I tried to remove some parts of shader code), but disabling casting or receiving shadows doesn't change anything. Can you do something with it?
    Thank you in advance and sorry if there are some mistakes in English.
     
    Last edited: Jul 23, 2015
  26. Morfeuskiev

    Morfeuskiev

    Joined:
    Oct 10, 2013
    Posts:
    122
    hi @larsbertram1
    I came back to use your shader and unity tree from Speed Tree.
    Have two question (i don't found solution for resolving in latest posts):
    1) Queue Rendering with standard water4. https://gyazo.com/cf4d7a6031dbb01613074574b8ce51e7 . Water rendering before (earlier) Billboards.
    2) strange behavior in night scene - https://gyazo.com/c6b79b8b8b887490c3b11bdb427eb682

    All another is OK. Hm... one "another" work strange. But is not bug. When i use grass on terrain with AFS shader in project - terrain has strange black lines. But if i add to scene script setup foliage - all work OK.
     
  27. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    the afs tree creator shader use exact the same texture layout as the built in shaders.
     
  28. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    unfortunately i do not own natural bloom – but if it breaks a built in shader you may probably want to contact the author.
     
  29. larsbertram1

    larsbertram1

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

    just a quick answer:
    1) both billboards and water use the transparent queue. so if you want to have billboards in front of the water (and that would mean: always in front of water) you will either have to lower the que of the water shader or raise the queue of the billboard shader.
    2) thta is a common problem too, sorry. the internal render billboard function renders the billboards in front of a standard gray – which as in your case – spills into the texture...
    so you might edit the "AfsBillboardTree v4" shader and add something like this:
    col.a *= col.a;
    before:
    return col;
     
  30. ArsKvsh

    ArsKvsh

    Joined:
    Dec 13, 2014
    Posts:
    17
    The problem is not only with SE natural bloom. It happens with all blur effects in Unity.
     
  31. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    built in blur and bloom:

    Bildschirmfoto 2015-07-23 um 21.40.35.png
     
  32. ArsKvsh

    ArsKvsh

    Joined:
    Dec 13, 2014
    Posts:
    17
    Hmmm, please, can you enable HDR and try DoF or Vignetting or Chromatic Aberration (enable Blurred Corners)? And try to rebuild trees in Tree Creator. By the way, I also sent a bug report to Unity about a week or two ago, but haven't got any answer. If you want, I can provide you my project to reproduce the issue. The problem reminds me white dots in deferred path but you solved it in AFS.
     
    Last edited: Jul 23, 2015
  33. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    same result. but i am on osx. so may be it is a dx9/dx11 problem.
    Bildschirmfoto 2015-07-23 um 22.07.39.png
     
  34. ArsKvsh

    ArsKvsh

    Joined:
    Dec 13, 2014
    Posts:
    17
    Strange, strange, strange. Okay, thank you, I'll try to find the solution.
     
  35. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Tested this out in DX9 and 11 on my pc and did not see this issue. Adaptive tonemapping is still broken in Dx11. Sorry man. That is the only problem I saw.

    Have you tried the trees in a clean project? Without any custom/Asset Store image effects imported?
     
  36. ArsKvsh

    ArsKvsh

    Joined:
    Dec 13, 2014
    Posts:
    17
    The problem is with shininess. Any value lower than 0,15 causes that black squares. It's strange because in versions of Unity older than 5.1 everything worked perfectly.
     
  37. Avonaeon

    Avonaeon

    Joined:
    Apr 17, 2012
    Posts:
    48
    I have a strange issue when I rotate my directional light below the horizon (Using the default procedural skybox), where the leaves on the trees don't seem to be properly effected by the lighting.

    http://i.imgur.com/7Di5L5X.png
     
  38. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    If the directional is still at full strength below the horizon then you will have a few issues. Billboards do not receive shadows and the leaf material has to have full shadow strength. So while you can raise the shadow strength to full the billboards will still be lit up. Best(and only) solution is to have the light strength at 0 when going below the horizon.
     
  39. Unplug

    Unplug

    Joined:
    Aug 23, 2014
    Posts:
    256
    hello i have just added AFS 4 to my scene hoping to improve billboard tree and unfortunatly i don't see any smooth transition. It "pop" between regulard tree and billboard. Do i have to change anything in those tree (they were painted before addid the AFS package). I only have created an empty object and attach the setup script to it. Do i have something else to do ? i see that the tree are "dancing" in the scene view while i'm in the play mode so I guess it mean it is working, but billboard occur badly and color shift is quite noticeable. any help are welcome
     
  40. Morfeuskiev

    Morfeuskiev

    Joined:
    Oct 10, 2013
    Posts:
    122
    @Unplug

    Read manual about Unity Tree and Billboard it root AFS folder. You must to replace standard Nature/tree shader on AFS (But not in tree component).
     
  41. Avonaeon

    Avonaeon

    Joined:
    Apr 17, 2012
    Posts:
    48
    Thank you, I'll probably do this then :)
     
  42. Unplug

    Unplug

    Joined:
    Aug 23, 2014
    Posts:
    256
    I read it, it's unclear, that's why I'm here I'm asking clear indications. they tell you stuff without telling you what and where you actually do what they want you to guess.
     
  43. Morfeuskiev

    Morfeuskiev

    Joined:
    Oct 10, 2013
    Posts:
    122
    @Unplug

    Okay.

    1) Put Unity tree object on scene.
    2) Create two new materials (*_Bark and *_Leaf) and change shader to AFS tree creator bark and the same for leaf. (For bark i chosen Deffered).
    3) Near Unity tree object in project (as example Tree1) we have Tree1_textures folder with 4 textures.
    4) Put this texture to AFS materials (in step 2).
    5) Put new AFS materials to Unity Tree on the scene in mesh render component (Not in Tree component) instead Optimized leaf and bark materials.
    6) Save your new tree (As example Tree1_AFS) to project as new prefabs.
    7) Use this prefabs in terrain.

    There is nothing difficult
     
  44. Unplug

    Unplug

    Joined:
    Aug 23, 2014
    Posts:
    256
    thanks, i'll try that.
    but if I already painting tree without that, i'm out of luck ?
     
  45. Unplug

    Unplug

    Joined:
    Aug 23, 2014
    Posts:
    256
    i must be stupid, after doing this, the tree turn invisible in both scene and game...

    EDIT: after setting alpha cutoff to 0 for bark, the bark appear. No matter what i do for leaf, they stay invisible.
    EDIT2: after clicking the leaf in the "tree" section of the tree, they reapeared, when i push play. Unity hang forever. Good lord, this is so much fun.
     
    Last edited: Jul 27, 2015
  46. Morfeuskiev

    Morfeuskiev

    Joined:
    Oct 10, 2013
    Posts:
    122
    @Unplug

    See on the screenshots.
    1) Put Tree in scene http://gyazo.com/ad5d213d1c8b5da63a88be9b83914f92
    2) Create new materials http://gyazo.com/d00c0666f4af12a8adfb3dc5c9d70865 (Bark and leaf shader)
    3) Assign Texture - (Leaf, bark the same without shadow)
    4) Put new materials in tree on the scene. http://gyazo.com/991c1122506a210b4e0aa71bc39a1657
    5) Save new Tree as new prefabs with another name http://gyazo.com/64de5364b160f112b228257d8d532bb1
    6) use this prefabs (copy if need to another folder) in terrain and you have smooth transition )
     
  47. wheels

    wheels

    Joined:
    Jan 20, 2013
    Posts:
    29
    Hey lars, been a while since I was here.

    So, I’m sure you are sick of answering speedtree stuff, but there doesn’t seem to be a actual solution posted here so here it goes. We switched to using speedtree a while back but here are the problems there.

    1. Speedtree does not use pbr

    2. Speedtree does not do spec

    3. Speedtree does not do translucency

    4. Speedtree does not do touch bending

    5. Speedtree does not use raindrops

    6. Speedtree is extremely un-optimized drawcall wise

    On the other hand speedtree does have

    1. A very simple way to set up wind

    2. Great modeling toolset

    3. LOD generation

    4. Great tools for leaf generation

    5. Intersection blending

    Basically we are at crossroad’s and need to figure out do we create our own shader or use afs somehow. Obviously, we’d like to use your package but the foliage tool doesn’t work for speedtree. So the question is, How, If at all, can we use your packages benefits with speedtree in a step by step process? Keep in mind you cannot export speedtree meshes to other programs but we are prepared to create, edit, and view any additional maps that we will need inside of unity. Is this possible or do we need to create our own custom shader? Thank you for your time.
     
  48. Unplug

    Unplug

    Joined:
    Aug 23, 2014
    Posts:
    256
    @Morfeuskiev

    yup i can confirm i'm dumb ! lol
    thanks a lot again for your patience and your extremely detailed instruction. The problem was that I was using wrong shader. I took those from AFS category instead of those in NATURE I didn't realise there was two set. I guess AFS one are those for hand place item in the scene and not for those use by unity terrain engine. Everything work flawlessly now, impressive result with billboard
     
  49. Morfeuskiev

    Morfeuskiev

    Joined:
    Oct 10, 2013
    Posts:
    122
    No need for this :). Everything comes with experience.
     
  50. Unplug

    Unplug

    Joined:
    Aug 23, 2014
    Posts:
    256
    it's good to know you don't know, it's how you start learning !!! it's such an amazing software and amazing asset.