Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Advanced foliage shader [released]

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

  1. StudioDKP

    StudioDKP

    Joined:
    Nov 14, 2013
    Posts:
    6
    (This is Feracon)

    For doing plant planes like that is it best practice to model geometry that more or less follows the contour of the plants in the texture? So potentially more polys but less alphaed area on screen?

    I mean, whats the best way to do plant planes while conserving fill rate?

    Also, does AFS work with Unity 4.0.x?

    Thanks for the advice!
     
    Last edited: Nov 14, 2013
  2. larsbertram1

    larsbertram1

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

    it is always good to make very tightly modeled geometry – even if this would cost you some more polys. so: yes.
    modern gpus can handle a lot of polys and there are mostly fill rate bound.
    another very important point: smoothing angles. the higher the smoothing angle the less vertices you will get, as those get split at a shading edge.
    check this on the imported mesh. your 3d app won’t be able to tell you how many vertices unity will generate from your mesh.

    afs has been tested with unity 3.5 up to 4.3 and works fine.

    lars
     
  3. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    999
    Hey, I picked this asset up primarily to be able to have animated grass on my mesh terrain. Are the texture requirements for grasses the same as whats described on page 7 of the documentation PDF? Also, would it be possible to use/generate billboards for trees on a mesh? And I have a lot of trees from various assets, Is there a guide for modifying them to be compatible with AFS? Thanks.
     
  4. larsbertram1

    larsbertram1

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

    no. as i would highly recommend to use the "no translucency" version of the grass shader all you need is a single diffuse texture.
    but when using different "grass textures" it is always recommended to atlas them (but you do not have to split the texture into half nor have to use a atlas shader). simply add all textures to one image file und lay out your uv accordingly.

    that is not supported by the package. billboarding only works if you use the built in terrain engine.
    but of course you can use LODs or create your own solution.
    or you can wait for the next update: free positioned terrain trees: you would have to place a terrain object below your mesh terrain (a very simple one, very high pixel error, low res heighmap and custom shader which does not render anything at all so you do not wast many draw calls). then you could use the script to make the terrain trees show up un your mesh terrain. might be heavily overdone but that would just work…

    you do not have to make them compatible with afs if they are use the "tree creator" shaders. but you won’t benefit much from the improvements of the afs tree shaders as most of those effect billboarding and the transition between billboard and mesh tree ;-)
    but of course you can also use the standard advance foliage shader on a tree (bending will look different though).you would have to combine both tree materials into on, then set up the vertex colors according to the manual.

    lars
     
  5. feracon

    feracon

    Joined:
    Mar 4, 2013
    Posts:
    84
    Hi Lars,

    I'm still having issues with the gloss. The attached screenshot shows the uneven shading we're getting with a RGBA targa with black in every channel. $Flower error.jpg

    I'm trying to turn off the normal map (GA) translucency (R) and gloss (B) completely but it's not working.
     
  6. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,927
    hi feracon,

    first: when talking about adding more ploys i did not mean to do what you have done.
    for a simple flower i would not spend more than 50 – 60 tris at all.
    the the mesh and the texture atlas could look like this may be:

    $flower.png $flower_atlas.png

    as far as specularity is concerned: everything looks alright for me: no bleeding highlights visible as far as i can say.
    so may be your directional light is simply too strong and ambient lighting might be too low.
    please also check your normals and the smoothing angle of your model.

    just to test it: switch the used shader to diffuse or specular bumped.
    i am pretty sure that both shaders will give you equal results.

    lars
     
  7. feracon

    feracon

    Joined:
    Mar 4, 2013
    Posts:
    84
    Hi Lars,

    Thanks for the in depth reply! This flower will be viewed in virtual reality with HMD and head tracking. For this reason we need flowers that are not back face culled. We'll probably use a mix of the higher poly version we have and a low poly configuration as you suggest.

    The issue I was having turned out to be a combination of the normal map channels being black or white, instead of 50%; and the directional light we're using in the scene just affected your shader overly harsh compared to others.

    We're just going to put all objects using your shader on a layer with a dedicated directional light.

    Thanks again!
     
  8. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,927
    hi feracon,

    fine that you have figured it out, haven’t you?

    lars
     
  9. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,527
    Hey lars I am clueless as to how to paint grass on geometry. I read the documentation, which I'm sure it's in, but I can't figure it out.

    Thanks
     
  10. larsbertram1

    larsbertram1

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

    you can either just place your grass objects manually like you would do with any other game object.
    or you can download and use the customized geometry brush to just "paint" grass. this would need colliders on the geometry you want to paint on.
    do not forget to parent your grass under an empty game object and use the combine children afs script.

    so what exactly is your problem?

    lars
     
  11. Quen

    Quen

    Joined:
    Apr 6, 2010
    Posts:
    21
    Hi,

    this looks great! I don't know much about shaders, I just use them. ;-) Though, in the past I experienced some problems combining shaders from different sources as they seem to replace each other sometimes. In my project I use RTP3 and I would like to know if your foliage shader works with this in combination? Do you have any experience with this?

    Greetings,
    Quen
     
  12. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,927
    hi quen,

    ;-)

    lars
     
  13. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,527
    I have been placing them manually. Where would I download the geometry brush to paint the grass?
     
  14. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,927
  15. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,527
    Thanks lars. Sorry for my incompetence :confused:.
     
  16. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,927
    we are all getting better from day to day. so just be patient.
     
  17. david55527

    david55527

    Joined:
    Mar 24, 2013
    Posts:
    58
    Just purchased last night, looks great so far.

    I have some small bushes created using the tree creator. It appears that touch bending won't work on these. Any easy way to get this working?
     
  18. larsbertram1

    larsbertram1

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

    in order to make your bush work with touch bending you would have to export it (e.g. using the obj exporter form the wiki).
    open the obj. file with your 3d app and merge both materials. you could also add some vertex colors (red and green like mentioned in the docs).
    save it as fbx and bring it back to unity.
    use the foliage tool to set up primary and secondary bending.
    then you are ready to use touch bending.

    lars
     
  19. david55527

    david55527

    Joined:
    Mar 24, 2013
    Posts:
    58
    Awesome, thanks :)
     
  20. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,927
    you are welcome!
     
  21. feracon

    feracon

    Joined:
    Mar 4, 2013
    Posts:
    84
    Hey Lars,

    I'm trying to use your shader in a project that is limited to Unity 4.0.1f2 and I'm getting errors after import. Can you work with me to resolve these? Let me know what information or troubleshooting steps you'd like me to take. Thanks!

    Capture attached.

    $AFS_401f2.JPG
     
  22. larsbertram1

    larsbertram1

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

    the yellow one are just warnings. so simply ignore those.
    but i do not know where the red ones come from: i have tested it with unity 3.5, unity 4.2 and unity 4.3 and everything works fine...

    usually when using js you do not have to declare a variable before you can use it. so "unknown identifier i" does not make much sense.
    really strange. but nervertheless.
    try to declare it after all other variables.
    so find:
    Code (csharp):
    1. //    Special Render Settings
    2. var AllGrassObjectsCombined = false;
    3.  
    and add:

    Code (csharp):
    1. var i = 0;

    below.


    lars
     
    Last edited: Nov 17, 2013
  23. David-Lindsay

    David-Lindsay

    Joined:
    May 20, 2009
    Posts:
    121
    Hi Lars,

    I have a problem with the AFS shaders that ONLY occurs in deferred rendering.

    The foliage and tree shaders are somewhat transparent (in addition to their alpha cutout). This is most visible in places of dark shadow, as I am using very high bright/dark areas in my test scene.

    I've attached pictures that attempt to display the issue, but it's hard to perceive from a static picture. When the camera moves around the scene, however, the transparency of the trees is very very clear and looks like a graphic bug even to the untrained eye. Basically the shaders are just too transparent, but none of the settings can adjust this.

    I want the opaque areas of my foliage to be like normal unity3d cutout shaders (leaves and thick branches should not be transparent at all).

    I feel like I am missing something here... maybe in the Alpha vertex color channel? Or is this a texture channel problem?
     

    Attached Files:

  24. David-Lindsay

    David-Lindsay

    Joined:
    May 20, 2009
    Posts:
    121
    Sorry, the bug/issue is very hard to capture in a screenshot. Perhaps this one is better?
     

    Attached Files:

    Last edited: Nov 17, 2013
  25. David-Lindsay

    David-Lindsay

    Joined:
    May 20, 2009
    Posts:
    121
    UPDATE: Tried a clean project and same results. Objects in background bleed through the AFS shaders, especially SSAO (both obscurance and occlusion.
     
    Last edited: Nov 17, 2013
  26. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,927
    hi david,

    i am sorry that you are having problems using the shaders but i think that a solution should be found rather quickly.

    especially the fact that ssao seems to shine through the foliage clearly points towards an incorrect calculation of depth.
    and i guess this will probably be the reason for all your problems.
    so lets focus on this first.

    depth is calculated by the "Camera-DepthNormalTexture" or the "Camera-DepthTexture" shader both located in the "Resources" --> "ShadersBuiltin" folder that ships with the package.
    please make sure that it is right in place. then have a look at the shaders e.g. the "Camera-DepthTexture" shader.
    the first subShader should start with: Tags { "RenderType"="Opaque2Sided" }
    the second with: Tags { "RenderType"="AfsTreeBillboard" }
    you can simply start by reimporting them to make sure that they are compiled properly and active.

    it also might be that those shaders get overwritten by other "Camera-DepthNormalTexture" or the "Camera-DepthTexture" shaders that might ship with another package you use in your project. check this by searching for "camera-depth" in your project folder. there should be 2 hits only…
    if there are more you can either remove the shaders that do not belong to the afs package (which might break rendering on other objects though) or you can "merge" the single shaders together.

    please let me know if this solves your problems.

    lars
     
  27. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,927
    and here is a picture of how it should look – and looks for me of course ;-)

    $ssao.jpg
     
  28. David-Lindsay

    David-Lindsay

    Joined:
    May 20, 2009
    Posts:
    121

    Hi Lars,

    I was using Unity 4.3.X and AFS 2.04. I thought that was the newest AFS. I downloaded from the asset store again and it seems that 2.041 has none of the SSAO or shadow issues. That seems to have completely made the issue go away.

    If anyone else has this issue, I suggest not only to reimport, but also delete the previous 2.04, download the newest package from the store again, and reimport.

    Lars -Thanks for pointing me in the right direction! Those two camera depth shaders were the ones that did not compile. I think the problem was this: The directory structure in 2.04 is different, I upgraded to 2.041 without noticing the extra +0.001 version change. Then some scripts couldn't find their buddies in the "resource" folder -I think that's why my "Camera-DepthNormalTexture" or "Camera-DepthTexture" were showing shader-compile errors. But they seem fine now, so... Yippee! :p

    I can clearly see that the shader is now correctly compiled and looks about a million times nicer (even with my mis-matched spec/trans and diffuse/alpha here)... phew!
     

    Attached Files:

  29. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,927
    jippieh, i am glad you have solved it.
     
  30. larsbertram1

    larsbertram1

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

    just a quick preview on one of the new features:
    in the upcoming version 2.042 the foliage tool will automatically detect whether it is assigned to a tree created using the built in tree creator and offer you some new options which will do most of the job as far as making your tree compatible with the "Foliage" shader or the "Simple Terrain Tree" shader
    (using the "Foliage" shader you will be able to add touch bending, using the "Simple Terrain Tree" shader will cut the number of draw calls into half).

    the foliage tool will merge the submeshes, delete the 2nd uv set and give you the possibility to combine the normal_specular and translucency_gloss maps into one single texture with just a single click.
    all you have to do is to set up primary and secondary bending using the "Set Bending" function of the foliage tool.
    "phase" and "edge fluttering" as well as "ambient occlusion" are copied from the original tree.

    lars


    $foliageTool.jpg
     
  31. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Wow this looks so good, both Lars your presentation on simple white ground and David your plants too.
     
  32. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,927
    thanks janpec!
     
  33. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    999
    That is great! When do you expect to release the update? Thanks.
     
  34. larsbertram1

    larsbertram1

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

    i might be ready to send it to the asset store within the next few days – but the asset store team needs about a week to approve the package.
    so it might be 10 – 14 days…
    do you have need of a feature like this right now? then send me a pm.

    lars
     
  35. larsbertram1

    larsbertram1

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

    here comes a little list of all new features and changes of the upcoming version 2.042:

    Reposition Trees AFS
    - This script lets you place "terrain trees" on top of any other geometry while you will still benefit from billboarding


    Advanced Billboard Shader
    - Billboards can cast real time shadows


    Advanced Tree Creator Shaders
    - Adjust the contrast of the generated billboard textures globally and/or per leaf material using the "BillboardContrast" parameter of the "AfsTreeCreatorLeafsOptimized (_ShadowFade) shaders


    SetupAdvancedFoliageShader script
    - Refactored and converted to c# – finally...


    Foliage Tool
    - Lets you easily merge meshes of Tree Creator Trees to make them fit the needs of the foliage shaders or simple terrain tree shader


    Shaded Billboards AFS
    - Better memory management, less garbage collector calls


    i hope you like it,

    lars
     
  36. bpears

    bpears

    Joined:
    Aug 23, 2012
    Posts:
    249
    So, will this still require a unity terrain? To be underneath? To just exist somewhere? No need? Or..? Sounds great :)

    Edit: also, will terrain trees also still benifit from tree wind with this?
     
    Last edited: Nov 22, 2013
  37. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Lars have you been thinking spicing up grass shader with strong AO for example like user with name "cod" did in WIP thread. Basically making grass shader look better.
     
  38. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,927
    Reposition Trees AFS
    those require a unity terrain, yes.
    i did not have a scene in mind which would not contain any unity terrain but only manually modelled geometry but more or less a quite typical case: unity terrain plus some manually modeled cliffs, overhangs and huge rock formations. so the extension will allow you to place "terrain trees" on those too.

    nevertheless you can even have your terrain just manually modeled and place "terrain trees" on top of this if you add a very simple lowres unity terrain underneath.

    yes of course.

    lars
     
  39. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,927
    hi janpec,
    no, i have not been thinking about that – as it is already possible.
    you can either just use the texture to bake ao or you can bake it to vertex.color.rgb.

    lars
     
  40. feracon

    feracon

    Joined:
    Mar 4, 2013
    Posts:
    84
    Hey Lars,

    Ive used your plugin in a live wallpaper for android, it works on my Samsung S3 but on my Nexus 10 and 2.2 droid, it doesnt animate the verts.

    Any idea why or how I could go about possibly getting it to work on these devices? I think this indicates a large part of my target demographic will have issues with it.
     
  41. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,927
    hi,
    the shaders have neither been written nor optimized for mobile.
    but most of them just should work if the needed shader model is supported on the given plattform.
    (groundlighting and simple tree sahder needs sm 3.0 – all other sm 2.0).

    so i have no idea what is going on there, sorry.
    have you checked the setupscript? because if the plants are rendered the shaders work (as no fallback is definded).
    so there might be just the modified wind parameters missing from the script.

    lars
     
  42. feracon

    feracon

    Joined:
    Mar 4, 2013
    Posts:
    84
    Yeah they are rendering, they are just completely still. They run really well on my S3.

    There was a warning it gave me about certain processors I believe. When I get back home today I'll get you more information, maybe we can work through it.
     
  43. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,927
    do so. and let me know what kind of warning you get.

    lars
     
  44. bpears

    bpears

    Joined:
    Aug 23, 2012
    Posts:
    249
    So, if I moved that mesh I had placed the trees on, someplace that did not hover above the unity terrain, would the trees stay in place?

    How about if I moved the mesh, but it was still hovering over the Unity terrain?

    If I moved the Unity terrain with the mesh?

    Thank you
     
  45. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,927
    nope, trees can only be placed above the terrain i would say.

    you will have to hit "reposition trees" again.

    should be ok.
     
  46. feracon

    feracon

    Joined:
    Mar 4, 2013
    Posts:
    84
    Below are the errors I'm getting on build for android. It's the qualcomm/Adreno driver issue I'm assuming is affecting my two test devices.

    All I absolutely NEED from your shader is the vertex animation.

    Any ideas? Thanks!

    $AFS_shderror.JPG
     
    Last edited: Nov 23, 2013
  47. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,927
  48. feracon

    feracon

    Joined:
    Mar 4, 2013
    Posts:
    84
    I tried building with the ATC texture compression and the app crashed on both devices. Also the same errors are thrown on build.

    Each instance of that error points to an instance of your AFS shader.

    I do have cutout shaders being used, disabling them did not help.
     
  49. feracon

    feracon

    Joined:
    Mar 4, 2013
    Posts:
    84
    If I use nature>tree creator leaves, the wind influences the verts but doesnt appear to take into account the vertex paint; so they're moving way too much. But the meshes animate on all devices just fine.

    Is there a way to just paint verts wind influence using the regular tree creator leaves shader?
     
  50. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,927
    and do you get errors or warnings when using the tree creator leaves shader?
    they should be exactly the same: "shader is using clip instruction"...