Search Unity

Advanced foliage shader [released]

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

  1. neler93

    neler93

    Joined:
    Dec 11, 2012
    Posts:
    99
    Hey lars, I bought your pack and it is just awesome! But the problem is that the tree billboards are showing up over global fog image effect. I just cant get it to work properly. I am using deffered lighting.
    Untitled-2.jpg
     
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    billboards use forward rendering – and regular fog. so in case you use height based fog in the deferred fog image effect this might cause your problem. just deactivate height based fog and it should be gone.
     
  3. xstar_green

    xstar_green

    Joined:
    Mar 28, 2015
    Posts:
    16
    I'm reading the documentation inside the unitypackage.
    And found this:
    111.png
    How to fix this?
     
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    first you have to find out why the shader is broken.
    you should have some errors in the console.
    if not, select the shader in the project tab and rmc -> reimport it.
     
  5. xstar_green

    xstar_green

    Joined:
    Mar 28, 2015
    Posts:
    16
    Thanks for your reply.
    And here's the error:
    5.3.1f1:
    123.png
    122.png
    So...any solutions?
     
  6. xstar_green

    xstar_green

    Joined:
    Mar 28, 2015
    Posts:
    16
    Hi,
    I'd also want to ask if those tree shaders support speedtree(.spm) because I usually use speedtree models rather than built-in tree creator's.
     
  7. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    you may have to update to the latest version of the package. the errors point towards lines which i had to change for unity >5.2
     
  8. totrider

    totrider

    Joined:
    Jul 25, 2014
    Posts:
    13
    Hi, i am currently using the advanced foliage shader in a tower defence project and have run into an issue.

    As you can see in the image below, a projector is projecting colors down onto the playable area which indicate where the mobs can walk and where you cannot build etc.

    It works for regular shaded objects like the cliffs and such, but it does not affect the advanced foliage v4 shader on neither the trees/grass placed manually or on the terrain plate.

    Any idea on how to get it working so that the plants are also affected by the projector?
     
  9. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    unfortunately you can not use projectors on (vertex) animated and cutout geometry...
    not to mention that using projectors is insanely expensive as everything has to be rendered twice.
     
  10. PiAnkh

    PiAnkh

    Joined:
    Apr 20, 2013
    Posts:
    126
    Is AFS shader compatible with unity 5.4?

    I am getting some strange black stripes in the grass when I import the current version of AFS into my scene. I have no other foliage/grass shaders in my project.
    withAFS.jpg
     

    Attached Files:

  11. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    i have not encountered any problems yet – but i m not sure if that really is the afs grass shader. please enable approximated translucency and check if you get any translucent lighting.
     
  12. PiAnkh

    PiAnkh

    Joined:
    Apr 20, 2013
    Posts:
    126
    How do I enable approximated translucency?
     
  13. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    use the afs setup script to do so.
     
  14. PiAnkh

    PiAnkh

    Joined:
    Apr 20, 2013
    Posts:
    126
    I found the problem. I had not set up the afs scrpt. I did not realise it was need for grass. Silly of me.
    Thanks Lars
     
  15. artistpetemac

    artistpetemac

    Joined:
    Sep 8, 2014
    Posts:
    19
    Hi Lars and AFS family,
    I've recently created a scene using Time of Day (by plzdiekthxbye) using Tropical Trees (by baldinoboy) and everything worked pretty well after I had it all set up properly. The only issue is that the tree billboards have noticeable halos around them at night, seemingly related to the mipping of the billboard texture. If you move toward the billboard trees you can see the halo's get thinner with each mip level. This problem is amplified by the fact it's a VR scene, so the resolution is lower...
    VR, Forward rendering, realtime lighting...
    Any suggestions?
    -Pete
     

    Attached Files:

  16. artistpetemac

    artistpetemac

    Joined:
    Sep 8, 2014
    Posts:
    19
    It occurs to me that dilating the RGB channels of the billboard texture would probably resolve this. Is that something you've ever considered doing Lars?
     
  17. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    that is not trivial. but you find various proposals for solving the problem (e.g.: http://answers.unity3d.com/questions/336217/terrain-tree-billboard-have-bright-outline-against.html).
    in fact simply multiplying the color by alpha^2 pretty much does the job: it adds a tiny dark border around the billboard which is not very noticeable at daytime but removes the bright outline at night.
    fixed4 col = tex2D( _MainTex, input.uv);
    col.rgb *= col.a * col.a;
     
    artistpetemac likes this.
  18. totrider

    totrider

    Joined:
    Jul 25, 2014
    Posts:
    13
    hmm makes sense, however, not having any significant performance decrease, also read that projectors should be quite cheap for what they can be used for :)

    Guess we have to figure out something else.
     
  19. artistpetemac

    artistpetemac

    Joined:
    Sep 8, 2014
    Posts:
    19
    Hi Lars,
    Thanks for the help with the billboard halos. Today I'm struggling using the CTI and Afs Foliage Tool. I hoped to convert a custom modeled tree to an AFS tree, just for the bending and leaf tumbling. Then I hope to use the Foliage Tool to collapse it to one draw call. It really didn't work out well, lot's of things were broken after the foliage tool finished. Before I go into the details of what was broken, I guess my question is: should this work? Is the foliage tool strictly for tree-creator trees, and by feeding it a converted afsTREE did I just confuse it?
    -Pete
     
  20. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    hi pete,
    i would expect it to work.
    what was broken?
    lars
     
  21. artistpetemac

    artistpetemac

    Joined:
    Sep 8, 2014
    Posts:
    19
    Here's a before and after. The UV's and textures were not re-configured correctly. You can see that the trunk and the leaves both use the whole UV 0-1 space. The diffuse texture is only leaves, but 1/2 of the alpha channel is black. The trans-gloss map is similar, no information from the trunk, except the alpha. The normal map is just the leaf normal map.

    Also, the whole tree animates like a leaf...fluttering trunk and branches. When I add the tree to the terrain system it doesn't animate at all. I exported it as an obj so I could bring it into 3dsMax and fix the UV's, There I discovered that it didn't have any vertex color information. Which I guess explains the animation issues.

    AFS_FTool_Issue.JPG AFS_FToolMat_Issue.JPG
     
  22. artistpetemac

    artistpetemac

    Joined:
    Sep 8, 2014
    Posts:
    19
    btw, I've just been testing the Foliage tool with some of Baldinoboy's Tropical trees, and I've been getting the same kind of errors. That seems to indicate that the issue doesn't lie with the custom tree importer.
     
  23. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    hmm, i will have to look into this, but:
    • already the "pagoda_afsTREE_combined_b_material" looks corrupted: base and normalmap should show a combined map (left half trunk, right half leaves) – like the trans/gloss map does.
    • exporting any tree/cti mesh as obj will totally corrupt your efforts as obj does not support more than one uv set
    nevertheless cti supports different texture sets for bark and leaves (it does not need combined / atlased textures).
    and the foliage tool does not include any functionality to atlas textures and tweak uvs on the fly.
    so when you originally model your tree in your 3d app you will have to manually atlas your textures and set up the uvs for bark and leaves accordingly.

    as far as fluttering is concerned: it might be related to the bending you have choosen: you wil have to use "vertex colors and uv4".
     
  24. artistpetemac

    artistpetemac

    Joined:
    Sep 8, 2014
    Posts:
    19
    Thanks for your time. I'm confused by your response. When I add the Foliage Tool script to the tree (after creating a save mesh) I have two options: "Convert Tree into flattened Tree" and "Convert Tree for Foliage Shader". Since the tree's materials, and vertex info are already afs, I choose "Convert Tree into flattened Tree". I don't get the option to choose bending parameters. So that's my first question: where do I do that?

    As you noted the textures it creates are not correct. I expect to see the bark textures on the left side, and the leaf textures on the right side, but what I get is leaf textures, with some corrupted alpha channels, where the left side has been turned white. It's as if it's not finding or reading the bark textures somehow. So when you say "you will have to manually atlas your textures and set up the UVs" Do you mean I should create these combined textures before running the Foliage tool, and arrange my bark UV's and Leaf UV's accordingly before I run the foliage tool? If that is the intended workflow, then why is the script generating textures and materials at all? Or is it assuming you are giving it standard textures and it's shuffling the channels into afs combined textures, and then filling in the bark alpha in case the source textures didn't include it?

    -Pete
     
  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    you get this option only if you choose "Convert Tree for Foliage Shader".
    the script expects a "tree creator tree" which always have atlased textures and uvs setup properly.
    and it only "corrects" the alpha for the bark texture.
    yes. your custom tree modeled in your 3d app already has to use that combined textures and to have proper uvs applied to it – unfortunately.
     
  26. artistpetemac

    artistpetemac

    Joined:
    Sep 8, 2014
    Posts:
    19
    Okay, Thanks for helping me figure this out. It turns out that the answer to my first question: "I guess my question is: should this work? Is the foliage tool strictly for tree-creator trees, and by feeding it a converted afsTREE did I just confuse it?" Is "no, it's expecting a tree creator tree in these respects...." It would be helpful if you mentioned this in the documentation...would have saved me a day. I might humbly suggest for any upcoming versions of this tool, to provide a 3rd option to flatten afsTREE's. It seems like it would be a fairly simple thing...for that matter atlasing the UV's would also be easier in code than it is in 3ds max.

    So let me ask you this: Since I'm using the CTI to get my tree in, I don't need to use the "convert tree for Foliage shader"...in that case, do I have any way to set the bending parameters? Or should I run it through that option first, and then remove the script, add it again, and then run the collapse option?

    Please take my suggestions in the constructive spirit they are intended. I appreciate everything you do, especially your responsiveness on this forum.

    -Pete
     
  27. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    hey pete,
    you need to do so as it will flatten the submeshes and copy bending information to the proper uv set.
    and as far as i can say you do not have to run it a 2nd time. but you will have to prepare your manually modeled tree properly (shared textures, shared uvs – as described above).
     
  28. artistpetemac

    artistpetemac

    Joined:
    Sep 8, 2014
    Posts:
    19
    Thanks Lars,
    I understand about the UV's and texture atlas'ing, I did manage to get that tree working last night, (although the bending seems imperfect, it will do for now) I thought the Custom tree importer also did that? It creates the _modified mesh...does it not copy the bending info? The tree that I did last night does move in the wind, and it is now one mesh and material, and I never used "convert tree for foliage shader". So to be very clear here is my process:

    1) 3dsMax: break down custom modeled tree, and create hierarchy, move pivot points, name submeshes trunk/branch/leaf
    2) 3dsMax: Transform the branch and trunk UVs to fit in the 0,0 - 0.5,1, Leaves into 0.5,0 - 1,1
    3) 3dsMax: export tree with the name treename_afsTREE.fbx ( _modified mesh is created and assigned in Unity)
    4) Photoshop: Create combined texture atlas with bark on the left, leaves on the right, with channels arranged according to the modeling guide
    5) Unity: Assign the same texture atlas to both the bark and leaf materials, (make sure they are type advanced bypass RGB sampling)
    6) Unity: add the Foliage Tool script, save off a treename_afsTREE_collapsed mesh.
    7) click the "Convert Tree into flattened Tree"....wait....
    8) Test!

    So are you saying I need to use "convert tree for foliage shader" as well?...
    -Pete
     
  29. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    in order to get best bending you will have to add control tags to the different parts of your tree.
    please have a look at the jatoba tree included in the package.

    either or:
    • using "Convert Tree into flattened Tree"will give you a "simple" tree – which should be fine: one material, one draw call. but it stores bending in UV2 like the built in tree creator shaders which means: no lightmapping. you have to use the simple tree shader.
    • using "Convert Tree for Foliage Shader" will do more or less the same but copies bending information to UV4 (or simple combines primary and secondary bending in vertex color blue). lightmapping is fully supported and you can use any of the foliage shaders.
    lars
     
    artistpetemac likes this.
  30. artistpetemac

    artistpetemac

    Joined:
    Sep 8, 2014
    Posts:
    19
    Thanks Lars! That explains a lot. I didn't realize convert tree for Foliage Shader also flattens.
     
  31. PutridPleasure

    PutridPleasure

    Joined:
    Mar 3, 2015
    Posts:
    11
    Hi Lars,
    I was wondering if GPU instancing would be feasable and provide a benefit if added to your asset?
    If so I'd be happy to pay for a new Version of afs that supports it.

    Edit: Added link to manual
     
    Last edited: Aug 4, 2016
  32. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    instancing will come with the next version currently under development and nearly ready to ship :)
     
  33. Lan14n

    Lan14n

    Joined:
    Feb 8, 2014
    Posts:
    4
    Hello Lars,
    Was just wondering why ssao is going through my foliage textures.

    It was working fine before upgrading to 5.4.
    I'm using AFS/Foliage Shader v4 with ssao pro attached to the camera. It also happens with the built-in unity ssao.
     
  34. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    hi there!
    in unity 5.4. you have to assign the depthnormal shader – it does not get simply overwritten as before.
    go to edit -> project settings -> graphics
    in the inspector that will show up find "depth normal shader" chose "custom shader" and assign the depth normal shader that ships with afs.

    lars
     
  35. Avonaeon

    Avonaeon

    Joined:
    Apr 17, 2012
    Posts:
    48
    So after a lot of testing, I found out it was because certain scenes had the lighting mode set to "Directional - Specular". If lighting mode was set to this, and I make a build, any scene that has trees will have the white tree glitch issue. Setting the lighting mode to Non-Directional and making a new build, fixed the issue.

    I'm really at a loss as to why this happens, but at least I have a fix I can use, or rather I know what to avoid doing.
    I tried setting the lighting mode to "Directional - Specular" in an empty test project with only afs and scion as well, like you suggested, but the issue doesn't appear in the new project. So it might be a combination of AFS, Scion, lighting mode set to "Directional - Specular" and something unknown that seems to cause the issue.

    Anyway, thanks for all the help in trying to figure this out.
     
  36. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    hmm, interesting finding.
    trees do not support lightmapping by design as they store bending values in uv2 – and do not have any lightmap uvs.
    i guess i have to think about this a while.
    lars
     
  37. Lan14n

    Lan14n

    Joined:
    Feb 8, 2014
    Posts:
    4
    Cool thanks!
     
  38. buronix

    buronix

    Joined:
    Dec 11, 2013
    Posts:
    111
    Hi I having a problem with the grass mesh and the wind blending, the entire mesh is blending with the wind :



    That video was of a mesh configured with the Afs Foliage Tool with this configuration :

    grass_foliage_tool.jpg

    I also tryed with the mesh from "Grass singlesided shifted Pivot_AfsGM10", I modify the UV in Blender I tryed to exporting to fbx and its working except for the Wind blending problem, I tryed to update the exported fbx with the Afs Foliage Tool and the results are the same, but its not happening with the Original Meshes provided in the demo scene (But I need to implemented it with my own grasses).
    Am I doing something wrong?
    Please, Can you guide me through this problem? I can give you any information you need to resolve this.

    Thanks in Advance.

    Ruben.
     
  39. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    hi ruben,
    the foliage tool does not let you set up grass meshes, sorry.
    you will have to either:
    - manually paint bending to vertex color alpha: 0.0 = no bending / 1.0 = full bending
    - or you can use the "AFS Grass Model Postprocessor" script. please have a look at "09 AfsGrassModel Postprocessor.rtf" how to take advantage of this script.

    lars
     
    buronix likes this.
  40. buronix

    buronix

    Joined:
    Dec 11, 2013
    Posts:
    111
    Thanks!! the postprocessor script works like a charm!!
     
  41. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    fine!
     
  42. buronix

    buronix

    Joined:
    Dec 11, 2013
    Posts:
    111
    Hey!

    Im trying to use the AFS tree creator shaders in my "trees" (bushes and special grasses but generated with tree creator), and Im getting a weird message when I try to set the material with the shader on it, and it does not allow me to use the shader :
    material_afs_tree_creator_leaves_optimized.jpg

    afs_tree_creator_Error.jpg


    What am I doing wrong?

    Im on Unity 5.4 f2.

    Thanks in Advance.
     
  43. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    hi there,
    you must NOT use the "Nature/Afs Tree Creator Leaves Optimized" shader on your base material.
    use the "Nature/Afs Tree Creator Leaves" instead. it will be replaced on the final tree by unity automatically.

    lars
     
  44. buronix

    buronix

    Joined:
    Dec 11, 2013
    Posts:
    111
    Hey thanks!, I feel pretty stupid right now.

    :D.

    One thing, I have a dynamic weather system and I want to add wetness and snow to my Enviroment, I was checking other of your products. and for example Lux allow to add dynamic snow to shaders and wetness, I was testing with other shaders to implement something similar, and I only found the solution to add a second material with the dynamic snow and change the cutout of the AFS material to only display the second one with the same textures and the snow/frost effect, I am not a graphical designer so My knowledge about shaders and 3d models are very limited, (Im a programmer), Is there other way to implement wetness or dynamic snow in AFS?

    is it in your mind to implement it like the raindrops etc?

    Thanks For all!.

    Ruben.
     
  45. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    wetness is already implemented (although it is not connected to Lux Dynamic weather – which should be easy to accomplish though). dynamic snow is not part of afs.
    but as Lux supports to write your own surface shaders you may simply edit the foliage shaders and add lux's snow funtions to them. follow the lux documentation to find out more and have a look at the example shaders included in the lux package.

    lars
     
  46. buronix

    buronix

    Joined:
    Dec 11, 2013
    Posts:
    111
    Hey thanks for your time,

    I was testing with the standard foliage shader v4 and its working but I notice that my bushes are not generating shadows neither with this modified version or the original, need I to do something to generate realtime shadows on the terrain?, Im not adding these bushes as terrain details, they are prefabs on top of the terrain, Im on forward Rendering Path.

    Im not sure if Im abusing of your time but could you check if my modified version of the shader is correct (its displaying the snow correctly but I want to make sure about this before start modifying all my other afs shaders).

    Thanks in advance for your time and patience!!

    Ruben.
     

    Attached Files:

    Last edited: Aug 14, 2016
  47. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    hi ruben, i do not have a project which contains afs and lux right now so i could not do a quick test, but from what i can see in the shader code you use #pragma .... addshadow which should take care of proper shadow casting automatically.
    if placed as prefabs they should ast real time shadows, strange!
    which version of unity, which gpu, os etc do you use?
     
  48. buronix

    buronix

    Joined:
    Dec 11, 2013
    Posts:
    111
    Im on 5.4 f2., Radeon HD 6970, windows 7, but I checked the plants you attached to the Afs package and they are casting shadows.

    I was testing with Yughues Bushes asset
    https://www.assetstore.unity3d.com/en/#!/content/13168

    They are in obj format, I tryed to exported as fbx from Blender and its the same, Does the mesh or the texture needs something in particular to cast shadows with AFS?
     

    Attached Files:

  49. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    well, not that i am aware off.
    i tested your "bush01Blend" fbx and it just casts shadows using the "Foliage Shader v4".
    i had to adjust the cutoff value as the alpha of your main tex is pretty dark.
    normals are pretty much corrupted so lighting looks odd. i would suggest to let unity calculate normals on import.

    Bildschirmfoto 2016-08-14 um 12.21.07.png
     
  50. buronix

    buronix

    Joined:
    Dec 11, 2013
    Posts:
    111
    Never underestimate how stupid I am, I was testing in your scene and suddenly a wild shadows appears!!

    I was close to blowing my head off and then I noticed I was culling the bushes layer from the light, I completely forgot to change the layer of the bushes to my vegetation layer!!

    Sorry for losing your time, and lot of thanks for all your efforts!!.

    Ruben.
     
    hopeful likes this.