Search Unity

Advanced foliage shader [released]

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

  1. baci

    baci

    Joined:
    Apr 29, 2013
    Posts:
    4
    The AFS/Foliage Shader v4 doesn't work anymore in Unity 5.2! (DX9 mode)

    The attached screenshot shows a scene directly after project conversion. Exact Unity version is 5.2.0p1.
     
    nasos_333 likes this.
  2. RockSPb

    RockSPb

    Joined:
    Feb 6, 2015
    Posts:
    112
    Hello!
    I have a couple questions.
    Does afs works on WebGL?
    Is bug with SSAO still don't fixed?
    Thanks!
     
  3. kideternal

    kideternal

    Joined:
    Nov 20, 2014
    Posts:
    82
    Errors after opening a 5.1.3p2 project in 5.2.1p1:
    Shader error in 'AFS/Foliage Shader v4': invalid subscript 'color' at line 149 (on d3d11)
    Shader error in 'AFS/Foliage Shader Raindrops v4': invalid subscript 'color' at line 163 (on d3d11)
    Shader error in 'Hidden/TerrainEngine/Details/Vertexlit2': invalid subscript 'color' at line 178 (on d3d11)
    Shader error in 'AFS/Foliage Shader Touchbending v4': invalid subscript 'color' at line 156 (on d3d11)
     
  4. Xenonus

    Xenonus

    Joined:
    Jun 26, 2014
    Posts:
    53
    Indeed the AFS Foliage shader does not work in 5.2.1f1.
    The shader itself cannot compile due to the above already mentioned errors:

    Shader error in 'AFS/Foliage Shader v4': invalid subscript 'color' at line 149 (on d3d11)
    Shader error in 'AFS/Foliage Shader Raindrops v4': invalid subscript 'color' at line 163 (on d3d11)
    Shader error in 'Hidden/TerrainEngine/Details/Vertexlit2': invalid subscript 'color' at line 178 (on d3d11)
    Shader error in 'AFS/Foliage Shader Touchbending v4': invalid subscript 'color' at line 156 (on d3d11)

    AFS Foliage shader deferred however works in linear.
    Please recheck this.
     
  5. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    Hi, I had a couple of questions. Does this work in a way where I can make trees have scripts and colliders on them? My trees need to be interactable when the player is nearby.

    2nd question, are the billboards auto-generated from the plugin or do I need to create them myself? I have a bunch of already made trees and I'm not sure if they'll work with your plugin.
     
  6. BornGodsGame

    BornGodsGame

    Joined:
    Jun 28, 2014
    Posts:
    587
    I will piggy-back on wightwale with some newbie questions made pre-purchase.

    I only really want two functionalities. These are for hand-placed plants ( not using terrain tool). The two functions are bend and wind effects.

    Is this as simple as changing the shader I am currently using (nature-leaves) to a new shader and adjusting some shader setting in the editor? Or does this involve messing with textures or other more complicated things.

    It looks like an amazing product with great features and support, but I am pretty far into my project, and so have to decide if it is worth going back and doing a ton of work on hundreds of different plant prefabs in order to add a few cool features.
     
  7. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi there,
    indeed: some shders do not compile in unity 5.2.1.
    i am sorry for that inconvenience but to me it looks like a massive bug in shader lab…

    i have just pushed an updated package which however might take some days to get accepted.

    so for all those who do not want to wait: you can simply edit the affected shaders (AfsFoliageShader v4, AfsFoliageShader Touchbending v4, AfsFoliageShader Raindrops v4 and AfsFoliageShader Terrain v4) manually:

    find:

    struct Input {
    float4 myuv_MainTex; // here we need float4
    #if !defined(UNITY_PASS_SHADOWCASTER)
    fixed4 color : COLOR; // color.a = AO
    float3 worldNormal;
    INTERNAL_DATA
    #endif
    };

    and replace it by:

    struct Input {
    float4 myuv_MainTex; // here we need float4
    // Unity 5.2 does not like this?!
    //#if !defined(UNITY_PASS_SHADOWCASTER)
    fixed4 color : COLOR; // color.a = AO
    float3 worldNormal;
    INTERNAL_DATA
    //#endif
    };
     
    hopeful likes this.
  8. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    please have a look into my post above.
    lars
     
  9. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    you will have to "rework" your plant meshes – which can be done using the provided afs foliage tool in order to set up bending.
    and textures use a custom combined format – so you will have to work on them too.

    sorry, but there is just no way to apply proper bending to a random mesh.
    lars
     
  10. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    if you place trees as trees they will just act as regular trees – apart from the improved fading into billboards.
     
  11. Xenonus

    Xenonus

    Joined:
    Jun 26, 2014
    Posts:
    53
    Many thanks for quickly fixing the compile error in 5.2.1!
     
  12. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    So I have a bunch of tree models for my game and they will work with fading into billboards system? Can I also add the bending to my own trees? How much work is this for me to setup? Also does this use a LOD system to accomplish this or would it be possible to use this with another LOD system?
     
    Last edited: Sep 30, 2015
  13. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    you are welcome!
     
  14. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    trees will work like regular trees with advanced blending into billboards.
    afs doe not use any lod system by default but you could use unity's built in one.
    and the amount of work demands on your personal demands.
     
  15. BornGodsGame

    BornGodsGame

    Joined:
    Jun 28, 2014
    Posts:
    587
    No problem, thank you for being upfront. I will have to wait til Nobiax redoes the rest of his packs.
     
  16. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    I'm a bit confused on billboarding. I put the AFS Simple Tree shader on a single tree mesh and put it in the terrain, but it doesn't appear to be billboarding only changing color from dark to light. My trees were made in 3DSMax and not in unity. What am I missing?
     
  17. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    please refer to the "tree demo" scene.
    and your description is not very precise. sorry.
     
  18. RockSPb

    RockSPb

    Joined:
    Feb 6, 2015
    Posts:
    112
    Could you answer, please?
     
  19. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i am not on webgl right now.
    and i am not aware of any ssao isues.
     
  20. Gozdek

    Gozdek

    Joined:
    Jun 21, 2015
    Posts:
    356
  21. Avonaeon

    Avonaeon

    Joined:
    Apr 17, 2012
    Posts:
    48
    I think it might be a conflict between Sonic Ether's SSAO and AFS, but might also be the normal SSAO, though I'm not sure. How it's shows for me is that SSAO seems to flicker on branches of tree creator trees. I have two screenshots here: http://imgur.com/a/0McaC
    Using Unity 5.1.3 in DX9
     
  22. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    that looks more like regular shadow acne (as ssao would not create such sharp artifacts i think).
    so i would recommend to check your shadow bias settings.
     
  23. Avonaeon

    Avonaeon

    Joined:
    Apr 17, 2012
    Posts:
    48
    No, it's definitely the SESSAO / AFS combo. Tweaking the shadow bias does nothing, and making a tree that doesn't use the AFS shaders, also does not have the flickering.
     
  24. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    then make sure that you use the correct cameradepthnormal-shader that ships wit afs and get rid of any other cameradepthnormal-shader in your project.
     
  25. Avonaeon

    Avonaeon

    Joined:
    Apr 17, 2012
    Posts:
    48
    I should be using the correct cameradepthnormal-shader, if I followed the guides for setting up AFS, right? Or are there additional steps that I've missed?

    I can see that the SESSAO shader uses _CameraDepthTexture as well, so I guess we can't use SESSAO and AFS together, and have to sacrifice one or the other?

    If that's the case, we'll probably be sacrificing the SESSAO effect, but it'll be a damned shame.
     
  26. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    you have to make sure that there is no other cameradepthnormal-shader in your project.
    hmm, i have no idea why sonic ether would use both textures… but according to the docs:
    Depth texture is rendered using the same shader passes as used for shadow caster rendering (“ShadowCaster” pass type). So by extension, if a shader does not support shadow casting (i.e. there’s no shadow caster pass in the shader or any of the fallbacks), then objects using that shader will not show up in the depth texture.
    http://docs.unity3d.com/Manual/SL-CameraDepthTexture.html

    so it should be just fine.
     
  27. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    I was trying to use your shader on PS4 but I'm hitting some issues. Do you know if this is an easy fix or hard? I'm not that great with shaders.

    22:14:08 WARNING: Shader Unsupported: 'Nature/Afs Simple Tree v4' - Pass 'FORWARD' has no vertex shader
    22:14:08 WARNING: Shader Unsupported: 'Nature/Afs Simple Tree v4' - Pass 'FORWARD' has no vertex shader
    22:14:08 WARNING: Shader Unsupported: 'Nature/Afs Simple Tree v4' - Pass 'SHADOWCASTER' has no vertex shader
    22:14:08 WARNING: Shader Unsupported: 'Nature/Afs Simple Tree v4' - All passes removed
    22:14:08 WARNING: Shader Unsupported: 'Nature/Afs Simple Tree v4' - Setting to default shader.

    Porting Your Shaders
    If you have existing Unity projects that you wish to try on PS4, then you should take note of a change to how shaders must be written. Failure to make these changes will most likely result in objects being rendered in pink/purple.

    The details of what to change are below, shaders updated in this way should continue to work on all platforms:

    • v2f structures (output from vertex shader used as input to fragment shader) must be changed from POSITION to SV_POSITION. Note that a2v (application to vertex) structures should continue to use POSITION.
    • Fragment shader output that writes colour must be changed from COLOR to SV_Target.
    • Fragment shader output that writes depth must be changed from DEPTH to SV_Depth.
    • Do not use "sample" as a variable name in shaders. This is a reserved word that will cause shaders to fail to compile.
     
  28. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi there,
    i do not know which version of afs you use. but it looks as if it was not the latest one.
    currently almost all shaders are written as surface shaders so unity should be fully responsible for applying the needed adjustments.
    next to that i am pretty confused about this shader not compiling while others seem to do.
     
  29. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    I tried out the foliage shader overview demoscene on the PS4 to see which other shaders had issues. I used the 4.01 version of the plugin. The grass looked good as well as the banana trees.

    05:27:58 WARNING: Shader Unsupported: 'Nature/Afs Tree Creator Leaves Optimized' - Pass 'FORWARD' has no vertex shader
    05:27:58 WARNING: Shader Unsupported: 'Nature/Afs Tree Creator Leaves Optimized' - Pass 'FORWARD' has no vertex shader
    05:27:58 WARNING: Shader Unsupported: 'Nature/Afs Tree Creator Leaves Optimized' - Pass 'SHADOWCASTER' has no vertex shader
    05:27:58 WARNING: Shader Unsupported: 'Nature/Afs Tree Creator Leaves Optimized' - All passes removed
    05:27:58 WARNING: Shader Unsupported: 'Nature/Afs Tree Creator Leaves Optimized' - Setting to default shader.
    05:27:58 WARNING: Shader Unsupported: 'Nature/Afs Tree Creator Bark Optimized' - Pass 'FORWARD' has no vertex shader
    05:27:58 WARNING: Shader Unsupported: 'Nature/Afs Tree Creator Bark Optimized' - Pass 'FORWARD' has no vertex shader
    05:27:58 WARNING: Shader Unsupported: 'Nature/Afs Tree Creator Bark Optimized' - Pass 'SHADOWCASTER' has no vertex shader
    05:27:58 WARNING: Shader Unsupported: 'Nature/Afs Tree Creator Bark Optimized' - All passes removed
    05:27:58 WARNING: Shader Unsupported: 'Nature/Afs Tree Creator Bark Optimized' - Setting to default shader.
    05:27:59 The tree Conifer [TreeCreator] must use the Nature/Soft Occlusion shader. Otherwise billboarding/lighting will not work correctly.
    05:27:59 (Filename: C:/buildslave/unity/build/Runtime/Terrain/TreeDatabase.cpp Line: 133)
    05:27:59 The tree Conifer [TreeCreator] must use the Nature/Soft Occlusion shader. Otherwise billboarding/lighting will not work correctly.
    05:27:59 (Filename: C:/buildslave/unity/build/Runtime/Terrain/TreeDatabase.cpp Line: 133)
    05:27:59 WARNING: Shader Unsupported: 'Nature/Afs Tree Creator Bark Deferred Optimized' - Pass 'FORWARD' has no vertex shader
    05:27:59 WARNING: Shader Unsupported: 'Nature/Afs Tree Creator Bark Deferred Optimized' - Pass 'FORWARD' has no vertex shader
    05:27:59 WARNING: Shader Unsupported: 'Nature/Afs Tree Creator Bark Deferred Optimized' - Pass 'PREPASS' has no vertex shader
    05:27:59 WARNING: Shader Unsupported: 'Nature/Afs Tree Creator Bark Deferred Optimized' - Pass 'PREPASS' has no vertex shader
    05:27:59 WARNING: Shader Unsupported: 'Nature/Afs Tree Creator Bark Deferred Optimized' - Pass 'DEFERRED' has no vertex shader
    05:27:59 WARNING: Shader Unsupported: 'Nature/Afs Tree Creator Bark Deferred Optimized' - Pass 'SHADOWCASTER' has no vertex shader
    05:27:59 WARNING: Shader Unsupported: 'Nature/Afs Tree Creator Bark Deferred Optimized' - All passes removed
    05:27:59 WARNING: Shader Unsupported: 'Nature/Afs Tree Creator Bark Deferred Optimized' - Setting to default shader.
    05:27:59 The tree Conifer [TreeCreator] deferred bark must use the Nature/Soft Occlusion shader. Otherwise billboarding/lighting will not work correctly.
    05:27:59 (Filename: C:/buildslave/unity/build/Runtime/Terrain/TreeDatabase.cpp Line: 133)
    05:27:59 The tree Conifer [TreeCreator] deferred bark must use the Nature/Soft Occlusion shader. Otherwise billboarding/lighting will not work correctly.
    05:27:59 (Filename: C:/buildslave/unity/build/Runtime/Terrain/TreeDatabase.cpp Line: 133)
     
  30. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    as written before: those shaders are surface shaders which means that unity’s shader compiler should automatically take care of anything needed to make it compile for ps4.
    what makes me being surprised is:
    05:27:59 WARNING: Shader Unsupported: 'Nature/Afs Tree Creator Bark Deferred Optimized' - Pass 'FORWARD' has no vertex shader
    this shader is deferred only – so there is no Pass 'FORWARD' at all!

    which version of afs do you use? which version of unity?
     
  31. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,315
  32. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    strange. the converted trees should bend just like the original ones.
    you may go back to the original trees and reduce "edge turbolence".
     
  33. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    The unity guys told me what the fix was.

    The problem appears to be in AfsBuildin3xTreeLibrary.cginc

    at line 103

    Code (csharp):
    1.  
    2. float3 projectedVertex = pos.xyz - (dot(planeNormal, pos) + _SquashPlaneNormal.w) * planeNormal + _AfsBillboardCameraForward.xyz * halfPI * pos.y;
    3.  
    the call to dot() is ambiguous ... it has a float3 and a float4 as a parameter. The PS4 shader is quite particular about things like that.

    I assume the correct line should read:

    Code (csharp):
    1.  
    2. float3 projectedVertex = pos.xyz - (dot(planeNormal, pos.xyz) + _SquashPlaneNormal.w) * planeNormal + _AfsBillboardCameraForward.xyz * halfPI * pos.y;
    3.  
    After correcting that line all shaders build successfully and (at least) the first 3 sample scenes in your project build, run, and render on the PS4.
     
    hopeful likes this.
  34. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    thanks a lot for that finding!
    i have added that to the package and committed it.
    the original version compiled fine on all platforms i have access to but ps4 seems to be quite picky...
     
  35. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    I'm having a bit of trouble using the simple tree shader. The roots on my plant as well as the yellow flower are showing up black. It only happens on certain objects and they render properly using the standard shader. Any idea on what's happening?

     
  36. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    you haven’t assigned the combined normal/translucency/smoothness texture.
    try to add it and see if it already fixes your problem.
     
  37. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    Sorry about that last one it turned out to be an issue with the model history in max.
     
  38. Loishtc

    Loishtc

    Joined:
    Oct 19, 2013
    Posts:
    32
    How do i get rid of white billboard borders at night? (im with a day night cycle).
    I used tree creator engine trees and i want to know how to get rid of this problem.
    I see something like rewrite the billboard shader, but AFS its supposed to work well with this, or not?
     
  39. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    bright borders around billboards most likely are caused by the background color (medium gray) leaking into the texture. that background color is set by unity internally so not much you can do about it.
     
  40. ZenMicro

    ZenMicro

    Joined:
    Aug 9, 2015
    Posts:
    206
    Hi Lars,

    I have a question, i know the trees i am using are ridiculously high poly, but in any case i'm keen on this shader, my question is as i am placing the trees through TerrainComposer as Objects (because they don't show up as trees) can this script work with objects as well for the billboarding? like my trees or rocks for example? I know normally object would have a LOD and i'm not sure if Unity does any billboarding for objects but with the trees it really appears not as i can see them glistening in the distance.. no billboarding there at the moment.
     
  41. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    objects will not billboarding. only trees added to the terrain do.
     
  42. ZenMicro

    ZenMicro

    Joined:
    Aug 9, 2015
    Posts:
    206
    OK fair enough, so your shader works only with Unity trees?, which I think i can't get my trees to that requirement.

    BTW i can't seem to access the demo from the links on the asset store, (dropbox) ERR_CONNECTION_TIMED_OUT

    Your touch bend trees... they are placed as arbitrary meshes correct? so do they not billboard either?

    I can't help but ask, and you would obviously be the best person to answer this as it is your asset...

    How hard would it be to rework this asset to allow for trees as object (they are already using the Unity Tree creator shaders for bark and leaves) to work?

    I mean the tree is loaded into Unity , in game shaded etc.. just there is not billboarding... is this something you would consider looking into, or do you think if i grab a copy it could be modified too support the trees as they are - custom meshes? (im not to concerned about anything but supporting billboards as in you demo.. and maybe the bendy stuff for smaller shrubs and trees)

    It's not a problem that is going to go away for me.. i have these trees and i have to be able to get a billboard working, your asset looks like it is the best base for this. you thoughts?
     
    Last edited: Oct 26, 2015
  43. DivergenceOnline

    DivergenceOnline

    Joined:
    Apr 19, 2015
    Posts:
    244
    How do you get AFS 4 Tree Billboards to play nice with Time of Day scattering? (In laymans, non-programmer speak please)
     
  44. Morfeuskiev

    Morfeuskiev

    Joined:
    Oct 10, 2013
    Posts:
    122
    @larsbertram1

    Hi .... how i can add support FOG on Unity Billboards as post effect, not Unity fog? I create my game with Unity Atmospheric Scattering, but it does not have affect on billboards.

    With Best Regards, Leonid.
     
  45. Precizion

    Precizion

    Joined:
    Nov 19, 2012
    Posts:
    8
    Anyone know how to fix this issue with the grass giving off a stripe pattern?



    That's using just a grass texture, rather than a mesh.

    Also seem to be having problems getting detail meshes using vertex to blow in the wind. I've tried the base meshes and ones converted using the foliage tool, but neither seem to work. Doesn't seem to work right in the demos either with the nettles, just the very edge of a leaf fluttering in a weird way. Anything I'm missing?

    Is there a way to get the ATS v2 pack working with this one? I had the grass and terrain details set up great on that, but don't want to give up on the tree shaders in this. Tried it myself by deleting the relevant grass and details shaders from AFS, but there seems to be some other stuff causing it to not work right.
     
  46. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    I had the exact same problem, and I fixed it by doing the following:
    - I opened a new scene
    - I deleted the AFS asset folder in the project view
    - I reimported the latest AFS
     
  47. Precizion

    Precizion

    Joined:
    Nov 19, 2012
    Posts:
    8
    Unfortunately, that hasn't seemed to have fixed anything for me.
     
  48. Morfeuskiev

    Morfeuskiev

    Joined:
    Oct 10, 2013
    Posts:
    122
    @Precizion

    When you using AFS shader you must ADD to scene empty GO with script "Setup foliage.... " from AFS folder. Color of stripe pattern you can edit in terrain settings (beside grass wind settings)
     
    hopeful likes this.
  49. Precizion

    Precizion

    Joined:
    Nov 19, 2012
    Posts:
    8
    Editing the color in the terrain settings fixed the grass striping. Thanks.

    Already have an AFS object setup in the scene. All the manually placed placed objects work fine with it, it's just the vertex lit terrain detail items that don't seem to be reacting properly.
     
    hopeful likes this.
  50. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    What are the Rain Settings for? I don't see it described in the documentation at all and it doesn't seem to do anything when I turn Rain Amount to maximum.