Search Unity

Advanced foliage shader [released]

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

  1. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    319
    Don't forget there are any number of scatter plugins on the store many of which are free.
     
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    afs touch bending is not meant to be used with "grass" – at least not grass which floods your entire terrain.
    it needs game objects and colliders.
    you may look for more simple solutions based on "obstacle avoidance", render textures and some simple vertex shader animations.
     
  3. kypronite

    kypronite

    Joined:
    Apr 15, 2013
    Posts:
    21
    Hi, do you have link to demo?
    the broken link and no images on first post in this thread really gives bad impression that this asset is no longer
    actively supported.
     
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    no link to the demo, sorry.
    and images on the first page are broken because this thread was created nearly 7 years ago. the forum just does not let me edit the first post.
     
  5. Dan_P_BBox

    Dan_P_BBox

    Joined:
    Jan 2, 2018
    Posts:
    1
    Using something like Prefab Brush, or another splat painting plugin for models works great for me.
     
  6. tallentslastname

    tallentslastname

    Joined:
    May 23, 2018
    Posts:
    5
    Hi!
    I'm having some problems implementing my custom made trees with AFS.
    I've read through the documentation a couple times but I'm still having a hard time figuring out how to get a couple things working.
    My main issues are that I can't get secondary/detail blending working right and I cannot tell if the vertex painting I did to my model is being applied correctly. I have combined my tree into one mesh, UVed accordingly, baked and combined the texture maps (color, smoothness, translucency, normal) and attached the correct maps to the foliage shader.

    My plan is to use UV4 and vertex colors because the project I am working on has a high spec target.
    I'm using the foliage shader on the mesh and have attached the correct maps.

    At this point the mesh is moving, but the whole tree is waving, the way I painted the vertices the trunk and the beginning of the branches shouldn't be moving from what I understand.

    I then tried to use the AFS foliage tool and 'save the mesh' so I could edit it. but after doing that it blew up my mesh. So i'm not sure where to go from here to get it on the right track. I hope you can help.

    I'll upload some photos of what happens and of my vertex painting

    Thanks
     

    Attached Files:

  7. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    "uv4 and vertex colors" means that primary and secondary bending must be baked to uv4 – not the vertex colors.
    u would be primary bending, v secondary.

    looking at your setup of the foliage tool i noticed that ii is set to bake bending to vertex colors only.
    but the debug shader you use expects bending in uv4 and vertex colors. so this combination will never work. settings have to match.

    bendingmodes.jpg

    looking at your vertex painting i see only vertex color red?! red is the phase. and it is different for leaves and trunk and branches which might lead to discontinuities (if using the legacy vertex color mode).
    in case you are using any of the newer bending modes red should be slightly different for any branch/leaves combination.

    if you send me your model via pm or email (larsbertram69[at]gmail[dot]com) i can have a look into it.

    but as you you are working on trees i would like to point you towards another asset:
    https://assetstore.unity.com/packages/tools/modeling/custom-tree-importer-21079
    this asset has been written to import custom made trees and will generate trees that support e.g. billboarding and way more advanced bending then you will get from afs.



     
  8. tallentslastname

    tallentslastname

    Joined:
    May 23, 2018
    Posts:
    5
    thanks for the in depth reply!!! I appreciate it!
    I am a bit confused on how to bake the bending into UV4 I thought the foliage tool did that from the vertex painting. I suppose I just haven't ever used UV4 in any asset before and am not quite sure how to do that and have had a hard time finding examples online of that process.
    I will email you the model.
    Thank you.
     
  9. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    i will look into it asap.
     
  10. docsavage

    docsavage

    Joined:
    Jun 20, 2014
    Posts:
    1,021
    @larsbertram1,

    Hi, I tried contacting via conversation but that may not have got through.

    Was thinking AFS + CTI being compatible with this - https://www.assetstore.unity3d.com/en/?stay#!/content/132433 would be a really really nice combination. In a few clicks some of the best looking trees would make these a asset store top combination.

    Are they already compatible?

    Just a thought.
     
  11. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    i did – but i am very short on time right now. so i simply forgot to answer, sorry.
    i haven't looked into this asset. but i guess cti would be the more interesting candidate.
     
  12. docsavage

    docsavage

    Joined:
    Jun 20, 2014
    Posts:
    1,021
    Sounds good either way. Thanks
     
  13. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    dear customers,

    this is not really related to AFS but as it also may increase the immersion of your scene/game i would like to introduce you to Lux Lit Particles which give you rather cheap and real time lit particles receiving real time shadow and proper ambient lighting to make particles fit with the rest of your scene.



    As i always wanted particles to be more grounded i added support for directional light shadow. You will see the difference it makes int the screen shots below.



     
    Lex4art, hopeful and cygnusprojects like this.
  14. franky_li

    franky_li

    Joined:
    Aug 8, 2016
    Posts:
    163
    Hi Lars, I have errors in build with AFS and Unity 2018.3.8f and some from the CTI shaders. I'm using AFS, TFP and Lux Water in my project. There are no errors in editor or in play mode.
    LuxErrors.png
    The 'invalid subscript' errors come from '\Assets\Advanced Foliage Shaders v5\Shaders\Hidden Shaders\AfsFoliageShader Terrain.shader'
     
  15. larsbertram1

    larsbertram1

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

    i just tested it in unity 2018.3.10f1 on dx11.
    i do not get any errors from the afs shaders when i run out a build... ?!
    and the error you get from the AfsFoliageShader Terrain.shader looks pretty strange as this shader should never compile an instanced variant.

    have you assigned it manually to any game object? and have you enabled instancing in the material inspector?
    if so: do not do this. this shader is only for the terrain engine.
    but as it is a surface shader unity should take of adding all needed code anyway.
    so it is even more strange.
     
  16. franky_li

    franky_li

    Joined:
    Aug 8, 2016
    Posts:
    163
    No, I'm using Microsplat for terrain.
     
  17. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    i did not mean terrain and terrain shading. but vegetation rendering done by the terrain engine like grass :)
     
  18. franky_li

    franky_li

    Joined:
    Aug 8, 2016
    Posts:
    163
    I do not use details in terrain settings, I use VegetationStudio Pro for vegetation and only the VS and the AFS shaders. Even if I disable VS and have no vegetation at all, I have those errors in build:(.
     
  19. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    as i wrote yesterday: i do not get these errors in the AfsFoliageShader Terrain.shader and unity should never even try to compile an instanced version for this...
    but as you do not use this shader: simply delete it.
     
  20. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    Hey, in your documentation you give a link to a script that is supposed to bake AO for the folliage inside Unity - the link does not work, could you provide another one?
     
  21. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    you may use the vertex painter from jason booth instead:
    https://github.com/slipster216/VertexPaint
     
  22. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    Hey, there seem to be a problem with your shader and Unity's temporal anti-aliasing. I get the same artifacts when the leaves are moving as for the objects that have "Write motion vectors" set to off. Did I miss something?
     
  23. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    nope, you did not miss anything. unity's legacy rendering pipeline simply does not have any "render motion vectors" pass. so taa will never know about any animation done in the vertex shader.
     
  24. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    This is quiet sad, like really really sad, so what no fricking chance to solve it AT ALL?
     
  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    as far as i know: no. there is simply no pass that would render motion vectors for vertex animations.
    all i can think of is writing your own rendering pipeline which mimics the built in one...
     
  26. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    wait, what about skeletal animation? Is that not vertex animation? It changes resulting pixels in the end of the day, I am damn sure the actual mesh is animated via GPU, why do my skeletal meshes look great with TAA, was I not paying enough attention or what? And even still, if there is no "render motion vectors" pass, everything somehow gets rendered into motion vectors texture anyway, why is it that vertex animation is special in this regard, I really really don't get it?
     
  27. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    Ok, reading around MotionVectors I found this thing:

    https://github.com/Unity-Technologies/ScriptableRenderPipeline/wiki/How-motion-vector-work

    where they say this:


    And it led me to create a simple workaround for the leaves: just add a script to every mesh renderer which slightly changes the object's transform matrix every frame. Like this, for instance:


    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class ChangeTransformEachFrame : MonoBehaviour
    7. {
    8.     void Start() { }
    9.  
    10.     bool forward = true;
    11.  
    12.     void OnRenderObject()
    13.     {
    14.         float delta = 0.01f;
    15.         if (forward)
    16.             delta = -0.01f;
    17.  
    18.         transform.position = new Vector3(transform.position.x + delta, transform.position.y + delta, transform.position.z + delta);
    19.  
    20.         forward = !forward;
    21.     }
    22. }
    23.  
    24.  
    Can't say I am completely satisfied with how leaves looks, but they are much much cleaner looking than without the script.
     
  28. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    this is mainly related to the scriptable render pipelines – but afs is written for the built in ones.
    but actually it says "With builtin unity, you can't have wind vertex animation on an object if it doesn't move."
    so your script actually should force unity to render something to the motion vectors.

    however shaders for the built in pipelines do not have any "motion vector pass" – so the motion vectors rendered can only reflect the motion of the transform not the wind animation (done in the vertex shader).

    nevertheless: if it improves the visual result you may add your script to a few obejcts.
     
  29. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    Still, what about SkinnedMeshRenderer? Special case handeled with an internal code?
     
  30. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    i think i do not understand your question.
    skinned mesh renderers? and motion vectors?
    well, these do not do any "per vertex" animation but skinning. so these might be handled internally completely differently, yes.
     
  31. marggob

    marggob

    Joined:
    Feb 24, 2013
    Posts:
    65
    Hey.
    In the description of the asset it is written that the translucency works in deferred mode. But when you try to enable deferre mode, we get this result.
    Forward
    2019-05-24_09-38-13.png Deferred 2019-05-24_09-39-24.png
    Are we doing something wrong or is it supposed to be?
     
    Last edited: May 24, 2019
  32. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    you have to assign the afs or lux plus deferred lighting and reflection shaders to make it look correctly.
     
  33. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    Ok I will clarify what I was asking: did you try to use SkinnedMeshRenderer with your shaders in any way? Skinning is exactly the same as vertex animation (e.g. if you attach a cloth component to an object the SkinnedMeshRenderer is attached automatically) and clearly Unity has a special procedure in their builtin pipeline for motion vectors of the skinned meshes (because they look good with TAA). I am absolutely positive that if you were to somehow use your shaders with the SkinnedMeshRenderer instead of the oridary MeshRenderer than the results would be perfect. I even believe that one just have to change the MeshRenderer to SkinnedMeshRenderer and everything will work immediately.

    I wanted to ask you if you tried it (because you have clearly put a tone of work into your product) because if you did not - I will try it myself.

    UPDATE: ok, just tried SkinnedMeshRenderer and the folliage, although rendered, was not animating at all, still I feel that if one to do it properly it should solve the TAA problem.
     
    Last edited: May 24, 2019
  34. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    nope. skinning is way too expansive.
    no :)
     
  35. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    To clarify: I know the technical distinction between these things, I am talking only in the context of motion vectors. In the context of motion vectors SkinnedMeshRenderer is the same as your vertex animation, because SkinnedMeshRenderer is used when I use blendshapes models in Unity.


    Don't you think it's for users to decide what is and is not expensive? Still, did you TRY it? Or did you just deemed it too expensive? I need to know if TAA can be done via SkinnedMeshRenderer?
     
    Last edited: May 24, 2019
  36. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    Dude, AFS is a foliage shader. Skinned meshes are way too expensive for foliage. "Does TAA work with skinned meshes?" isn't a relevant question for this thread. Maybe ask on the PPSv2 thread?
     
    Willbkool_FPCS likes this.
  37. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    afs does not use blendshapes. nor does it use skinned mesh renderers. so legacy rp has no (hidden) pass to render out motion vectors which would reflect the animation done in the vertwx shader.
    that is all i know.
     
    Last edited: May 25, 2019
  38. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    no. as i have to take care for the hole system to work, i decide what the system supports. and no engine, no solution i am aware of uses skinned meshes for foliage.
    i can of course understand your frustration of vertex animations not being supported by taa.
    but that is unity, sorry.
    support for this comes with hdrp, but legacy simply does not have a specific shader pass for this.
     
  39. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    Edge fluttering cuts the mesh open.

    1.JPG

    I've noticed the if I don't paint the entire mesh vertices with the same color, I constantly get mesh tears like these when the edge fluttering animation is playing. Here is how the model looks in blender:
    2.JPG

    What could be the problem?
     
  40. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    you might have accidentally added 2 different vertex colors to a single vertex. that will double the vertex.
    also if a vertex has multiple normals (hard edges) fluttering will break the mesh.
     
  41. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    It's a 'no' to both suggestions, any other ideas?
     
  42. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    send me the mesh :)
     
  43. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    Ok I tried just repainting the mesh from scrtach (the same way I did it before) and then added it into the already initialized object (dragged into the mesh slot) and it worked perfectly right from the start (saving/applying the mesh through the afs folliage tool was not needed). I tried adding AFS folliage tool afterwards and applying the parameters and it still worked ok. This was not the first time it happened though, I might send you another mesh in the future.
     
  44. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    Yeah by the way, did you notice that your shader completely breaks if you set the camera's FOV low (like 15) - the trees start looking flat with zero translucency or specular. I plan on rewriting your shader to overcome this, but before I start maybe there is something I should know? Maybe there is an easy way to do this?
     
  45. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    i did not.
     
  46. nova234

    nova234

    Joined:
    Feb 19, 2018
    Posts:
    17
    Any chance it get a 2019.1.x update , for the LW Render pipeline
     
  47. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    lwrp might come :)
     
  48. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,208
    When using some of the AFS included prefabs in a scene, I get the following error in the development console (in a debug build) repeated several times:

    A scripted object (probably AfsFoliageTool?) has a different serialization layout when loading. (Read 32 bytes but expected 1728 bytes). Did you #ifdef UNITY_Editor a secion of your serialized properties in any of your scripts?

    The number of bytes expected varies. This is then followed by a callstack.

    Is this a problem? I'm trying to track down a crash issue, not sure if this is related or not. If not, is there a way to get it out of the development console?
     
  49. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    it is not good coding. but it should not cause a crash.
     
  50. nova234

    nova234

    Joined:
    Feb 19, 2018
    Posts:
    17
    Any new Information, when I can use Tropical Forest Pack with Unity 2019 LWRP. Its based on your shader and the dev is waiting too. My boss is not switching back from LWRP and I don't wont to lose month of hard work. I would be really thanks full if I get any info s when you start to work on it and when you release it.