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
    look for: "Prepare your project"
     
    magique likes this.
  2. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    OK, I found that. Thanks for the tip. I'll give that a try tonight and see how it goes.
     
  3. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    a package dedicated to unity 5.6 is now available on the asset store :)
     
  4. Alian

    Alian

    Joined:
    Jan 8, 2013
    Posts:
    1
    Hi there,

    Running Unity 2016.1.0b6, on import and after following your quickstart guide, I'm still getting the following shader error: "Shader error in 'AFS/Foliage Shader': Unexpected token usertype. Expected one of: ',' ';' at line 152"

    Haven't done anything to the assets except for setup the project as explained in the documentation - any clue what might be up"?
     
  5. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    i guess you mean Unity 2017.1.0b6 – which i haven't tested yet.
    it should run fine using unity 5.6. though.
     
  6. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    385
    Hi, this looks awesome!

    Web demo links are dead, any chance for testing? Maybe standalone demo?

    Thanks!
     
  7. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Awesome. I'll give this another try and see if I can get it all working again.
     
  8. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I actually tried this again using Unity 5.5.4p1 on the Wii U and it works.

    [EDIT]
    However, there are some issues with editor mode versus stand-alone build. Your CombineChildrenAFS.cs script has references to UnityEditor, which causes the build to fail. And the entire AfsFoliageTool.cs script is wrapped in #if UNITY_EDITOR, which causes all kinds of serialization errors such as:

    A script behaviour (probably AfsFoliageTool?) has a different serialization layout when loading. (Read 32 bytes but expected 1328 bytes)
    Did you #ifdef UNITY_EDITOR a section of your serialized properties in any of your scripts?

    And, of course, all the foliage items that use this script then get missing behavior errors.
     
    Last edited: Jul 11, 2017
  9. Sp-ce

    Sp-ce

    Joined:
    Feb 2, 2015
    Posts:
    65
    Hello,

    I'm looking for some support regarding this package. I get most of it - but I really don't understand how I can just get a tree working with some wind animation. I get the leaves part, but what about the trunk? Do all textures - leaves and bark need to be on one shader? I also don't get why there are tree creator shaders included? Is not the whole tree creator system legacy at this point? I do understand that some folks might still use it, but then I wonder if I import a mesh tree I've made in Blender, can/should I use tree creator shaders?

    Thanks!
     
  10. ryschawy

    ryschawy

    Joined:
    Jul 28, 2012
    Posts:
    65
    Hi,
    I tried a build and do get this AFS related error. Doesn't sound like this is something I can fix on the user side?
    Shader error in 'Hidden/AfsCamera-DepthNormalTexture': Non system-generated input signature parameter (TEXCOORD) cannot appear after a system generated value. at line 310 (on d3d11)

    Compiling Fragment program with LOD_FADE_CROSSFADE INSTANCING_ON
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING SHADER_API_DESKTOP
     
  11. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    sorry - not at the moment.
     
  12. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    thanks, but it is already fixed in the latest version pending for review.
     
  13. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    no, the tree creator shaders need very special bending information baked into the mesh.
    if you really want to import manually modeled trees i suggest to use the custom tree importer:
    https://www.assetstore.unity3d.com/en/#!/content/21079
    it handles way more complex structures than the tools included in the afs package (foliage tool).

    no :)
     
    Dwight_Everhart likes this.
  14. larsbertram1

    larsbertram1

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

    thanks for your report.
    i was able to reproduce the error – unfortunately. but fortunately it is rather simple to fix so you do not have to wait for the update.

    edit the "AfsCamera-DepthNormalTexture" shader and find (line 289 i think):
    UNITY_VERTEX_INPUT_INSTANCE_ID
    UNITY_DITHER_CROSSFADE_COORDS_IDX(2)

    and simply change the order of these 2 lines to:
    UNITY_DITHER_CROSSFADE_COORDS_IDX(2)
    UNITY_VERTEX_INPUT_INSTANCE_ID

    that's all.

    please let me know if this fixes your problem.
     
  15. Sp-ce

    Sp-ce

    Joined:
    Feb 2, 2015
    Posts:
    65
    Ahh, okay, cool! The asset you pointed out looks really good, thanks!

    But, on the tree creator thing - where does one even find that module in Unity anymore? Was it not replaced with speed tree? What am I missing here?

    Thanks again!
     
  16. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    under "Game object" --> "3D Object" you will find "Tree".
    that will create a new tree using the tree creator.

    there is no need for unity to drop the tree creator. and its trees are very fast (much faster than speedtrees) and allow full angle billboards – even from above.
     
    Sp-ce likes this.
  17. Sp-ce

    Sp-ce

    Joined:
    Feb 2, 2015
    Posts:
    65
    This is really embarrassing. I've been using Unity every day for well over a year on lots of different projects - how the hell did I never see the tree creator in editor before? I read about in the documentation, but as it mentions SpeedTree I had just assumed that the Tree Creator isn't used any more... I consider myself a competent 3D artist and Unity Creator, but there is so much stuff in Unity across so many areas I guess this happens. Damn.

    Anyway, again, thanks for the very helpful product and information!

    Cheers
     
  18. ryschawy

    ryschawy

    Joined:
    Jul 28, 2012
    Posts:
    65
    It was indeed as simple as changing the order :)
    Fixed. Thanks.
     
  19. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    fine!
     
  20. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    @larsbertram1 Did either of the 2 recent updates address the issues I presented earlier with stand-alone builds and Unity editor code?
     
  21. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    one addresses the missing #if UNITY_EDITOR the other the depthnormal-shader.
     
    magique likes this.
  22. BLUESurfer-MONSTER

    BLUESurfer-MONSTER

    Joined:
    Oct 12, 2013
    Posts:
    11
    Hi guys, I've just purchased this asset and I was planning to use it on Unity 2017 but I've got almost all demo scenes broken. The plants are colour red, only painting geometry, no cuotout or transparencies.... ¿any ideas?
     
  23. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I tried 5.02c and I still get the following error:

    Assets/Advanced Foliage Shaders v5/Scripts/Combine Cildren/CombineChildrenAFS.cs(75,14): error CS0103: The name `EditorUtility' does not exist in the current context

    I fixed it myself again, but if you can add to next update then that would be great.

    [EDIT]
    And when I run in stand-alone on Wii U, still getting the other error:

    A script behaviour (probably AfsFoliageTool?) has a different serialization layout when loading. (Read 32 bytes but expected 7936 bytes)
    Did you #ifdef UNITY_EDITOR a section of your serialized properties in any of your scripts?
     
  24. Fabbs

    Fabbs

    Joined:
    Dec 2, 2013
    Posts:
    43
    I have the same problem, probably broken i 2017 or something.
     
  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    unity 2017 broke the way cross fading is handled... without any notes in the upgrade guide.
    i will file a bug report:
    https://fogbugz.unity3d.com/default.asp?930800_mtlav570rld8ovnf
    meanwhile you could simply edit the "AfsFoliageShader (instanced)" shader and comment:
    UNITY_APPLY_DITHER_CROSSFADE(IN)
    in the surface function.

    a real fix however is a bit more complex so i would like to ask you to wait for the next update.
     
    Last edited: Jul 13, 2017
  26. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    only the setupafs script has – but i get no errors at all.
     
  27. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    You may not get it in PC build, but in Wii U the error spams the console. The entire script is in a #if UNITY_EDITOR block, but it seems the script is needed for run-time so that's a problem. Or is that script supposed to be removed for run-time?
     
  28. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    i can not test wii u builts.and all #if UNITY_EDITOR scripts of course are editor only
     
  29. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    So why does the foliage have that script attached to it then? If it's supposed to be editor only. I'm confused.
     
  30. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    because i wanted to keep the number of prefabs low.
    in a production environment you would set up the bending once.
    then use the created prefabs in your scenes.
     
  31. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    OK, thanks. I will remove the script then and everything should be fine.
     
  32. BLUESurfer-MONSTER

    BLUESurfer-MONSTER

    Joined:
    Oct 12, 2013
    Posts:
    11

    Oh, thanks we will test it right now!. New versions of Unity... always a little pain in the ass. :)
    Thanks for your fast reply!
     
  33. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    you are welcome.
    and after reading through the changelog i found a new surface shader directive.
    so adding crossfading in 2017 is as simple as changing the initial #pragma:

    #pragma surface surf AFSSpecular vertex:AfsFoligeBendingGSFull addshadow fullforwardshadows dithercrossfade
     
    Dwight_Everhart likes this.
  34. PutridPleasure

    PutridPleasure

    Joined:
    Mar 3, 2015
    Posts:
    11
    Hey Lars, I'm looking to Upgrade my Projects from v5.4.5 to v2017.
    Currently the demos of the latest release of afs v.5 seem not to be working correctly if I import afs in a new empty project in v2017 (no bending, weird colors on foliage).

    So my question: Does AFS already fully support unity v2017 and I just have to follow some instructions in the documentation to get the demos to work correctly, or should I just wait until you update it?
    (If I remember correctly there was no action of my own necessary to get the demos to work as intended for unity v.4 - v.5.4)

    Thanks in advance and sorry If you already answered this somewhere
     
  35. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    2017 is not supported out of the box right now – as the "AfsFoliageShader (instanced)" errors due to some changes Unity made concerning crossfading.

    you can easily fix this by editing the shader.
    find:
    UNITY_APPLY_DITHER_CROSSFADE(IN)
    and comment it so it looks like this:
    // UNITY_APPLY_DITHER_CROSSFADE(IN)

    then find:
    #pragma surface surf AFSSpecular vertex:AfsFoligeBendingGSFull addshadow fullforwardshadows
    and change it to:
    #pragma surface surf AFSSpecular vertex:AfsFoligeBendingGSFull addshadow fullforwardshadows dithercrossfade

    that is all that is needed.
     
  36. BLUESurfer-MONSTER

    BLUESurfer-MONSTER

    Joined:
    Oct 12, 2013
    Posts:
    11
    I think that something is still broken... or at least in my version. Larsbertram1 I applied your suggestions:

    "you can easily fix this by editing the shader.
    find:
    UNITY_APPLY_DITHER_CROSSFADE(IN)
    and comment it so it looks like this:
    // UNITY_APPLY_DITHER_CROSSFADE(IN)

    then find:
    #pragma surface surf AFSSpecular vertex:AfsFoligeBendingGSFull addshadow fullforwardshadows
    and change it to:
    #pragma surface surf AFSSpecular vertex:AfsFoligeBendingGSFull addshadow fullforwardshadows dithercrossfade"

    And actually works in Forward mode but in Deferred the plants and foliage seems to be very "green" without shadows at all... like if they had textures in the "emissive" slot. ¿Maybe we have to change some more lines? :)
     
  37. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    you have to assign the cistom deferred lighting and reflection shaders as described in the docs :)
     
  38. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    Hi, I just bought AFS 5, and tinkering around to see how can I use it.
    Now my game object can be put into my scene correctly, but when I use the terrain's detail sector to plant vertex lit ferns, it results like this:
    upload_2017-7-24_20-27-24.png
    strange shadow on the back of leaves. I found the example scene doesn't have this issue, but I can't find the key in that scene. Anyone here can enlighten me that how should I set this right?
     
  39. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Do you have light baked for your scene?
     
  40. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    No, I use MapMagic to generate terrains in runtime, don't know how to bake the scene in runtime...
     
  41. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    i remeber having a similar problem but do not exactly remember how i solved it.. :)
    it has to do with ambient lighting which gets not sent to the vertex lit shader properly.
    so make sure that in the "lighting window":
    - sun source is assigned
    - auto generate is checked
    you may also try to set the terrain to not static.
     
  42. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    Hey, thanks for the advice!
    But I'm wondering if the runtime generated terrain can also be baked?
    And Tenkoku Dynamic sky seems to have it's own GI method, usually I don't need to use unity's light baking.
    How could I make this work with both MapMagic and Tenkoku then...?
    BTW I tried to add Tenkoku Skybox into the demo scene, everything looks fantastic, but not in my own test scene.

    Edit 1:
    upload_2017-7-25_12-5-56.png
    I set up a new test scene and used the same prefab for both terrain trees and terrain vertex lit details and found the trees looks more beautiful than vertex lit details and it got shadow.
    Downside is I can't put too much trees on terrain, this is more costly than detail system.

    Edit 2:
    How do I bake the terrain's combined detail textures? Do I have to do it in a third party software or inside AFS's tools?
     
    Last edited: Jul 25, 2017
  43. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    ambient lighting seems to be fixed in your new scene as far as the vertex lit shader is concerned.
    do you know the difference between your first and the new test scene?

    i create the texture atlas in photoshop and adjust the uvs in modo or maya.
    afs does not provide any tool to do this in unity.
     
    Harekelas likes this.
  44. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    The next scene is made with unity 5.5 and the previous is 5.4, both are brand new scenes and the first one was not using the atlas normal/trans/smooth texture in the AFS setup.The translucency strength was lower than the new scene and also the Legacy Bending was enabled in the previous scene.
    Though translucency can solve some of the problem but when I look at the models painted by terrain detail system, they still have some very black spots.
    In the second scene, all ferns with shadows are placed through terrain trees and they looked much better than terrain detail ferns.

    Edit: got another question here: If I put every tree and bush as a gameobject rather than terrain trees, will it cost much more performance with AFS? I tested the other tree shaders (speed tree)
    about gameobject vs terrain tree, the set pass call is drastically increased if I put trees as game object in the scene. Don't know if AFS has some optimizations for gameobject trees?
     
    Last edited: Jul 25, 2017
  45. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    ah, yes. now i remember: "Legacy Bending" stores ambient occlusion in vertex color alpha – whereas the models use vertex color alpha in order to store primary bending... interpreting the bending value as ambient occlusion of course will kill most ambient light.
     
    Dwight_Everhart likes this.
  46. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    I've got another question. It's about the grass model postprocessor, I can find the script in the AFS folders, but unity does not allow me drag it onto any gameobject and I cannot find any editor window that can open it.
    How do I use this tool? I've changed the imported fbx's name with "_AfsGM" at the end, but when I drag this fbx grass model into the project there is no popup window or anything to let me use the processor.
    Maybe I'm doing something wrong, but what is the workflow to use this tool?
     
  47. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    it is all done on the fly. you simply have to name the fbx properly then the importer will do its work in the background.
     
  48. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    So, basically I just give the fbx a "_AfsGM" at the end and drag it into asset folder then assign the AFS grass shader to it then all down?
     
  49. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    yes. you may add 2 digits at the end to define the strength of the bending.
     
  50. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    @larsbertram1 I was wondering if you can recommend a solution for wind behaving incorrectly when instancing is turned on for materials using AfsFoliageShader (instanced) shader. With instancing off, wind seems to displace small areas, but with instancing on, noise field seems to be blown up in scale, offsetting vertices of entire trees in exact same way. Check this animation:

    To be specific, displacement here is produced by your AfsAnimateVertex function using o.animParams arguments where only z and w components are non-zero (primary and secondary bending is enabled, while edge flutter and phase difference is disabled). Hopefully that narrows things to look at down a fair bit.

    Root points of trees are not displaced in the gif because influence of AfsAnimateVertex function is graded by height. In case you're interested in how things look without my custom shader, here are same trees with unmodified AfsFoliageShader shipping with AFS. Same behaviour here:


    Maybe the AfsAnimateVertex function from Includes/AfsFoliageBendingInstanced.cginc receives wrong vertex positions when instancing is enabled, or something along those lines? Any ideas? :)
     
    Last edited: Jul 31, 2017