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,901
    as always: texture import settings... ;-)
    i am glad you fixed your problem,

    lars
     
  2. konsnos

    konsnos

    Joined:
    Feb 13, 2012
    Posts:
    121
    Hello, I've just moved from Unity 4.5.1 to 4.6b18. I got some weird errors like

    Code (CSharp):
    1.  
    2.  
    3. Shader error in 'Hidden/TerrainEngine/Details/WavingDoublePass': Can't open include file "../Includes/afsWavingGrass.cginc" at line 27
    4. Shader error in 'Hidden/TerrainEngine/Details/WavingDoublePass': Can't open include file "../Includes/Afs_AmbientLighting.cginc" at line 72
    5. Shader error in 'Transparent/Cutout/AFS_v3/Advanced Foliage Shader IBL': Can't open include file "Includes/Afs_DirectLighting.cginc" at line 83
    6. Shader error in 'Transparent/Cutout/AFS_v3/Advanced Foliage Shader IBL': Can't open include file "Includes/CustomBending.cginc" at line 84
    7. Shader error in 'Transparent/Cutout/AFS_v3/Advanced Foliage Shader IBL': Can't open include file "Includes/Afs_CustomFog.cginc" at line 97
    8. Shader error in 'Transparent/Cutout/AFS_v3/Advanced Foliage Shader IBL': syntax error, unexpected identifier at token "LeafSurfaceOutput" type name expected at token "LeafSurfaceOutput" at line 120
    9. Shader error in 'Transparent/Cutout/AFS_v3/Advanced Foliage Shader IBL': Can't open include file "Includes/Afs_AmbientLighting.cginc" at line 156
    10. Shader error in 'Transparent/Cutout/AFS_v3/Advanced Foliage Shader IBL': Can't open include file "Includes/Tree.cginc" at line 239
    11. Shader error in 'Transparent/Cutout/AFS_v3/Advanced Foliage Shader IBL': Can't open include file "Includes/CustomBending.cginc" at line 240
    12. Shader error in 'Transparent/Cutout/AFS_v3/Advanced Foliage Shader IBL': syntax error, unexpected ';' at token ";" type name expected at token ";" at line 268
    13. Shader error in 'Transparent/Cutout/AFS_v3/Advanced Foliage Shader IBL': too many parameters in function call at line 276
    14. Shader error in 'Hidden/TerrainEngine/BillboardTree': Can't open include file "../Includes/Afs_BillboardShadow.cginc" at line 122
    15.  
    16.  
    I've tried to go back, but shaders still show the pink error color. Is there something that I missed?

    Edit: Found the fix from here. Tricky :-S
     
    Last edited: Sep 17, 2014
  3. DanialFrost

    DanialFrost

    Joined:
    Nov 23, 2013
    Posts:
    5
    Shaded Billboards is not working for me. When I attached the script to the terrain, it shows
    I did attach the light reference to the script. What am I missing ?
     
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    Hi there, some more info would be Fine... E.g.: Line number, Screenshots...
     
  5. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    Crazy, but it is still unity 4.6 Beta...
     
  6. DanialFrost

    DanialFrost

    Joined:
    Nov 23, 2013
    Posts:
    5
    I don't remember what I did last night, I opened Unity this morning just now and it's fixed. Looks like my self unconscious mind fixed the problem. :D
     
  7. bakno

    bakno

    Joined:
    Mar 18, 2007
    Posts:
    604
    We are trying to add dense grass to a custom mesh terrain (not Unity's). After trying your V2 shaders we decided to purchase the V3.

    Does the Grass Shader provide a "Detail Distance" similar to regular grass on Unity's terrain? I mean, there is a distance to the camera that activates/deactivates the actual grass. When the camera is far away, we prefer not to render the grass in a similar way.
     
    Last edited: Sep 23, 2014
  8. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    hi there,
    the grass shader supports fading out over distance.
    so together with the built in "layer culling" you easily achieve grass like that in the terrain engine.
    but how would you like to render grass far away from camera?
    why do you want to render it at all?
    lars
     
  9. bakno

    bakno

    Joined:
    Mar 18, 2007
    Posts:
    604
    Hi Lars

    What we want is to NOT render grass away from the camera. Thank you for the advice.
     
  10. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    sorry, but i do not get you...
     
  11. bakno

    bakno

    Joined:
    Mar 18, 2007
    Posts:
    604
    Hi Lars

    Is it possible to get the bending effect on grass using the WavingDoublePass shader on manually placed objects (no terrain)?
     
  12. bakno

    bakno

    Joined:
    Mar 18, 2007
    Posts:
    604
    Or alternatively. Using the VertexLit shader. How can I edit it in order to get directional light shadows.

    Please take a look at the following scene which has the same grass rendered with both shaders:

    DoublePass
    Doublepass.png

    VertexLit
    VertexLit.png

    DoublePass looks better because it receives the shadows casted on the left portion of the mesh-terrain.

    However, DoublePass is a little bit more expensive and it does not shows the waving effect.
     
  13. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    hi there,
    in order to "get" or pick up the the "shadows" or better: lighting from the underlaying terrain you either have to use the advanced grass shader or the groundlighting shader (both need the "combine children script" to be attached to work properly).
    but for meshes like grass i would always use the grass shader of course.

    lars
     
  14. laurent-clave

    laurent-clave

    Joined:
    Jul 18, 2011
    Posts:
    280
    Hi !

    You have a idea why the billboard is blue?

     
  15. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    not really. may be fog?
    and pretty interesting that some billboards are rendered correctly and others not:
    which shaders do your trees use?

    lars
     
  16. PeaceRich

    PeaceRich

    Joined:
    Feb 20, 2014
    Posts:
    3

    When setup AFS script is active I get this wired artifact, can you help me solve it? It looks like the rendering range of the terrain is reduced.
     
  17. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Weird. Looks like those trees are using the wrong shaders.

    Incredible scene by the way.
     
  18. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    hi there,

    which terrain shader do you use?
    and try to disable fog and see what happens.

    lars
     
  19. PeaceRich

    PeaceRich

    Joined:
    Feb 20, 2014
    Posts:
    3
    Thanks for replying so fast,

    I'm quite sure I don't use any terrain shader.
    And I tired turning off fog (that is unistroms fog), with no effect.
     
  20. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    well, you definitely use one – but probably the default one ;-).
    fine. as fog is just a pain in the a...
    you may also try to switch to dx11 (as dx9 is often a bit picky – although i do not know anybody else havin gtrouble like you).
    one last thing: which layer is your terrain assigned to?
    afs enables early layer culling on layer 7 and 8 (or 8 and 9 – i am not sure right now).
    if all this does not help you could try to assign a terrain material (using the built in spec bump terrain shader – which you should use anyway).

    lars
     
  21. PeaceRich

    PeaceRich

    Joined:
    Feb 20, 2014
    Posts:
    3
    Hi again,
    Looks like I fixed it? I messed around with the layers, I just switched layers and then back? And somehow that fixed it!
    Thank you so much for your help and leading me in the right direction!
     
  22. laurent-clave

    laurent-clave

    Joined:
    Jul 18, 2011
    Posts:
    280

    The standart tree shader worl fine. But afs3 alway render billboard with blue color.
    This is not the fog :(
     
  23. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    you are welcome.
    and i am glad that you were able to fix your problem.

    lars
     
  24. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    ups,
    from what i can see on your screenshoot: you are using the "advanced foliage gs shader" on your trees, right?
    if so billboarding will NEVER work. you have to use one of the afs tree shaders as only those support billboarding.
    all "foliage" shaders are made to render only smaller plants NOT placed as trees within the terrain engine.
    you may probably easily switch to the "simple terrain tree" shader: it should pick up your already setup bending and supports billboarding. however it only supports one material (leaf) so the bark of your palm trunks will be lit much smoother (using "wrapped around diffuse" like the leaves).

    another possibility would be getting my "custom tree importer" which you could use to make your custom trees fit the needs of the built in or afs tree creator shaders ;-)
    https://www.assetstore.unity3d.com/en/#!/content/21079
    watch the latest demo to see how imported palms might look like and bend in the wind:
    https://dl.dropboxusercontent.com/u...orter_simpledemo/treeimporter_simpledemo.html

    lars
     
  25. konsnos

    konsnos

    Joined:
    Feb 13, 2012
    Posts:
    121
    Hey lars.

    Your asset creates a funny problem in my scene. My terrain is cut in chunks.

    Here is a sample screenshot



    When I deactivate the game object with the Setup Advanced Foliage Shader script, everything get's back to normal.
     
  26. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    hi there,
    a problem like this has been described a few posts back:
    the afs setup script sets early culling on some layers (if activated in the inspector).
    please check which layer your terrain is set to.

    lars
     
  27. konsnos

    konsnos

    Joined:
    Feb 13, 2012
    Posts:
    121
    Thanks!
     
  28. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    you are welcome!
     
  29. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    999
    Are your tree packages compatibility with AFS without modifying the materials/atlasing? Thanks.
     
  30. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    compatible with the "regular" afs tree shaders (not the simple one)?
    yes, they are.
     
  31. TDH_DrThirteen

    TDH_DrThirteen

    Joined:
    Jul 3, 2014
    Posts:
    42
    Hi Lars,
    great work on the shaders they look fantastic. I have a problem when I use one of the Advanced Foliage Cutout Shaders.
    It works fine when I paint my bushes with the terrain brush, but when I place them manually(drag them into the scene) they start to move very weirdly. I dont have any windzone activated so I dont what to change.
     
  32. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    hi there,
    the shader comes in different variations. depending on your settings (like using static batching) you have to choose the corresponding shader. please have a look at the docs.

    lars
     
    Last edited: Oct 22, 2014
  33. Jonn Doo

    Jonn Doo

    Joined:
    Dec 2, 2012
    Posts:
    7
    hello all together!
    The shader looks really good. I like particularly the light beam effects on the trees in our webdemo but in the project demo scene i see nothing. What seems to be the trouble?


    jonn
     
  34. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Hey Jonn Doo

    It is an image effect so for it to work in your project you have to be using Unity Pro, the sun shafts effect on the camera, and be in play mode. You will not see it in the scene view.
     
    Last edited: Oct 27, 2014
  35. Jonn Doo

    Jonn Doo

    Joined:
    Dec 2, 2012
    Posts:
    7
    Ahhh ok! Thanks baldinoboy
     
  36. WarGod100

    WarGod100

    Joined:
    Mar 25, 2013
    Posts:
    8
    Hi Lars,

    You helped us before in our hour of need...now we coming back for more help.
    We just rolled onto the new Unity 5 beta and all our AFS plants have turned pink. I am not sure if you have tried the beta yet or if you have any suggestions for things we can try?

    Cheers
    Neil
     
  37. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    Hi there,
    i would just like to give you a sneak preview on the upcoming version of afs which will be prepared for unity 5 as well as giving you some enhanced tree creator shaders, making bending much more believable.

    i have already added in shader wind variation and enhanced leaf bending but i am also working on some more enhanced features which you might utilize in case you use the custom tree importer (which is needed to bake all the additional data into the mesh – unfortunately).

    the video attached shows a manually modeled tree – imported using the custom tree importer – taking advantage of the fact that leaf plane’s pivots can be baked into the mesh (unity 5).
    but leaf planes might not only grow: they can roll or tumble.




    lars
     
    Baldinoboy likes this.
  38. Teila

    Teila

    Joined:
    Jan 13, 2013
    Posts:
    6,932
    Wow! Amazing video!!! Thanks for sharing.
     
  39. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    hi teila,
    thanks a lot. but it is just a test if i can reconstruct the pivots correctly...
    i hope this will help me to take bending a next level.

    lars
     
    Baldinoboy and Teila like this.
  40. Owen_Gusson

    Owen_Gusson

    Joined:
    May 26, 2014
    Posts:
    11
    Hi, I just purchased this asset very enthusiastically, and it looks like a great asset. However upon reading the documentation I'm worried it is not going to do what I was hoping for. I am working with scenes that do not use Unity terrains, for various reasons. Instead I have landscapes that are modeled externally (Blender) and imported, upon which game objects (including trees) are placed. I also own several of your tree assets (which are very awesome) and am trying to place many, many of them (1000s) across these landscapes, and yet keep the performance reasonable. My understanding from AFS description, was that I could have all but a handful of trees closest to the camera rendered as billboards (presumably only taking up 4 vertices each). I would like to lightmap shadows onto the terrain, and while wind for the trees closest to the camera (non-billboarded) would be nice, it's not a strict requirement. But it seems like, perhaps this only works with the Unity terrain engine? Is what I would like to do really not possible with trees manually placed on an arbitrary mesh? Thanks in advance for any thoughts or advise!
     
  41. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    hi owen,

    if you want to have billboarded trees you have to use the terrain engine, sorry.

    but – the terrain just has to be present in your scene ;-) ---> using the "reposition terrain tree" script you can put a simple flat unity terrain (causing only a few extra draw calls) at the bottom of your scene, add your manually modeled terrain on top, add trees to the unity terrain and reposition the trees to be rendered on top of your manually modeled terrain.

    and just a quick question: if you have a huge landscape (as it fits for 1000 trees), would it not be better to use the built in terrain (automatic LODs)? i would expect a large mesh/object to slow down rendering.

    lars
     
  42. gurayg

    gurayg

    Joined:
    Nov 28, 2013
    Posts:
    269
    Hello Lars,

    I was just wondering AFS and U5 and saw your previous post. Glad you've already starting working on U5+AFS :)
    I just want to add to that and ask about Speed Tree. I don't know even know if ST has its own shader or uses built-in.
    -Do you know if we will be able to use AFS features ( rain,PBR...) with ST models?
    -Is AFS in U5 a free upgrade?

    Thanks!
     
  43. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    hi gurayg,

    thanks.
    as far as speedtree is concerned: it needs and comes with its own shaders.
    so it does neither support rain nor pbs.

    and afs v4 for unity 5 will most likely be a free update ;-)

    lars
     
  44. gurayg

    gurayg

    Joined:
    Nov 28, 2013
    Posts:
    269
    Thanks for the quick reply.
    One more reason to upgrade to V5 :)

    I guess the reason they're using their own shader is because they prepare the tree vertex colors for their own shaders.and multi texturing to hide branch-trunk intersections.

    It does use the Unity Terrain systems tree LODs, doesn't it?

    Do you think it is feasible to replace the ST shader? AFS ST edition :)

    As a rough estimate, do you think you'll be able to finish AFS 4 by the end of this year (as a new year present maybe? :)
     
  45. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    hi gurayg,

    sorry, but no further comments on speedtree right now ;-)
    and i think afs 4 should be ready just a few weeks after unity 5 has shipped.

    lars
     
  46. Owen_Gusson

    Owen_Gusson

    Joined:
    May 26, 2014
    Posts:
    11
    Well I definitely tried to get the terrain engine to work, but it's just not suited to what I need. Most of the landscape area is low-res, but there are multiple areas with detailed cut-outs and specific sculpting that simply aren't possible with unity terrain. With blender I'm able to of course have a high resolution around certain areas, and decimate low-res areas. All told I have about 15k - 20k vertices for my landscape, which is around what I have budgeted.

    Anyway this is great - only I'm having a little trouble getting it to work. I did manage once to get it to work with the tree shaders demo scene, but I'm not sure how and I can't seem to repeat it :) My mesh is about 800m x 800m, and has a mesh collider. I added it to the "additional colliders" section of the reposition script, and it mostly worked -- the trees were placed at a relative height to the landscape, even though they weren't flush with the top. But moving my mesh down a few dozen meters, the trees showed up, perfectly aligned to the contour of the landscape. awesome! but then I tried adding some more trees to the terrain, and repeating the process, but it didn't work.

    So after multiple tries, I tried to create a whole new scene. A single, flat 800m x 800m terrain, placed trees, added my landscape mesh, added the reposition script to the terrain and then TRY to add my mesh to "additional colliders," but when I press "Add" after dragging it into the slot for "Add new collider", nothing happens. It never adds it to the list.

    Do you have any idea what I might be doing wrong?

    Thanks!
     
  47. Owen_Gusson

    Owen_Gusson

    Joined:
    May 26, 2014
    Posts:
    11
    never mind, I have gotten the reposition script to work now. I do still have one question. With the tree shader demo, I notice in the profiler a fair bit of processing by the script(s), even with the camera / character controller is stationary. I've tried to figure out which shader or script is responsible, but I can't seem to narrow it down. I'm guessing there is a lot of computation happening per frame. Do you know what might be responsible for the processing, and is it possible to optimize it such that it's only done on demand? for a scene where the camera is fixed, it seems to be doing a lot of unnecessary work.

    Thanks!
     
  48. Lupin500

    Lupin500

    Joined:
    Mar 6, 2012
    Posts:
    25
    Hi Lars,

    I'm having a strange issue and was wondering if you have suggestions regarding it. I'm using AFS for the terrain built-in grass (with AfsWavingGrassTerrainEngine v3) and I painted the vertex color alpha in the detail mesh (full alpha at the root and no alpha at the top).

    When I play in the editor everything works fine (the root is not affected by the bending, only the top part) but when I build the game the entire mesh is affected and the alpha at root is ignored. Do you know what could be causing this difference of behaviour between editor and build?
     
  49. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    hi owen,
    fine that you have find a way to work it out!
    as far as computation per frame is concerned: that should be rather low.
    the setup foliage shader script has to update the camera values (for camera aligned billboards), animate the wind and some other things – all pretty cheap as far as i can say. however it is very modular so you can easily comment functions you do not need. pleas have a look at "void update".
    if you use shaded billboards things might look a bit different as this script might do a lot of raycasts (according to your settings).

    lars
     
  50. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    hi lupin,
    have you attached the setup foliage shader script to your scene?
    as far as i can remember there was an issue with windows dicing vertex colors... (might be the byte order).

    lars