Search Unity

Advanced foliage shader [released]

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

  1. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Hi @nova234, Waiting and looking forward to the LWRP & HDRP support of the CTI shaders, but it is a complete rewrite since they each handle shading completely different from SRP. Work has started on it but it is a lot of work. So hopefully something we will see soon but not something that can be rushed.

    When the support is out though will get you an updated TFP version to you and on the store as soon as possible.
     
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    it is based on the cti shaders. this is the afs thread. so you are at the wrong place...
     
  3. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    @larsbertram1

    Out of curiosity, can you tell me what exactly AFS is using modified deferred library include file (Afs_DeferredLibrary.cginc) for? I'm not seeing any obvious AFS-specific changes in there, but I need to merge it with another asset that actually does a lot of changes there (NGSS). If there are changes, I would've really appreciated them being wrapped in "// AFS" comments! :)

    The only thing I noticed is an additional shadow strength out parameter in
    UnityDeferredCalculateLightParams. Is that the only change?
     
    Last edited: Aug 2, 2019
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    i think so, yes.
     
  5. Jellonek

    Jellonek

    Joined:
    Jan 3, 2018
    Posts:
    2
    Hello.

    I need to add to AfsFoliageShaderLite.shader: _DetailAlbedoMap ("Detail Albedo x2", 2D) = "gray" {}

    half3 detailAlbedo = tex2D (_DetailAlbedoMap, TRANSFORM_TEX((_UVSec == 0) ? IN.uv_MainTex : IN.uv2_Tex, _DetailAlbedoMap)).rgb;

    and it's working perfectly for TEXCOORD0, but for TEXCOORD1 not.

    Any sugestions why?
     
  6. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    it should be: IN.uv2_DetailAlbedoMap, shouldn't it?
    and you have to declare it in the Input structure.
     
  7. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    from the docs:
    The input structure Input generally has any texture coordinates needed by the shader. Texture coordinates must be named “uv” followed by texture name (or start it with “uv2” to use second texture coordinate set).
    https://docs.unity3d.com/Manual/SL-SurfaceShaders.html

    and if you can't solve the problem with _DetailAlbedoMap_ST and TRANSFORM_TEX, do not use TRANSFORM_TEX. feed in your own tiling param (as float or float2).
    IN.uv_MainTex should already have applied the TRANSFORM_TEX anyway.
     
  8. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    this just works for me:

    Shader "Custom/NewSurfaceShader" {
    Properties {
    _Color ("Color", Color) = (1,1,1,1)
    _MainTex ("Albedo (RGB)", 2D) = "white" {}
    _Glossiness ("Smoothness", Range(0,1)) = 0.5
    _Metallic ("Metallic", Range(0,1)) = 0.0

    _DetailAlbedoMap ("DetailAlbedo (RGB)", 2D) = "white" {}
    _UVSec ("UV channel", Float) = 0
    }
    SubShader {
    Tags { "RenderType"="Opaque" }
    LOD 200

    CGPROGRAM
    // Physically based Standard lighting model, and enable shadows on all light types
    #pragma surface surf Standard fullforwardshadows

    // Use shader model 3.0 target, to get nicer looking lighting
    #pragma target 3.0

    sampler2D _MainTex;
    sampler2D _DetailAlbedoMap;
    float _UVSec;

    struct Input {
    float2 uv_MainTex;
    float2 uv2_DetailAlbedoMap;
    };

    half _Glossiness;
    half _Metallic;
    fixed4 _Color;

    // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
    // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
    // #pragma instancing_options assumeuniformscaling
    UNITY_INSTANCING_CBUFFER_START(Props)
    // put more per-instance properties here
    UNITY_INSTANCING_CBUFFER_END

    void surf (Input IN, inout SurfaceOutputStandard o) {
    // Albedo comes from a texture tinted by color
    fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
    o.Albedo = c.rgb;

    float2 detailUV = (_UVSec == 0) ? IN.uv_MainTex : IN.uv2_DetailAlbedoMap;
    o.Albedo += tex2D (_DetailAlbedoMap, detailUV);

    // Metallic and smoothness come from slider variables
    o.Metallic = _Metallic;
    o.Smoothness = _Glossiness;
    o.Alpha = c.a;
    }
    ENDCG
    }
    FallBack "Diffuse"
    }
     
  9. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    i just focused on the uvs here.
    what you do with the sample is up to you.

    i don't know what this Lite shader is...

    do not use TRANSFORM_TEX here.
     
    Jellonek likes this.
  10. Jellonek

    Jellonek

    Joined:
    Jan 3, 2018
    Posts:
    2
    I was talking about: Shader "AFS/Foliage Shader Lite".

    And now it is working correctly, one small mistake ! Thank you very much and have, a nice day.
     
  11. Radu392

    Radu392

    Joined:
    Jan 6, 2016
    Posts:
    210
    Hello, I recently bought this pack and I'm having an issue with the 'Foliage Shader v4'.



    I'd like to put some detail meshes onto my terrain. However, the detail mesh using that shader is red (grass on the left). The grass on the right is a detail mesh using the standard shader and the one in the middle is gameobject using the foliage shader. This is with a completely virgin terrain.



    Also the wind affects the gameobject and detail mesh differently. The detail mesh moves all of the leaves from bottom to top, but the gameobject moves only the higher parts of the grass which is the correct behaviour. (imagine a whole human moving as opposed to its upper body) How can I get the same result with the terrain? Playing with the wind settings on the 'SetupAdvancedFoliageShader' doesn't get me the same result as the gameobject.
     
  12. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    i do not see any red mesh and adding them to the terrain needs you to add them to the terrain and paint them using the tools built in to the terrain...
     
  13. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    Hello! Does this shader work on naturemanufacture assets? And also, does bending work when rendering with VS Pro? @larsbertram1
     
  14. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    unfortunately not without painting new vertex colors.
    you will have to set vertex color green to 0.0 or to very low values at the outer edges of the leaves.
    you may set vertex color red to entire shells to get some variation depending on the model.
    you may use the included foliage tool to set primary and secondary bending
    only if the you spawn the plant as game object when it gets close to the camera. it relies on physics and materialpropertyblocks. vs pro displacement is not suitable for anything else but grass afaik.
    .
     
    mattis89 likes this.
  15. bobAZ2019

    bobAZ2019

    Joined:
    Mar 28, 2019
    Posts:
    28
    hi,

    i just bought this in December 2019.
    just wondering when will AFS support URP?
     
    URPian likes this.
  16. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    i have no eta yet – but 2 other assets which support URP:
    Advanced Terrain Grass [>] (grass and foliage shaders)
    Lux URP Essentials [>] (grass, foliage, tree creator trees)

    which shader do you want to use with urp? and which feature do you need?
     
  17. bobAZ2019

    bobAZ2019

    Joined:
    Mar 28, 2019
    Posts:
    28
    i bought both of your Advanced Terrain Grass & Lux URP Essentials. excellent stuff.
    i also bought Advanced Foliage Shaders v.5 & Tropical Forest Pack (TFP).
    actually, i bought TFP because it needs AFS.

    anyway, the stuff i need is the URP shader that will work with TFP.
     
    URPian likes this.
  18. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    this is a completely different story then. the tropical forest pack uses cti – which already supports urp.
    ask baldinoboy for a proper package.
     
    URPian likes this.
  19. TaylorMonkeyAl

    TaylorMonkeyAl

    Joined:
    Nov 13, 2019
    Posts:
    4
    We're using AFS in an upcoming project and I'm currently having some issues with the Child Combine script when using the AFS Foliage shader and Legacy Vertex Color Bending.

    Instead of the foliage behaving like it would before combining, it seems to lose wind movement aside from what looks like turbulence. Combine Children with Vertex Color Bending seems fine (or at least better) from what I can tell.

    Does Combine Children properly support the AFS Foliage shader with Legacy Vertex Colors?
     
  20. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    it should! altho i do not recommend to use legacy vertex colors at all.
     
  21. TaylorMonkeyAl

    TaylorMonkeyAl

    Joined:
    Nov 13, 2019
    Posts:
    4
    Do you mind running a quick test on your end to see if combining several instances of a tree (like the banana tree) with the shader set to use legacy vertex colors produces the same/similar movement as when it's not combined?
     
  22. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    it might not!
    if gpu instancing is disabled and dynamic or static batching are enabled the foliage shader will take the wave size into account as specified in the setup script because it is not clear if the pivot of the mesh the vertex shader is operating on is the pivot of a real plant. so the shader does not do any calculations based on he pivot but uses some world space noise (waves).
    if you combine meshes the combine children script will bake the pivots into the mesh. so you alwas get the "better" bending based on pivots.

    but i did a quick test, opened the overview demo, created a new game object, parented 3 copies of the banana legacy colors under it and added the combine children script: hitting play the bending of the combined mesh jsut looks fine.
     
  23. zelmund

    zelmund

    Joined:
    Mar 2, 2012
    Posts:
    437
    hi there
    wanted to use it with URP with bending for grass and trees
    wanted to simulate grass/trees bending when explosions happens
     
  24. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    then lux urp esentials would be the right package for you.
     
  25. tntfoz

    tntfoz

    Joined:
    Sep 29, 2016
    Posts:
    129
    Hi quick question about your AFS shader: does it allow GPU instancing for tree creator trees even when wind is enabled? When looking at multiple instances of trees (all sharing the same material) in the Unity editor I can see the Setpass/batching calls remain fixed regardless of number of trees, until I enable a wind zone. Then the setpass calls multiply up by the number of trees.

    Does your shader allow GPU instancing even with wind enabled?

    I'm using Unity 2018.4.8 LTS and the trees currently have the default Tree Creator shaders (which I'm hoping to improve on!), thanks!
     
    Last edited: Jun 5, 2020
  26. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    they do. wind is part of an instancing buffer. just like per instance color or scale.
     
    tntfoz likes this.
  27. tntfoz

    tntfoz

    Joined:
    Sep 29, 2016
    Posts:
    129
    Thanks for your help!
     
  28. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    I've injected AFS code into an HDRP Lit shader and I everything works fine, the only trouble I am having is with leaves moving very fast once you move or rotate the camera. Now I know about the camera-relative rendering and I made sure to move the vertices to the object space and back (by adding/subtracting _WorldSpaceCameraPos) in all the case I could find (position, pivot, etc.) yet the camera movement still speeds up vertex movement, how can this be fixed?
     
  29. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    i guess you have missed one.
     
  30. KingLlama

    KingLlama

    Joined:
    Jul 18, 2015
    Posts:
    199
    Am I able to use AFS and ATG at the same time?
     
  31. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    they only interfere if it comes to deferred lighting. in this case you would have to use the deferred lighting shader from ATG.
    which feature from AFS do you want to use along with ATG?
     
  32. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    they only interfere if it comes to deferred lighting. in this case you would have to use the deferred lighting shader from ATG.
    which feature from AFS do you want to use along with ATG?
     
  33. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    btw.: AFS users can now get ATG for 5$.
     
  34. KingLlama

    KingLlama

    Joined:
    Jul 18, 2015
    Posts:
    199
    I would love to use the shaders for foliage and trees to create a better LOD compared to unitys.
     
  35. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    atg has its own foliage shader. and afs tree creator trees should be fine rendered using atg deferred lighting.
     
    KingLlama likes this.
  36. Unplug

    Unplug

    Joined:
    Aug 23, 2014
    Posts:
    256
    Hello,
    (using AFS V5 in unity 2017 LTS)
    in a developper build, the console return error regarding AfsFoliageTool script. The whole script is a
    #if UNITY_EDITOR

    and reading over the net, it look like it's the problem. Is there a fix or a way to avoid that or any problem removing the line ??? what is recommended

    that script is sitting on some of the included prefab which i used in my level.
     
  37. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    best way i guess: duplicate the prefab and keep the copy so you can rework the mesh later on.
    go bavk to the keep the modified mesh assigned and simply remove the foliage tool from the prefab.
    i have to admit that it was bad decision to use these prefabs in the included demos.
     
  38. Unplug

    Unplug

    Joined:
    Aug 23, 2014
    Posts:
    256
    i guess i should not have use them... but it should work, no script should cause build error. it's unacceptable. It me be my understanding of those script that is lacking. We learn in various way.

    After removing the script from the only problematic prefab i was using fix the problem. Im heading toward removing AFS anyway
     
  39. piorotorus

    piorotorus

    Joined:
    Apr 23, 2017
    Posts:
    1
    Hey, I'm using this asset and I have a problem. I have two different plants (not from the tree creator). I added an AFS shader to them and I would like one to move faster and the other slower. Is there any way to set it like this?
    Thanks :)
     
  40. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    email sent!
     
  41. nubdev

    nubdev

    Joined:
    Mar 30, 2013
    Posts:
    87
    Hi I am having trouble with grass using "Foilage Shader v4" not showing up in builds. The "Fern Pre" shows up while using it but not "Grass single sided pre" when building. It does show up in play mode in editor. Any assistance is appreciated thank you
     
  42. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    do you get any errors while building?
     
  43. nubdev

    nubdev

    Joined:
    Mar 30, 2013
    Posts:
    87
    No, I dont get any build errors. I am using Unity 2019.4.9f1, AFS v. 4.02. I use the Geometry Brush to apply the grass and fern prefabs parented to the required empty GameObject, but only the ferns are visible after building.
    Using deferred rendering, Built In Render Pipeline. Thanks
     
  44. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    so first question would be: is it geometry that is missing or the shader/material?
    what happens if you assign a different material with the sztandard shader e.g.?
     
  45. nubdev

    nubdev

    Joined:
    Mar 30, 2013
    Posts:
    87
    When changing the shader the grass does appear in builds so I am guessing it is the AFS shader and not an issue with the mesh. Also I was mistaken before, the fern and grass are not using the same shaders, the shader with the issue is "AFS/Grass Shader v4".
    I've added it to "Always Included Shaders" but it doesnt help.
     
  46. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    maybe some of the inputs from script are not set?
     
  47. nubdev

    nubdev

    Joined:
    Mar 30, 2013
    Posts:
    87
    I am unsure what you mean by this, are you referring the manager, shader or grass prefab itself?
     
  48. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    the manager.
     
  49. longde123

    longde123

    Joined:
    Dec 17, 2014
    Posts:
    1
    unity 2020 urp not work~~
     
  50. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    the shaders only support the built in pipeline.