Search Unity

Advanced foliage shader [released]

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

  1. Game-Armada

    Game-Armada

    Joined:
    Apr 29, 2013
    Posts:
    62

    sorry, I meant to upload my afs5 shader modifications only, but I was able to reproduce the problem with the "clean" package, so it wasn't necessary.
    Great, I will test this solution tomorrow!!! :) Will get back, if it works for me too! Thx for the quick reply!
     
  2. lucyod10

    lucyod10

    Joined:
    Oct 30, 2017
    Posts:
    1
    Hey!
    The shader looks incredible, and the effects are exactly what I'm after. However I'm having a few problems and I would be really appreciative of anyone helping me out because I'm not super familiar with using shaders from the asset store.
    All the prefabs provided are working fine, however when applying the shader to any of my models (trees, shrubs, 3D plants) the same issue happens. I've put in a vid of the issue, but basically it appears that the vertex colours are not working, and there are different transparencies of my texture wibbling at different rates.
    I believe where I'm going wrong is with the foliage tool, as when I apply it nothing changes, and I'm not sure how to edit it. Any change (except from turning primary bending to relative to pivot (which improves but doesn't fix the issue)) doesn't seem to change anything.
    I know I'm definitely doing something wrong but I cant find anything in the documentation to explain how I'm messing up.



    Thanks heaps!
     
  3. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,940
    do you use forward rendering? and do you have multiple pixel lights?
    in this case the ghosting effect most likely is caused by an additional forward lighting pass and slightly different displacement results between the different passes: deactivating "preserve length" in afs setup script should fix or at least reduce the ghosting effect.

    you haven't checked: enable instancing" in the material editor. in this case the shader expects just something like a soup of vertices (and no pivots) and applies some simple noise to the wind animation controlled by the "Wind Settings for Foliage Shaders" --> "Wave Size" parameter of the setup script. increase the wave size to get some more believable results. or – better – check "Enable instancing" to get best bending.
     
  4. Game-Armada

    Game-Armada

    Joined:
    Apr 29, 2013
    Posts:
    62

    Works, thx!
     
  5. JMeer

    JMeer

    Joined:
    Mar 3, 2017
    Posts:
    20
    Heyhey i'm having tons of fun vertex painting our plant/tree models and bringing them alive with the shaders! It is incredible how much more alive the game has gotten thanks to the wind shaders! Awesome documentation as well!

    I always use the AFS Foliage tool to tweak the Vertex colors. But since recently (Unity 2017.2.0f3), the curves don't get saved within the Inspector and instantly revert to the standard linear line somehow. I tested it in a new project and there, it also seems to be the case.

    When switching back to Unity 5.6, and opening the same new project, the curves do get saved within the inspector. I am using that project to tweak the models first, before transferring them to our project. Any tips? :D
     
  6. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,940
    it might be a bug in 2017 - at least i haven't been able to edit an animation curve in a custom inspector in unity 2017 so far...
    so right now all you can do is to switch to debug mode (upper right corner of the inspector tab), edit the cureves, switch back and apply your settings.
     
    JMeer likes this.
  7. JMeer

    JMeer

    Joined:
    Mar 3, 2017
    Posts:
    20
    Thanks man! That's really useful to me. :D
     
  8. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,940
    you are welcome – although i would be more satisfied if i had been able to write a fix...
     
    JMeer likes this.
  9. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,940
    finally i have found a work around for unity 2017 – it should be available within the next days.
     
  10. Dev-A

    Dev-A

    Joined:
    Oct 11, 2013
    Posts:
    28
    for the dev---
    "Legacy bending supports plants being placed using the terrain engine. Legacy bending will be skipped in the next updates." Why skip legacy bending, it sounds really useful in my case.

    Keep up the great work!

    for the forum----
    I had a problem with the touch bending. I noticed that it isn't the "is kinematic" that was the issue, it was gravity preventing it from bending. Also realized all I needed was a collider set to trigger with the touch bend script parented to my player. :oops: leaving this here in case others search this.
     
    Last edited: May 9, 2018
  11. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,940
    you can use "vertex colors" instead of "legacy vertex colors". so there is no need to keep the legacy bending.
     
  12. Game-Armada

    Game-Armada

    Joined:
    Apr 29, 2013
    Posts:
    62
    Hi again!

    Can I control somehow the translucency strength of the terrain grass detail ("grass texture", not "detail mesh")?
    The "Combined detail atlas" texture does not affect it.
    (which shader responsible for rendering those?)

    THX
     
  13. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,940
    unfortunately no. you have to add grass as detail mesh – not as a simple texture.
    using a simple texture is bad as it will most likely waste fill rate (grass does not look like a quad) and it does not allow you to map it to the "Combined detail atlas" texture.
     
  14. Ravery

    Ravery

    Joined:
    Mar 5, 2016
    Posts:
    26
    Why do you require everybody using your product to change the channels so much?
    Everyone creating your special texture has to take the normal's red channel and change it into green as well as taking the green channel and change it into alpha.
    This is how it is right now:
    Red --> Green
    Green --> Alpha
    Translucency --> Red
    Smoothness --> Blue

    I think this should be:

    Red -> Red
    Green -> Green
    Smoothness --> Blue
    Translucency -> Alpha (The alpha channel... which kinda deals with fkn transparency!)

    inb4 "performance gain":
    Whatever you gain in real time, does not compare to the drawbacks regarding development workflow and the whole channel separation/swap/recombination you make people do.
     
    Last edited: Nov 17, 2017
  15. coverpage

    coverpage

    Joined:
    Mar 3, 2016
    Posts:
    385
    Very rude
     
  16. Ravery

    Ravery

    Joined:
    Mar 5, 2016
    Posts:
    26
    You are right. I have edited the post. Still, it is a very strange design
     
    coverpage likes this.
  17. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,940
    normals are stored in dxt5nm format:
    red --> alpha
    green --> green
    blue is dropped. the reason for that is that the red channel has the worst quality after compression, it is just a blocky something with only a few shades of gray. alpha does not get compressed.
    so smoothness (very important for physically based shading) goes into blue.

    this is the best choice for packing all the data in just a single texture for both cases: using DXT5 (normal quality) or BC7 (high quality).
     
    hopeful likes this.
  18. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,301
    Understand it might look annoying at first but it is a very simple process once you do it a couple times. You can even make it an action in Photoshop so it only takes 3 seconds :)
     
  19. Ravery

    Ravery

    Joined:
    Mar 5, 2016
    Posts:
    26
    If this is indeed necessary provide some Editor based conversion method, which takes the smooth, trans and normal maps and creates your combined texture with a click of a button. Bonuspoints for some automatic process, which detects file changes and does the conversion automatically.
    Right now your product is incompatible with EVERY asset out there and needs a substantial amount of work to be made compatible. Given the file selection, import, channel swap, export, switching shader, changing blueprints, testing visuals every asset one wants to use adds like 20 minutes. Bought some 50 different plants pack to save time? Nope. Are you using some third party solution to increase your workflow? Nope.
    It's like having a nice mail program, but every time you get a mail you have to remompile it, because the developer thinks hardcoding content is more efficient.

    Here is one possible solution:
    Make a development shader, which takes all the maps as they are normally used.
    Create an editor extension, which runs through all prefabs using the dev shader.
    List all the prefabs with checkboxes (and a non/all option).
    Hitting Convert creates your maps and replaces all usage of the selected dev shader materials with generated materials using your normal shader.
     
  20. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,940
    thanks for your thoughts.
    i may consider adding something like this in future releases.
     
  21. travakin

    travakin

    Joined:
    Apr 20, 2012
    Posts:
    5
    Hi Lars, I recently purchased the ATS package and it really looks great! I have run into a problem though, the AfsCamera-DepthNormalTexture shader is giving me an error (invalid input semantic 'POSITION'): Error.PNG
    I could not find any fixes that worked on the web. What could be the issue here? I am using Unity 2017.2.0f3

    Thanks!
     
  22. Ranter1337

    Ranter1337

    Joined:
    Nov 4, 2015
    Posts:
    15
    I am getting the exact same error as travakin but on Unity 2017.2.0p2, this error only occurs when i try to build to Windows platform
     
  23. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,940
    actually the shader was missing some conditional directives.
    fixed version attached.
    please let me know if everything works fine now.
     

    Attached Files:

    hopeful likes this.
  24. travakin

    travakin

    Joined:
    Apr 20, 2012
    Posts:
    5
    It works perfectly now, thank you!
     
  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,940
    you are welcome!
     
  26. Game-Armada

    Game-Armada

    Joined:
    Apr 29, 2013
    Posts:
    62
    with AFS and some shader tweaks:

    tc2_test1.jpg tc2_test2.jpg tc2_test3.jpg
     
  27. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,940
    that looks pretty good – just like a heavly crossed photography.
    and i am a big fan of your trees, well done!
     
    Game-Armada likes this.
  28. 265lutab

    265lutab

    Joined:
    Sep 15, 2014
    Posts:
    150
    Can this plugin be used without a Unity Terrain placing grass onto a custom mesh ground?
     
  29. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,940
    it can – but it is not designed to cover huge areas of grass.
     
  30. AcornBringer

    AcornBringer

    Joined:
    Mar 22, 2015
    Posts:
    61
    Hey again!

    I recently switched over to linear color space for my project after all the signals pointing me in that direction as well as being told here that I should. Everything works fine after a few shader, light, and material adjustments however I started getting this notice down in the console stating the following:

    Colorspace changed to linear.
    UnityEngine.Debug:Log(Object)
    SetupAfs:afsCheckColorSpace() (at Assets/Advanced Foliage Shaders v5/Scripts/Setup AFS/SetupAfs.cs:285)
    SetupAfs:Awake() (at Assets/Advanced Foliage Shaders v5/Scripts/Setup AFS/SetupAfs.cs:204)

    As soon as I launch the project it pops up and at some points while I'm in the editor or when I run the game. I'm not sure what it means or how it is being produced but it has Afs in it so I figured I'd ask.

    Thanks!
     

    Attached Files:

  31. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,940
    it is all fine. afs just checks for the color space as it needs to know about when it comes to feed the billboard rendertexture shaders.
    i might rework the wording though.
     
    AcornBringer likes this.
  32. Game-Armada

    Game-Armada

    Joined:
    Apr 29, 2013
    Posts:
    62
    Hi Lars,

    is it possible to modify the AfsFoliageShader (instanced) shader to exclude the reflection probe and/or skybox when calculating the reflection/specular part? only count with the Unity lights to create the speculars?
     
  33. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,940
    depends on if you use deferred and deferred reflections – or forward or deferred an legacy reflections.

    in either way you will have to edit the lighting function and set gi.indirect.specular to 0.0 before you call
    "half4 c = UNITY_BRDF_PBS".
    in case you use deferred reflections you will also have to to set occlusion to 0 after you have called the BRDF:
    outDiffuseOcclusion = half4(s.Albedo,0);
     
  34. Game-Armada

    Game-Armada

    Joined:
    Apr 29, 2013
    Posts:
    62
    THX, done! works like a charm and now I am totally happy with the results!!! :)

    upload_2017-12-13_12-9-51.png upload_2017-12-13_12-13-5.png
     
  35. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,940
    it might look nice. personally i think not having specular ambient reflection will disconnect foliage from the rest of the scene.
     
  36. Game-Armada

    Game-Armada

    Joined:
    Apr 29, 2013
    Posts:
    62
    I only need this solution when the sun intensity is around 1 or 2.. normally I use a directional light with around 25-30 intensity with post processing, to achieve decent hdr visualization and good effects.
     
  37. Detniess

    Detniess

    Joined:
    Oct 28, 2014
    Posts:
    46
    This looks awesome. Could you show how to achieve results like this? :)
     
  38. Game-Armada

    Game-Armada

    Joined:
    Apr 29, 2013
    Posts:
    62
    With AFS of course :)

    Anyhow, what exactly you want to know?
    - how to create a model like this
    - what textures do you need
    - how to setup afs for that
    - how to setup the scene for that
     
  39. Game-Armada

    Game-Armada

    Joined:
    Apr 29, 2013
    Posts:
    62
    Randomly placed stuff:

    upload_2017-12-14_15-34-26.png
     
  40. Game-Armada

    Game-Armada

    Joined:
    Apr 29, 2013
    Posts:
    62
    upload_2017-12-14_15-37-34.png tree close-up:
     
    Detniess likes this.
  41. Detniess

    Detniess

    Joined:
    Oct 28, 2014
    Posts:
    46
    Mostly on how to setup it up in Unity with afs, lighting etc. But if you're using anything special related to the actual models and textures it could be interesting to know as well. I'm basically interested in what you think is the most important steps on how to achieve a visual quality like this. Only if you're willing to share ofc :)
     
  42. Game-Armada

    Game-Armada

    Joined:
    Apr 29, 2013
    Posts:
    62
    Basicliy what I am doing is very simple. For the tree leaves I use the AFS/Foliage shader with the color texture and with the Normal(GA) Trans(R) Smoothness(B) textures.
    I set the Trans channel to plain white (to make it fully translucent) and the smoothness to somewhere middle gray (127,127,127 rgb)
    I set the Specular Reflectivity to somewhere mid green like 65, 127, 65
    I use directional light for the sun and with intesity set to 2.
    For the environemnt I use http://noemotionhdrs.net hdr skies and at the lighting tab I set the environment lighting to skybox and tweak the Intesity there, too.

    Basically, that's all. Additionally I have added some extra parameters to the shader, like brightness, saturation, normal power. it's easier to tweak and not to modify the textures and save them ..etc..

    Let me know if you have more questions!
     
    jdraper3 and Detniess like this.
  43. shamsfk

    shamsfk

    Joined:
    Nov 21, 2014
    Posts:
    277
    Hi! I'm using both Vegetation Studio and CFS, first one to place foliage and second to render (a bit faster with my scene). Does AFS's integration with any of this assets supports collision bending?
     
  44. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,940
    none of these supports afs original touch bending as it relies on gos and colliders.
     
  45. Game-Armada

    Game-Armada

    Joined:
    Apr 29, 2013
    Posts:
    62
    upload_2017-12-21_17-32-16.png Endor :):)
     
    Baldinoboy likes this.
  46. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    4,873
    Very nice overall, but there are heavy seams low on the tree trunks? What causes that?
     
  47. Game-Armada

    Game-Armada

    Joined:
    Apr 29, 2013
    Posts:
    62
    Basic texture and/or UV problems with the assets. Asked the publisher to check on that, hope to get some answers soon :)
     
  48. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,512
    @larsbertram1 When using the update for Vegetation Studio, which Conifer prefab should I use? There are Conifer [FlattenedTree], Conifer [FlattenedTree] without tree script, and Conifer[as foliage]. Also, does the scene still need a Setup AFS prefab in it?
     
  49. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,940
    the update only effects the foliage shader.
    trees are still handled the way vs handles tree creator trees.
    yes
     
  50. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,512
    Are the grass prefabs supposed to work? I put one into VS and even though it seems to render, the rendering looks all wrong and I get a VS error as follows:

    NullReferenceException: Object reference not set to an instance of an object
    AwesomeTechnologies.VegetationItemModelInfo.CreateComputeBuffer () (at Assets/AwesomeTechnologies/VegetationStudio/VegetationSystem/VegetationItemModelInfo.cs:366)
    AwesomeTechnologies.VegetationItemModelInfo.AddVegetationModel (UnityEngine.GameObject rootVegetationModel, Int32 lodIndex) (at Assets/AwesomeTechnologies/VegetationStudio/VegetationSystem/VegetationItemModelInfo.cs:113)
    AwesomeTechnologies.VegetationSystem.SetupVegetationPrefabs () (at Assets/AwesomeTechnologies/VegetationStudio/VegetationSystem/VegetationSystem.cs:958)
    AwesomeTechnologies.VegetationSystem.SetVegetationPackage (Int32 index, Boolean resetCullingGroup) (at Assets/AwesomeTechnologies/VegetationStudio/VegetationSystem/VegetationSystem.cs:1425)
    AwesomeTechnologies.VegetationSystem.SetupVegetationSystem () (at Assets/AwesomeTechnologies/VegetationStudio/VegetationSystem/VegetationSystem.cs:535)
    AwesomeTechnologies.VegetationSystem.Enable () (at Assets/AwesomeTechnologies/VegetationStudio/VegetationSystem/VegetationSystem.cs:578)
    AwesomeTechnologies.VegetationSystem.OnEnable () (at Assets/AwesomeTechnologies/VegetationStudio/VegetationSystem/VegetationSystem.cs:571)

    upload_2017-12-28_13-57-47.png