Search Unity

Advanced foliage shader [released]

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

  1. devstudent14

    devstudent14

    Joined:
    Feb 18, 2014
    Posts:
    133
    That's a relief :) Which shader in particular? I attached the Foliage Shader v4 and turned the leaf turbulence up to 1 and it's not moving.
     
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    well, you have to set up the vertex colors. either using your 3d app or the foliage tool.
    and you have to add the afs setup script to your scene. please refer to the docs.
     
  3. devstudent14

    devstudent14

    Joined:
    Feb 18, 2014
    Posts:
    133
    Will do. On that note, the only document I can find is the AFS model and texture guide. In the guide it refers to grass shader documentation but I can't find it. Which folder is it in?
     
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    all the .rtf docs on the first level.
     
    devstudent14 likes this.
  5. devstudent14

    devstudent14

    Joined:
    Feb 18, 2014
    Posts:
    133
    Thanks for helping out (especially as my questions were quite stupid -good support review for you!). Just a quick note on the docs. I don't know what version of word you are using, but the last word on most sentences is cut-off in word 365. It can fixed by messing around with the margins, but I thought you'd like to know.
     
  6. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    it is textedit – not word…
     
  7. devstudent14

    devstudent14

    Joined:
    Feb 18, 2014
    Posts:
    133
    never heard of textedit before. they open as word documents on my system. i'll have to install textedit. thanks for the heads up.
     
  8. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    that is an os x system program…
     
  9. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    and you may try to open the rtf NOT using the "print layout" BUT "draft" view.
     
  10. Futurerobot

    Futurerobot

    Joined:
    Jul 13, 2011
    Posts:
    179
    Just bought and experimenting with this package for an underwater scene. It's looking sweet!

    There's one thing I'm trying to do though, and getting a bit lost. Since it's underwater, I want the windmotion to be much slower than the settings currently seem to allow. I've let the Wind Frequency slider go to 0.00001. I've tried multiplying in floats here and there to affect the speed, but no luck. Any tips on where I could add a variable that would slow the windmotion down?
     
  11. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i guess you will have to edit the shaders...

    open "AfsFoliageBending.cginc" and find line:
    float4 vWaves = (frac( vWavesIn.xxyy * float4(1.975, 0.793, lerp(float2(0.375, 0.193), _AfsTimeFrequency.zw, _LeafTurbulence )) ) * 2.0 - 1.0);

    here you will have to change these numbers: 1.975, 0.793, 0.375, 0.193
    to e.g. 1.975 * 10, 0.793 * 10, 0.375 * 10, 0.193 * 10

    then recompile/reimport all shaders
     
    hopeful likes this.
  12. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    389
    Can this be used with speedtree in deferred linear mode (for the leaves)? Currently Unity is broken in that aspect.

    Thanks,
     
  13. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    speedtrees are speedtrees, sorry.
    i might consider adding a speed tree shader to lux though.
     
  14. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    389
  15. docsavage

    docsavage

    Joined:
    Jun 20, 2014
    Posts:
    1,021
    If you could get that speedtree problem with liner deferred working with AFS as soon as people find out you would be onto a winner:)
     
  16. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    389
    I'll bow down to you lars if you do that... In fact, you should actually release it as a separate shader - you may get more sales, because it's such an important item, and worth its weight in gold.
     
  17. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    speedtree issues are on my radar – but they get fixed simply using (the free) lux deferred lighting shaders:

    lux_speedtree.jpg
     
    radimoto, hopeful and Martin_H like this.
  18. docsavage

    docsavage

    Joined:
    Jun 20, 2014
    Posts:
    1,021
    Hero :) Apparently unity and speedtree have been working on this a while. I am going to mention this in the speedtree thread.
     
    Martin_H likes this.
  19. fromium

    fromium

    Joined:
    Jun 7, 2013
    Posts:
    7
    I'm trying to use the grass shader with nature pack grass assets. All of the grass is being rendered black when the scene plays. It's a pain to go through and try to rename all of the assets with _AFSxxx plus many of the assets have submeshes. Is there a way to tweak the script to get the grass shader to work without these things?

    Thanks!
     
  20. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    just have a look at the script and tweak it to your needs.
    but submeshes are not a good idea as far as grass is concerned. it is also not a good idea to use a vast amount of different grass prototypes as either you will have to create a huge texture atlas or each prototype will cause a draw call.
    please check if the combine children script is assigned and works properly.
     
  21. tombombadil1988

    tombombadil1988

    Joined:
    Feb 21, 2015
    Posts:
    20
    I'm using your shader on a mobile low poly project to bend trees with no leaves. From my understanding your shader uses UV colors for bending and Vertex for the leaves. I would like to use Vertex colors for Ambient Occlusion as I don't need the leaves to move, just the bending.

    Can you give me a hint what to disable in the AfsFoliageShader or AfsFoliageBending.cginc so there is only bending happening?
     
  22. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    you may simply store ambient occlusion in vertex color alpha without touching the shaders.
     
  23. tombombadil1988

    tombombadil1988

    Joined:
    Feb 21, 2015
    Posts:
    20
    That would be great but I'm using the VertexDirt Plugin from the Asset Store to calculate the AO - no option there to save to alpha.
     
  24. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    well, then it might be easier to change the vertex dirt script to write to alpha…
    otherwise you will loose branch phase (stored in red) so all branches will sway in the exact same phase.

    in case you prefer to edit the shaders you will have to edit each foliage shader you want to use and look for:
    float4 bendingCoords;
    bendingCoords.rg = v.color.rg;

    you might replace it by:
    bendingCoords.rg = float2(0,0);

    then make sure you use "vertex colors and uv2" as bending input for the material
     
  25. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    389
    Lars is a god... the deferred linear speedtree problem has been fixed:

    A quick example:

    The directional light intensity is set to 5, and as you can see you get a beautiful green and some dark spots.
     
  26. fromium

    fromium

    Joined:
    Jun 7, 2013
    Posts:
    7
    Thanks. As far as tweaking the script, I would not know how to go about it. Also, I'm getting this error with the combine children script: "Mesh.tangents is out of bounds. The supplied array needs to be the same size as the Mesh.vertices array." I guess I was looking for help in how I might tweak it. Is there a way to look and see if there is a sub mesh and then just merge it into one if it has the grass shader applied?
     
    Last edited: Jun 22, 2016
  27. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    there certainly is. but having sub meshes usually means that you use 2 different materials on the mesh. which one wins? when should it be merged?
    and as you still will have to atlas the textures you will have to edit the models in your 3d app anyway. there it should be easy to merge materials.
     
  28. tombombadil1988

    tombombadil1988

    Joined:
    Feb 21, 2015
    Posts:
    20
    Thanks Lars, that did the trick.

     
  29. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    fine!
     
  30. Avonaeon

    Avonaeon

    Joined:
    Apr 17, 2012
    Posts:
    48
    Hey Lars,

    I'm using 5.3.5, DX11 in Deferred, with AFS 4.0.3 and in the editor, I have all the trees looking fine with Tonemapping on. However, in a build the trees show up with white highlights when tonemapping is on, and with black splotches when tonemapping is turned off.

    Am I missing something somewhere, that would cause this discrepancy?
     
  31. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hmm, sounds as if some shaders might not get into the built.
    you may try adding them manually: Project settings -> graphics -> Always included shaders.
    do yo have some screen shoots?
     
  32. Avonaeon

    Avonaeon

    Joined:
    Apr 17, 2012
    Posts:
    48
    I'm gonna try adding the AFS Tree Creator Bark Deferred Optimized and AFS Tree Creator Leaves Optimized to the Always Included shaders list. I suppose those are the ones to be added? Or are there others?

    Also, here's an album with the same tree in editor and build. http://imgur.com/a/svlzw
     
  33. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi there,
    that looks pretty strange.
    which version of unity do you use? and what tonemapper? old one, the one from the cinematic effects? which settings?
    i just did a quick test using the default demo scene, setting all trees to use the deferred bark shader, dx11 and the old tonemapper (hable): everything looks fine for me…
     
  34. Avonaeon

    Avonaeon

    Joined:
    Apr 17, 2012
    Posts:
    48
    I'm using Unity 5.3.5 and Scion Tonemapping, but Ihad the same problems with Unity's (Plus a lot of other issues) so I switched. With Scion I'm using Filmic with a white point of 3 (If that's any help at all).
     
  35. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hmm, i just ran out a built using unity 5.3.5. and scion 1.4. looks fine on windows 10, nvidia gtx 970m.
    what gpu do you have?
     
  36. Avonaeon

    Avonaeon

    Joined:
    Apr 17, 2012
    Posts:
    48
    The problem persist on a variety of GPUs. I've tried on GTX970, GTS 450, Radeon HD 6900 and it looks the same on all those.

    My import settings on the textures look like this: http://i.imgur.com/dOemo3b.png
     
  37. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    why do you import a diffuse texture bypassing srgb sampling?
    combined normal spec textures should, albedo never.

    but that should not be related to your problem. to be honest: i don't have any idea what is going wrong for you – as it just works fine for me.
    so i would suggest you create a new project and only import afs and scion.
    then open the "Foliage Shader Overview Demoscene", remove the first conifer prefab (which uses forward rendering bark) from the terrain and add some more trees using the 2nd prefab (deferred bark).
    add scion to the camera and do a test built.
     
  38. Avonaeon

    Avonaeon

    Joined:
    Apr 17, 2012
    Posts:
    48
    Bypassing srgb for the albedo is due to a bug in Unity, where trees built with the tree creator end up with albedo textures much darker than the source material. Checking that fixes the problem.

    I'm going to be indisposed for the next two weeks, but I will try the test build after that and let you know. Thanks for all the help so far, though :)
     
  39. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    sorry that i could not fix your problem so far…
     
  40. wilksy92

    wilksy92

    Joined:
    Jan 18, 2014
    Posts:
    2
    Hi Lars.
    I just purchased this and am wondering if i could get a copy that is compatible with Unity 4.7? The game im working on is still using unity 4 due to tech issued with the lighting systems in unity 5 and our lighting mechanics we are using for game play.

    We are not using Unitys terrain system.The main features im after is touch blending and the procedural wind for both grass and trees. We are rendering in deferred.

    Thanks heaps
     
  41. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i hope i will find an old version somewhere. but i would need your invoice number first.
    please send it to larsbertram69@gmail.com
     
  42. wilksy92

    wilksy92

    Joined:
    Jan 18, 2014
    Posts:
    2
    Thanks heaps, Email sent.
     
  43. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i did not receive any...
     
  44. docsavage

    docsavage

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

    Dannyoakes of speedtree mentions lux as a current workaround for speedtrees until unity do an official fix -
    http://forum.unity3d.com/threads/hi-i-work-at-speedtree.298762/page-3

    My dealing with them was they are a good company. They were very helpful and went out of there way when I contacted them about something.

    Glad they gave you credit for lux being usable here. AFS and Lux are good products that deserve a mention.
     
  45. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    thanks!
     
    docsavage likes this.
  46. KarloE

    KarloE

    Joined:
    Aug 26, 2013
    Posts:
    175
    Is there a way to make tree bilboards cast realtime shadows?
     
  47. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    currently: no. but i will work on bringing back that feature.
     
    docsavage and hopeful like this.
  48. KarloE

    KarloE

    Joined:
    Aug 26, 2013
    Posts:
    175
    Ok cool, thanks for the quick reply. :)
     
  49. artistpetemac

    artistpetemac

    Joined:
    Sep 8, 2014
    Posts:
    19
    Apologies for dropping this question and then buggering off. It was deadline time. I just wanted to fill you in on what we discovered: It turns out it wasn't a PS4-only bug, it was a build-only bug. We just happened to test the PS4 build first. Turns out that Unity was stripping out the vertex colors (maybe just alpha) of those meshes during the build because the shader assigned to them wasn't making use of them. We changed the shader and that fixed it. Cheers!
    -Pete
     
  50. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i had a look into that and brought back basic support for billboards casting shadows to unity 5.
    but unfortunately it turned out to be a) quite complex and b) even if you take all the burden the results still are somehow messed as unity 5 does not let you render different meshes for shadow casters, shadow receivers and the depth buffer (which now equals shadow receivers which of course makes sense).
    this means that we can't have nice transitions between billboards and mesh trees or can't have nice transitions between shadows casted by billboards and shadows casted by mesh trees.
    so instead i will have a look into fading in shadows casted by mesh trees in order to improve the transition.

    lars
     
    hopeful likes this.