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
    hi there,
    you have to switch the inspector to the debug mode (placed in top-right corner of inspector) to get the needed input.

    i am not sure what you mean: the folder "prefabs" in "demos" --> "00 shared assets" contains 3 prefabs which use the grass shader – and oll of them work properly for me.

    me too. but the best settings depend on a lot of different parameters. could you be a bit more specific about this?
     
  2. swredcam

    swredcam

    Joined:
    Apr 16, 2017
    Posts:
    130
    I installed v4 and then v5 almost immediately after. I can't seem to get any movement. Testing with included prefabs and also Underwater Plants from Yughues. Neither work. I notice the AFS Setup in the Inspector gives a message "The associated script can not be loaded. Please fix any compile....". Any idea what the problem might be?

    Also the Quickstart on google docs mentions "edit-->project settings--> graphics" for linear color space, however it is actually "edit-->project settings-->Player" that has the color space setting.

    Thank you!
     
  3. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    the console should give you more information about what has gone wrong.
     
  4. swredcam

    swredcam

    Joined:
    Apr 16, 2017
    Posts:
    130
  5. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
  6. swredcam

    swredcam

    Joined:
    Apr 16, 2017
    Posts:
    130
    OK so back to "the associated script cannot be loaded". Is it possible that installing v4 and then the v5 upgrade caused some issue? Perhaps a naming difference in the scripts? I'm just following the quick start. I think the "cannot load" message is an error rather than a warning, right?
     
  7. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    i am not sure about that.
    i don't think so.

    but in case you do not get any errors but only warnings i guess that unity simply can't find the script (IDs have changed).
    so you should try to assign it manually:
    - find the "SetupAfs.cs" in your project tab (located in "Advanced Foliage Shaders v5" -> "Scripts" -> "Setup AFS".
    - then drag it manually into the "empty" script slot of the "- - AFS Setup" prefab.
     
  8. JonasPersson

    JonasPersson

    Joined:
    Aug 14, 2016
    Posts:
    65
    Hi!

    I cant get the combined "Normal/Smooth/Translusency map" to work. There is no normal mapping happening. The normals goes totally flat. But the translucency map seem to work.

    Exectly how should the importer be set for this to work.

    If i turn it into a normalmap in the importer, the normalmapping works, but not the translucency.

    I tried lots of different import settings and the channels are placed correctly, just as the documentation.
     
  9. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    you need to disable sRGB processing by:
    - unity 5.4:
    - - set "Texture Type" to "Advanced"
    - - check "Bypass sRGB Sampling"
    - unity >= 5.5:
    - - set "Texture Type" to "Default"
    - - uncheck "sRGB(Color Texture)"

    you may choose "Filter Mode" = "Trilinear"

    that is all.
     
  10. swredcam

    swredcam

    Joined:
    Apr 16, 2017
    Posts:
    130
    Before getting your last suggestion I deleted both v4 and v5, and then installed v5. It works now. When I did the v5 "upgrade" step, very few files seemed to install. Maybe the v5 clean install is a better approach. Thank you!
     
  11. JonasPersson

    JonasPersson

    Joined:
    Aug 14, 2016
    Posts:
    65
    About my issue with the Translucency/Normal/Smoothness texture.

    It was the fileformat that was wrong.

    I got strange results with .TGA And for obvious alpha reasons .PNG

    The best way seems to be to use .PSD to get the channels out correctly
     
  12. JonasPersson

    JonasPersson

    Joined:
    Aug 14, 2016
    Posts:
    65
    Hi! I have a small feature request

    I would really love to have the possibility to set the viewing angle for the translucency effect.
    Now you have to almost look straight against a light to get the effect. I would like to see the effect from a much steeper viewing angle.

    This would be super nice

    Thanks for a great asset! :)
     
  13. swredcam

    swredcam

    Joined:
    Apr 16, 2017
    Posts:
    130
    The underwater plants from Yughues look great, however I have an issue where when I am viewing from a distance the plants "double" and start moving much more violently. It's a very discrete jump from normal movement to extreme. I think it may be LOD related. Can you comment on this? The image below shows the same plant from three distances in the game. Also, are plants like this foliage or trees? Thank you!
     
  14. JonasPersson

    JonasPersson

    Joined:
    Aug 14, 2016
    Posts:
    65
    And another suggestion.

    It would be great to have a occlution texture (Mostly for the specularity)
    Maybe Instead of having Smoothness as a parameter in the Normal/Translucency/Smoothness Texture, since the smoothness parameter often is the same all over the leaf.
     
  15. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    well, tga should just be fine as it ensures that there i snot any color management applied to it.
    psd add some magical stuff even to the alpha channel. but it is quite handy (adjustment layers), so i use it most of the time.
     
  16. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    that may come in further updates.
    it's already in (and used by the grass shaders) but not added to the foliage shaders :)
     
  17. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    i am not familiar with that asset.
    does it come with different LOD meshes? then you have to use the foliage shader and use the foliage tool to set up bending. make sure you assign LOD0 as blueprint when setting up LOD1 and LOD2 as the different meshes might have different bounds which would affect the calculated bending.
    but your "very far" looks as if it was double sided geometry with normals pointing in opposite directions.
    make it single sided and the ghost should simply go.
     
  18. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    here i do not follow you... whenever you read an article about physically based shading you will notice that smoothness is described as the most important texture.
    occlusion would be nice but does not fit into the 2 textures. and afs comes with horizon based occlusion – so at least "wrong" reflections are muted.
     
  19. JonasPersson

    JonasPersson

    Joined:
    Aug 14, 2016
    Posts:
    65
    Well which map is most important for of the material is of course determined by where the material should be used. In the case of leaves you could in 90% of all cases get away with the same smoothness over the entire surface. (in 100% of all my cases)

    Although if you use the material for an entire tree with trunk and bark smoothness is important.

    The AO would be very useful for canceling out reflections that are not accurate. Since you usually dont have a reflectionprobe in every tree you usually see sky reflecting even where it should be occluded.
     

    Attached Files:

  20. JonasPersson

    JonasPersson

    Joined:
    Aug 14, 2016
    Posts:
    65
    Yeaa!

    Make it soon:), Make a downloadable patch shader! for me, haha

    Then i could make ferns this butiful:
     
  21. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    not really... the most important texture is defined by the lighting function or brdf. and here smoothness definitely wins :)
    your screen shoot shows direct? specular reflections even on shaded pixels. so i assume that you have lowered shadow intensity to something < 1.0.
    if so: you must never ever do this! shadows have to cancel specular highlights. for this reason they have to have a strength of 1.0!
    if these reflections however are ambient reflections you may get rid of them by baking large scale occlusion into vertex color alpha.

    just find out which kind of reflections you have there set the "intensity" of the "environment reflections" to 0.0 in the lighting tab. if these reflections still remain please check your shadow strength.

    you do not have to wait for me.
    just edit the "Afs_Internal-DeferredShading.shader" file and find:
    transDot = exp2(saturate(transDot) * 8 - 8);
    setting this to e.g.
    transDot = exp2(saturate(transDot) * 4 - 4);
    will give you a much wider spread of the translucent lighting.
     
  22. FloBeber

    FloBeber

    Joined:
    Jun 9, 2015
    Posts:
    166
    Does anybody know how to fix that issue without having to disable anti aliasing in Quality Settings or use Post Processing Effect (which doesn't seem to work in VR)?
     

    Attached Files:

  23. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    it looks like a mip mapping issue: something from your albedo/ smoothness whatsoever texture spills at grazing angles.
    the only way to reduce artifacts in this case wold be to reduce the size the leaves take in uv space – leading to less resolution on leaves :(
     
  24. FloBeber

    FloBeber

    Joined:
    Jun 9, 2015
    Posts:
    166
    Thanks for the fast reply.

    The issue seems to be only on barks. I just tried to downsize the bark texture from 1024 to 256 and didn't notice any change. I've also tried many different trees, from different sources, and they all have the same issue.

    (that problem only appears with Forward rendering)
     
  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    downsizing the original texture of course does not help as unity's tree creator creates a combined texture atlas for each tree:

    left image: that how a texture altas usually looks like: bark in on left, leaves on the right.
    right image: in order to minimize spill on lower mips you would have to maximise the gap between bark and leave texture which only can be done by adding leaf planes as manually modeled geometry – and not the built in quads. your leaf models should not cover the whole uv space but only a range of e.g.: 0.3 < u < 0.7 (v is not important here).
    texatlas.jpg
    but as our problem only appears in forward it might be caused by msaa.
    so try to disable msaa to see if this would fix it – which of course might not be an option.
     
  26. JonasPersson

    JonasPersson

    Joined:
    Aug 14, 2016
    Posts:
    65
    Hi!

    "if these reflections however are ambient reflections you may get rid of them by baking large scale occlusion into vertex color alpha."

    Yes these are ambient reflections.
    I should have tried the vertex occlution before suggesting a texture. Its great if it also occludes ambient reflections. Just have to find out a way to bake just the alpha without ruining the rest of the colors.

    It is says in the documentation "Legacy bending will be skipped in the next updates.", So i guess i have to go with UV4 sollution to get AO, and stay up to date. I will try it out and see if i get it to work.

    "you do not have to wait for me.
    just edit the "Afs_Internal-DeferredShading.shader" file and find:
    transDot = exp2(saturate(transDot) * 8 - 8);
    setting this to e.g.
    transDot = exp2(saturate(transDot) * 4 - 4);
    will give you a much wider spread of the translucent lighting."

    Great! Thank you!
    Since im not a shader programmer i wouldnt have found it myself :)

    Thanks for the quick response.
     
  27. FloBeber

    FloBeber

    Joined:
    Jun 9, 2015
    Posts:
    166
    Maybe my first message was not clear enough, but turning off MSAA does fix the issue. But I obviously need MSAA (and I couldn't find any good alternative option for VR).

    Also, the trees I'm using don't have Atlas. Leafs and barks use their own material.

    Would upgrading from AFS 4 to AFS 5 help? Is there any changelog available somewhere?

    Thanks!
     
  28. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    you are welcome!
     
  29. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    sorry, i overlooked that...
    it not a pronblem of trees nor is it a problem of afs: it is a problem of unity and msaa.
    for example: screen spaced shadow maps do not use msaa.
    but nevertheless using afs 5 might help as it does fully physically based shading on the bark – and therefore might kill the specular highlights (if the artifacts are any) at grazing angles (although pbs usually is know for adding these -> fresnel). at least today i have looked at my afs 5 demo scene using forward and 8x msaa and have not been able to find any artifacts.
    you will find the documentation here:
    https://docs.google.com/document/d/164MTEnV_-krBdMr-20QhPttY1bY5H46FtpSDM1UQdRk/edit
     
  30. JonasPersson

    JonasPersson

    Joined:
    Aug 14, 2016
    Posts:
    65
    Hi!

    i tried the

    "you do not have to wait for me.
    just edit the "Afs_Internal-DeferredShading.shader" file and find:
    transDot = exp2(saturate(transDot) * 8 - 8);
    setting this to e.g.
    transDot = exp2(saturate(transDot) * 4 - 4);
    will give you a much wider spread of the translucent lighting."

    But nothing happends is there something else i need to do?
    I changed the values to 1 and up to 1000 but i could see no difference.
    Im sure its the right file.
     
  31. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    you have to set your camera to deferred of course – und assign that shader.
     
  32. nciofi

    nciofi

    Joined:
    Nov 3, 2014
    Posts:
    8
    Hi!

    The shaders works on custom 3d models ?! I really like to model my own trees, bushes and flowers instead of using any tree generator. My custom models can have the touch bending, winding and all those nice features?!

    Thanks!!
     
  33. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    yes, they do.
    you can do bushes and flowers and add bending information by painting vertex colors using your 3d app.
    you can also use this technique on simple trees.
    for really complex tress however i recommend my custom tree importer from the asset store.
    touch bending is only supported by the foliage shader.
     
  34. JonasPersson

    JonasPersson

    Joined:
    Aug 14, 2016
    Posts:
    65
    To bad im using forward rendering in my game. Is there any way to fix it in forward or does it only work in defferred?
     
  35. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    then you will have to edit the "AfsPBSLighting.cginc", find and edit the same line and finally recompile all shaders.
     
  36. JonasPersson

    JonasPersson

    Joined:
    Aug 14, 2016
    Posts:
    65
    Now it works!
    Thank you! It was the "recompile all shaders" part that i got wrong.
     
  37. MaxWitsch

    MaxWitsch

    Joined:
    Jul 6, 2015
    Posts:
    114
    Hi,
    I just implemented the foliage shader to my project.
    IMG-20170527-WA0012.jpg
    IMG-20170527-WA0011.jpg
    IMG-20170526-WA0016.jpg

    Performance is quite nice :D
     
  38. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    you are welcome!
     
  39. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    the images are nice too.
    but how do you darw that vast amount of grass – which even casts shadows?!
     
  40. MaxWitsch

    MaxWitsch

    Joined:
    Jul 6, 2015
    Posts:
    114
    The shadows come frome a screen space shader. You just need the depth from the gbuffer.

    The Density of the grass is achived by using custom grass blades for terrain details and a low(1024px) res control map on the terrain.
    So that means i have choose the built in terrain workflow.
    Unfortunately i cant take advantage of touch bending. ):
     
  41. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    i see, fine.

    why not? well, touch bending enabled plants have to be placed as gos. but you might add some gos here and there.
     
  42. MaxWitsch

    MaxWitsch

    Joined:
    Jul 6, 2015
    Posts:
    114
    Jep you right. It would look Awesome :)
     
  43. Crystalline

    Crystalline

    Joined:
    Sep 11, 2013
    Posts:
    171
    Can someone help me with this ? I dont get it why it gets so much darker in game... I really cant find a solution.
     
  44. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    the grass shader has 2 different modes:
    1) in editor: in this case it assumes that the "ground" normals are not baked ans simply lits the grass according to normal = up.
    2) in playmode: here the shader expects ground normal to be baked by the combine children script which also might add dry and healthy colors.

    does that help?
     
  45. Crystalline

    Crystalline

    Joined:
    Sep 11, 2013
    Posts:
    171
    Not really. What is the workaround for this issue? What do I need to do in order to keep that same look in game?
     
  46. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    that is not an issue. normals simply have to be baked to give you correct lighting.
    additionally baking the normals allows us to also add some color variation.

    so in order to get exact the same lighting in edit and playmode you will have to statically combine the grass and check "all grass statically combined" in the afs setup script.
     
  47. Crystalline

    Crystalline

    Joined:
    Sep 11, 2013
    Posts:
    171
    If I check that, then the editor looks like the in game one; bad. Same look over both , but not the look I am interested in. :(
    Just in case : I use the grass shader on some manually fabricated grass meshes, then paint them with the AFS Brush, not on terrain.
     
  48. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    if they both look the same half the work is done :)
    now lets talk about the "look".
    - please check the sampled ground normals: they should fit the ground normals of course. otherwise lighting gets off.
    - please check the dry and healthy color in the combine children script: they might be too dark.

    in case you use deferred you may check the baked normals in the scene view.
     
  49. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    Hey @larsbertram1, just got the asset and was very impressed by the system. It's pretty easy to extend the shader and features like translucency work wonderfully. Got a couple of questions, though:

    - How can I prevent or turn off normal/tangent contribution to the wind displacement? If your leaf cards contain hard edges - for example, if you're using Y shaped 3-surface card), wind tears the vertices in the middle quite far apart. If turning it off is not supported out of the box, I'd appreciate a pointer on location and best way to change to AFS wind displacement function being called from vertex shaders. :)

    - Is there any difference between primary and secondary wind fed by .ba channels of bending vector in the vertex shader? For example, is one bigger/less turbulent than another. Or they serve no function aside from allowing you to split your meshes into areas of 2 wind intensities? Should I keep one more intense than the other? Should I overlay primary and secondary intensities at value 1 on the same vertex, or it's preferable to keep one low when another is high to avoid "doubled" wind?

    - What is the range of values you recommend using in the smoothness channel of your translucency-normal-smoothness texture?

    - How is color variation implemented? At first I thought it worked off some sort of 3d noise, but as far as I saw in the source, it's vertex color based, which makes it dependent on manually authored vertex colors, right?

    P.S.: Any timeline on SpeedTree shader? Out of curiosity, what makes SpeedTree shader different and time-consuming to implement? It should be SpeedTree developer responsibility to provide a modern PBR shader for them, of course, but it would be wonderful if we were able to lift ST assets out of stone age of bad shading. :)
     
  50. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    you will have to disable edge fluttering:
    in AfsFoliageBendingInstanced.cginc find:
    float3 bend = animParams.g * fDetailAmp * normal.xyz * sign(normal.xyz);
    and replace it with:
    float3 bend = 0;

    AfsTreeLibraryInstanced.cginc find:
    float3 bend = animParams.y * fDetailAmp * vertexnormal * sign(vertexnormal);
    and replace it with:
    float3 bend = 0;

    it is not primary and secondary wind but bending.
    so the docs for more info about these.

    depends on the plant you have...

    it is based on worldposition.

    hmm, not sure if i am ever going to touch the speedtree shaders. speedtree models have such weird normals that pbs lighting most likely looks pretty strange. so you would have to edit the tree in speedtree modeler first.