Search Unity

Best built-in shaders for custom foliage?

Discussion in 'Shaders' started by hptware, Jul 2, 2014.

  1. hptware

    hptware

    Joined:
    Dec 11, 2012
    Posts:
    107
    Hi All,

    We are trying to figure out how to best implement custom foliage models (trees and plants) in Unity. We have a product Forester Pro which generates models of trees, bushes and small plants for Unity, UDK/UE4, Torque3D etc. It produces a model with separate meshes for leaves and branches/stems, it produces normals and uv coordinates, and provides textures. Basically it produces the custom model of a foliage item in FBX format.

    http://www.hptware.co.uk/forester.php

    Some of our Unity users, however, complain they can't make the foliage "look right" in Unity. As you might guess usually this is usually phrased like "your trees don't cast shadows! There is something wrong with the model" ;) However, the models provide just a mesh and textures that import and seem to be fine, so we suspect that it is the implementation of these models in Unity. So we are looking for advice on how to best set-up foliage shaders.

    This is what we've figured-out on our own:




    For leaves:
    (1) Nature\Tree Soft Occlusion Leaves - Probably the nicest looking but requires the asset to be in the Assets\Standard Assets\Terrain Assets\Trees Ambient-Occlusion folder. This shader casts shadows but won't receive them.

    (2) Nature\Tree Creator Leaves - A nice shader, and has lots of extra functions such as shadow offset channel, and transparency channel that require specific images (you could make these from the diffuse texture). The shader casts shadows but won't receive them.

    (3) Transparent\Cutout\Diffuse - Actually considering this is the simplest shader of the three it is pretty darn good. It casts and receives shadows, including self shadows. I'd recommend this one but users complain about the hard edges.

    For Bark
    (1) Nature\Tree Soft Occlusion Bark- The asset needs to be in the Assets\Standard Assets\Terrain Assets\Trees Ambient-Occlusion folder.

    (2) Nature\Tree Creator Bark- Casts and receives shadows.

    (3) Diffuse- Simplest shader of all, casts and receives shadows.


    So some questions:

    (1) Is any of the above wrong, or just plain stupid.

    (2) Are we correct in thinking that this is not a model related issue, but the shader implementation.

    (3) Are there any other built-in shaders that will work better?

    (4) Is it possible to use the hidden\nature\tree creator leaves optimised shader on custom models? I have tried to recreate this one (I have the code) as a custom shader but it won't compile.

    Anyway, many thanks in advance for the pearls of wisdom.

    Best,
    HPTWare
     
  2. kebrus

    kebrus

    Joined:
    Oct 10, 2011
    Posts:
    415
    alpha blended transparency doesn't cast shadows in unity, only alpha test (cutout) that said if you only want to point out a simple set it and forget it shader transparent cutout diffuse seems good to me

    the problem is, those are custom models for trees, which means not optimized at all, thats why unity has the builtin trees and shaders and thats why they have all those different pitfalls and combinations, so people can pick what works best for them

    if alphablend tecnique is important there is this technique where you render the foliage twice, one with cutout and another with alphablend to smooth the edges, looks okay but it's expensive, very common for character's hair and it would require you to write it (not that complicated)

    about all those directory dependencies i'm not sure, i don't see why would it need such specific directory since everything it needs should be in the resources folder, maybe someone can point it out better than me

    a bit offtopic, but i consider this to be of extreme importance for proper tree rendering
    http://wiki.polycount.com/VertexNormal#Foliage_Shading
     
  3. hptware

    hptware

    Joined:
    Dec 11, 2012
    Posts:
    107
    Hi Kebrus,

    Thanks for this. Normal bending is on our development list for Forester Pro. I agree manipulating normals makes leaf meshes look better.

    I also find it strange that models using ambient occlusion have to be in a certain directory. I am assuming their is some preprocessing involved and unity needs to know where to look. But I am guessing.

    I wonder how builtin foliage models are optimized. Forester provides the ability to optimize models in terms of polycount, but I guess there are some hidden rules. I find it a bit strange since other engines don't have these constraints on foliage models and yet unity has a vibrant asset store.

    I've seen lots of references to these hidden shaders but no clear way to access them. Again odd.

    Many thanks,
    HPTWare
     
  4. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
  5. larsbertram1

    larsbertram1

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

    just to correct some of your statements:

    Nature\Tree Creator Bark and Leafs
    - cast and receive real time shadows
    - leafs use custom lighting (wrapped around diffuse + translucency)
    - normal mapping
    - ambient occlusion is supported (has to be baked to vertex.color.a)
    - wind animation is supported (controlled by vertex colors and uvs – needs the tree script to be applied)

    Nature\Tree Soft Occlusion Bark and Leafs
    - cast real time shadows but do not receive any
    - no bump mapping
    (you can grab my free shader from the asset store which adds real time shadows and bump mapping at least to the bark:
    https://www.assetstore.unity3d.com/en/#!/content/929)
    - wind animation is only supported on trees added using the terrain engine

    personally i think there is no way around the tree creator shaders in case you want to create high quality trees that are lit nicely and support bending.
    however you have to set up vertex colors and uvs to match the shader’s needs.
    you can pm me if you need further information.

    lars
     
    metaleap likes this.
  6. hptware

    hptware

    Joined:
    Dec 11, 2012
    Posts:
    107
    Thanks Lars, I will pm you. Thanks for this really useful information.
     
  7. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    fyi:
    i have just released a small import script that will make custom made and manually modeled trees to be compatible with the built in tree creator shaders. it needs hierarchically structured models (flattened meshes will not be processed much convincingly..) but apart from that it is quite flexible:
    https://www.assetstore.unity3d.com/en/#!/content/21079

    or check a simple demo:
    http://dl.dropboxusercontent.com/u/2322017/treeimporter/treeimporter_simpledemo/treeimporter_simpledemo.html

    lars
     
  8. RickF

    RickF

    Joined:
    Sep 12, 2012
    Posts:
    33
    I am trying to manually bake some lightmaps into my leaf cards, and have had trouble finding an appropriate shader. Basically an unlit transparent/cutout shader with 2nd UV lightmap support and proper alpha blending/ sorting. Does this exist in any of your packs? Or any other packs out there that you are aware of?

    I have been searching and experimenting with a variety but have not found what I need. Any help would be appreciated.