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. Frozmat-Games

    Frozmat-Games

    Joined:
    Dec 17, 2012
    Posts:
    25
    Ah, now I get it. Thank you very, very much! I bought your Asset on this week and I really like it.)
     
  2. halecc

    halecc

    Joined:
    Dec 17, 2016
    Posts:
    33
    Im trying to convert some unity trees into flattened or foliage shader but getting an invalid path exception in either, have any idea how to fix this?

    Code (CSharp):
    1. ArgumentException: Invalid path
    2. System.IO.Path.GetDirectoryName (System.String path) (at <f826c2584fc94ec19a48a6576640bdc5>:0)
    3. AfsFoliageToolEditor.mergeTextureFoliage () (at Assets/Advanced Foliage Shaders v5/Scripts/Foliage Tool/Editor/AfsFoliageToolEditor.cs:1302)
    4. AfsFoliageToolEditor.OnInspectorGUI () (at Assets/Advanced Foliage Shaders v5/Scripts/Foliage Tool/Editor/AfsFoliageToolEditor.cs:395)
    5. UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor[] editors, System.Int32 editorIndex, System.Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1295)
    6. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
     
  3. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    hmm, i have never seen this before.
    which version of unity do you use?
    anything else i should know?
     
  4. halecc

    halecc

    Joined:
    Dec 17, 2016
    Posts:
    33
    I am using Unity 2018.1.8f1. The error message appears but it doesnt seem like any materials or textures are generated and the leaf shadows start flickering.

    Edit: Actually its not shadows, i turned off cast shadows and receive shadows, it seems like it might be a UV flickering thing.
     
  5. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    i tested it using unity 2018.1.0f2 on win 10 pro and the conifer tree that ships with the package – which simply worked as expected.
    your error log points towards line 1302 which most likely means that FileUtil.GetProjectRelativePath(); returns an invalid path... for what reason ever: maybe you use some special characters, have a very deep folder structure, ...

    but in order to just make it work you may edit the script and comment line 1301 and 1302. then add:
    directory = Application.dataPath;
    after line 1302.
     
  6. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    Lex4art likes this.
  7. ftejada

    ftejada

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

    I am trying to make a build for PS4 with a scene from an example package to see if its shaders work in Ps4, but I am throwing these errors and although compiles, Although apparently it looks good later on the PS4
    ProblemAFS_PS4.jpg

    The version of Unity that I use is 2018.1.3f1

    Can you tell me how I can make it work correctly?

    regards
     
  8. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    hmm, i do not have a ps4 dev kit.
    but i guess you use deferred?
    in this case you can simply remove/comment the depth normal shader.
     
  9. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    Sorry but I do not understand properly what I have to do ...
    Do I have to remove the AfsWavingGrass.cginc shader? Because a shader called "dephNormal" can not find it.

    Could you explain it a little better?

    regards
     
  10. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    i meant the "AfsCamera-DepthNormalTexture" shader. you have to look for its filename.
     
    ftejada likes this.
  11. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    Thank you ... It no longer throws any error.

    regards
     
  12. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    great – but nevertheless it would be good to fix the errors of that shader on ps4.
    so whenever you find the time to test it again it would be nice if you culd send me the complete error log.
     
  13. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
  14. zeux-n00b

    zeux-n00b

    Joined:
    Nov 4, 2017
    Posts:
    73
    Hello!
    I have question about trees that are not any part of Unity tree build. Will this asset work with 3 meshes or it needs something in order to respond to Wind Zones, will branch bend and so on ?
     
  15. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    hi there,
    do not really understand your question, sorry.
    afs supports unity's built in tree creator trees and will improve their shading and the fading towards billbords as billboards as well.
    afs furthermore lets you add procedural wind animations on custom meshes – which have to be prepared to contain bending information.
    wind in any case is driven by unity's wind zones.

    i have no idea of what you mean with "3 meshes". afs expects each instance to be just one single mesh – in case of tree creator trees: made out out of 2 submeshes.
     
  16. zeux-n00b

    zeux-n00b

    Joined:
    Nov 4, 2017
    Posts:
    73
    i didn't see that i wrote that, number 3 is my sloppy writing
     
  17. UnityRocksAlt

    UnityRocksAlt

    Joined:
    Dec 28, 2015
    Posts:
    157
    Your product is amazing, congratulatoins on that first. I wanted to use your product with GPU INstancer, but it does not work because:

    To have different property values per instance, shaders need to be edited as described in
    DefinePrototypeVariationBuffer API method's description. Then, with the use of DefinePrototypeVariationBuffer and AddVariation API methods, you can set different property values per instance. There is a demo scene called ColorVariations which has an example shader and script included in the package.

    When there are scripts involved which manipulate material properties, there is not much we can do on our side. The changes should be done on the shader and the scripts that set the material properties to make it compatible with GPU Instancer.
     
  18. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
  19. UnityRocksAlt

    UnityRocksAlt

    Joined:
    Dec 28, 2015
    Posts:
    157
    Last edited: Aug 21, 2018
  20. Gray_Master

    Gray_Master

    Joined:
    Jun 20, 2010
    Posts:
    152
    Hellow. This stil work with 3rd party tree editors (non SpeedTree), such us Evolved TreeIt (export to fbx or obj) ? Just i search simple & low-price converter for this tree types with wind support.
     
  21. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    oh, nice that treeit got updated. it looked abandoned for some years.
    but in order to come back to your question: i never really found out how treeit stored the bending information in the mesh. and if it ever exports these to obj or fbx. that would be the key questions here.
    doing a quick test with the latest version i could not find any bending information exporting the included fir tree as .fbx an examining it in maya...

    you may however contact the author of treeit about this. then we will find a way to get it working using afs shaders.

    the other solution would be to manually add bending information painting vertex colors in your 3d app and/or using the foliage tool, which ships with afs.

    but while the foliage tool does a rather good job on simple structures like ferns or small bushes it might not give you AAA results on complex trees. for this purpose i created the custom tree importer which on the other hand needs you to spend some time in your 3d of choice splitting up and reassemble your tree model from treeit.

    results using cti may look like this:

     
  22. Gray_Master

    Gray_Master

    Joined:
    Jun 20, 2010
    Posts:
    152
    as i known (i doing my experiments) leaves from TreeIT very good work wich unity tree creator shader, but without trunk/branches (this part of tree is not correctly - artefacts exist).

    ps. custom tree importer need hi-price for me (i from central asia) :(
    pps. optimal price for me between 20 - 30 $.
     
  23. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    these are the picky parts...
     
  24. Gray_Master

    Gray_Master

    Joined:
    Jun 20, 2010
    Posts:
    152
    May Be.

    Yes, and exported fbx file have next structure :
    Code (CSharp):
    1. +root
    2.     +trunk
    3.         +branch
    4.              leaves
    (in + simbol i show parent nodes)
     
  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    hmm, i get only 2 meshes: one for all geo using the bark material and one for the leaf material.
     
  26. Gray_Master

    Gray_Master

    Joined:
    Jun 20, 2010
    Posts:
    152
    in settings need unset flags combine trunks/branches on export & combine leaves layers on export )
    ps. structure after export may be setting as need in unity editor
     
  27. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    ah, thanks.
    and actually the fbx contains vertex colors - but i am not sure about their meaning.
    red looks like edge flutter.
    green like phase.
    main wind seems to be derived from v.vertex.y.
    so you would have to remap the bending parameters accordingly.

    another thing: you should uncheck "backface" for the leaves.
     
  28. Gray_Master

    Gray_Master

    Joined:
    Jun 20, 2010
    Posts:
    152
    small problem from all )
     
  29. joe_ftg

    joe_ftg

    Joined:
    Nov 9, 2015
    Posts:
    50
    I think there's a bug in touchBendingCollision. In OnTriggerExit, temp is changed but not written back to the touches array, so "left" never gets set? Looks like its missing a "touches = temp;" as in the Update
     
  30. Unlimited_Energy

    Unlimited_Energy

    Joined:
    Jul 10, 2014
    Posts:
    469
    AFS issue.JPG Hi,

    When I apply the AFS set up script to my windzone object, I noticed that my plant has the wind blowing effect totally separated from teh plant. as you can see the leafs and bending are separate and moving around on the right, the cluster highlighted in orange, where as the actual plant is on teh left inside the collider. This object is made up of multiple branches if that matters at all.
     
  31. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    have you baked proper bending information into your mesh?
    you have to merge all meshes of the plant into one single one.
     
  32. Ayfel

    Ayfel

    Joined:
    Feb 28, 2015
    Posts:
    13
    Ok so I have a big problem, I updated our project from Unity 5.6.4p3 to 2017.4.10f1 and now the objects with Foliage Shader v4 do not take any lighting from lighting probes. I checked this by changing shaders and turning off blending probes and it always works when doing that with a different shader. I also took my old project and deactivated the probe blending and it in fact looks like in the new project with probes activated( so they are not working). Lighting probes work for anything else with different shaders.

    Help?

    UPDATE: I erased the library folder and re imported, everything is fine again, probably there was some conflict. I however do not understand your statement about me having to update to v5, everything is working fine now, so why should I update? (It's a VR project in forward rendering if that helps)
     
    Last edited: Sep 14, 2018
  33. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    unfortunately v4 is not meant to be used with unity 5.3 and above. you will have to upgrade to v5, sorry.
     
  34. lo-94

    lo-94

    Joined:
    Nov 1, 2013
    Posts:
    282
    Hey so I'm looking to snag AFS and ATG this week and wanted to be sure I understand the difference between the two. ATG is simply a grass shader for terrain grass only while AFS is a package which includes a grass shader for non-terrain grass, correct?
     
  35. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    atg is a grass rendering system – the shader is an important part, the more important part however is the script.

    afs offers a grass shade for the terrain as well as a vertex lit shader for the terrain which supports nomral mapped bending instances. but it fully relies on unity's built in grass rendering.
    next to that afs comes with the foliage shader and the improved tree creator shaders.
     
  36. lo-94

    lo-94

    Joined:
    Nov 1, 2013
    Posts:
    282
    Ah I see, so in parallel with Vegetation Studio which would you recommend? Is there a benefit to having both with vegetation studio?
     
  37. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    in case you are looking for improved grass rendering on unity terrains i would go with atg.
     
  38. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    if it is working fine you are fine.
     
  39. lo-94

    lo-94

    Joined:
    Nov 1, 2013
    Posts:
    282
    Would advanced foliage shader be useful for VS instanced plant meshes or trees? I'm looking to get the highest visual quality for grass on terrain, plant meshes and trees (all of which I have VS handling)
     
  40. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    yes. you will get afs lighting and bending.
    depends on how you define highest visual quality: vs will drop lod blending or fading into billboards. lighting and bending however will just be as provided by afs.
     
  41. X1buk

    X1buk

    Joined:
    Jun 28, 2018
    Posts:
    1
    Hi,
    I'm porting the game from PC to PS4. On the standalone build everything works correclty. Unfortunately, during project's assetbundles building on PS4 platform I've got errors that are attached to the post. I cannot comment the AfsWavingGrass.cginc cause I need it. Can you give me any clue how to solve this problem? Additionally, I've got same errors in player build as ftejada but as I see above I can just comment this shader. My Unity version is 2018.1.9f1.
    Thanks for any help, advice, etc.
     

    Attached Files:

  42. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    hmm, all errors point towards "Instance" i guess which seems to be a reserved kryword.
    so you may try to change the code in the AfsWavingGrass.cginc

    line 23++
    fixed4 WaveGrass (inout float4 vertex, inout float3 normal, float waveAmount, fixed4 color, float2 Instance)
    {
    // Start bending
    #if defined (AFSMANUALGRASS)
    float inst = Instance.x;
    #else
    float inst = dot(color.rgb, 1);
    inst = inst*inst;
    #endif

    change it to:
    fixed4 WaveGrass (inout float4 vertex, inout float3 normal, float waveAmount, fixed4 color, float2 myInstance)
    {
    // Start bending
    #if defined (AFSMANUALGRASS)
    float inst = myInstance.x;
    #else
    float inst = dot(color.rgb, 1);
    inst = inst*inst;
    #endif

    this change might also fix he depthnormal shader.
     
  43. zelmund

    zelmund

    Joined:
    Mar 2, 2012
    Posts:
    437
    hi there

    have a problem with billboards, seem they cant get proper info about lighting and picture look like this.

    also have warning

    The tree Grass_AfsGM04_mod test 2 must use the Nature/Soft Occlusion shader. Otherwise billboarding/lighting will not work correctly.
    UnityEditor.DockArea:OnGUI()

    i saw same problem here, but i dont have any billboard shaders in project.
    also i dont see "Nature/Soft Occlusion shader" in project too.


    and second: how to turn off shadows on grass? (using grass shader)
    im placing patches of grass inside terrain and threre is no way to turn off shadows on this grass, even if in prefab i turned off shadows.
     

    Attached Files:

    Last edited: Sep 27, 2018
  44. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    you are adding a grass model as tree?
     
  45. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    the picture does not show how lighting should look like...
    you can not turn off shadows on grass. turning it off on the prefab would make it stop casting shadows. not receiving. but unity grass does not cast any shadows.
    that is an old built in shader.
     
  46. zelmund

    zelmund

    Joined:
    Mar 2, 2012
    Posts:
    437
    yes, im adding grass as tree, because its look simply much better than if i add as grass. (pic)
    plus if i place grass ass "terrain grass (mesh)", like in your demo, my grass start have very strange unexpected animation.

    ok, but why its spaming than? something referencing on it?

    EDIT:
    tweaket abit specular color in afs setup. look better on mesh grass (vertex lit). trying tweak grass now.
     

    Attached Files:

    Last edited: Sep 28, 2018
  47. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    if you add a tree, unity tries to generate billboards for them. so unity wants you to use a shader that supports that (tree creator or Nature/Soft Occlusion shader).
     
  48. zelmund

    zelmund

    Joined:
    Mar 2, 2012
    Posts:
    437
    ok, i think i know what i didnt liked in grass.
    somehow in 1 moment all lighting braking for all grass (detail mesh, vertex lit) placed on terrain.
    left - prefab, right this prefab placed like a detail mesh (vertex lit) on terrain. i think special map (Afs map) for grass somehow going wrong in UV on all grass. watch below on fern on right one. also, wind on prefab is much better than same prefab placed by terrain tools.

    EDIT:
    ok, i think i got it where dog hiding.
    seem all mesh placed MUST have same grass atlas (material and texture), is that correct? if i have different materials on details meshes that all start to see like broken lighting.
    honestly i didnt read all your documentation, its very detailed, hard to read it in 1 time, but if this situation described there, sorry for bothering.
    p.s. and sorry for lame language..
     

    Attached Files:

    Last edited: Oct 1, 2018
  49. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    that is correct. if you use different materials unity will create its own texture atlas and the custom normal atlas will no longer fit.
     
  50. zelmund

    zelmund

    Joined:
    Mar 2, 2012
    Posts:
    437
    ok, is there chanse to have more than 1 atlas for terrain?