Search Unity

Advanced foliage shader [released]

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

  1. wolfen231

    wolfen231

    Joined:
    Apr 22, 2014
    Posts:
    402
    Well I know everything has specular. That's simply light and shadows. But what I want is not to have a big flat shiny side face like it's a piece of plastic. Even with messing with the roughness map, I always get this result.

    So basically... I can't have tree planes with a flat surface at a sharp angle if I want to prevent this plastic shine?
     
  2. wolfen231

    wolfen231

    Joined:
    Apr 22, 2014
    Posts:
    402
    Also of note. When I disable IBL in the lighting settings for foliage shader setup, the planes are still lit up like that.
     
  3. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hi wolfen,

    setting the value in the roughness channel to 0 will completely remove specular highlights from direct lighting and (nearly) eliminate specular highlights in ambient lighting too like shown in the screen shoot below.

    however, you will have to take care about rain:
    adding rain will fade roughness towards 1 so all surfaces will become more shiny.

    so you can simply test how roughness influences specular highlight by setting the roughness channel to pure black.
    then switch to the "setup advanced foliage shader" script and fade in rain.

    lars

     
    wolfen231 likes this.
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    IBL only effects ambient lighting. direct lighting will always be the same.
     
  5. wolfen231

    wolfen231

    Joined:
    Apr 22, 2014
    Posts:
    402
    aaaaaaaaaaaaaaand there was the super simple and obvious thing. Rain was alread at 0.5. Turned it off to 0. Poof. Problem gone.
     
  6. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    fine!
     
  7. wolfen231

    wolfen231

    Joined:
    Apr 22, 2014
    Posts:
    402
    Yeah, like I said in first post. "I gotta be missing something really stupid and obvious."

    There it was haha.

    As usual, you are a ridiculously helpful dev. Many thanks as usual lars. =D
     
  8. hannahwilliams

    hannahwilliams

    Joined:
    May 25, 2014
    Posts:
    2
    Hi! This product looks fantastic, but I was hoping you could help me figure out if it would be compatible with my setup. We have an isometric 2d game (billboarding 2dtk sprites) without a terrain, which is why we're trying to find something to generate grass without one. Consider me 3d-handicapped: Is the billboard grass imported as just an image, or is a 3d mesh necessary? Additionally, if I can just use an image, can that be utilized with the bending/wind?

    Thanks so much, sorry if my questions are ridiculous, I haven't ventured too far from 2d development yet.
     
  9. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hi hannah,
    the grass shader does not support billboarded grass, sorry: you would have to rotate it according to your camera.
    and of course it needs a mesh – like anything that is rendered needs one (even if it looks 2d).

    lars
     
  10. Project-Mysh

    Project-Mysh

    Joined:
    Nov 3, 2013
    Posts:
    223
    Hi Lars,

    Any chance you can explain how we can implement your "CustomBending.cginc" to a custom shader (not surface shader)? There are some objects that we need the wind animation, but we cant use AFS shaders cause they are not foliage and dont need some of your shader functions.

    Thanks in advance for your understanding.
     
  11. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    well – the easiest way would be to write a surface shader... in this case you could simply change the lighting function, skip rain and add some of your stuff.

    but you can also have a look at the cg part of the foliage shader e.g.:
    Code (csharp):
    1. // vertexlit
    2. SubShader {...
    and do not forget to also include the shadow caster and shadow receiver passes.

    lars
     
  12. chilton

    chilton

    Joined:
    May 6, 2008
    Posts:
    564
    Hi, I get this weird z fighting issue with water+ and the advanced foliage shader on billboarded trees. Any suggestions?

    Screen Shot 2014-08-04 at 3.09.02 PM.png
     
  13. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hi chilton,

    you would either have to change the render queue of the billboard or the water shader as now the water seems to be drawn after the billboards. for transparent objects do not write into the z-buffer water will simply overwrite the billboards.
    you may have a look here to find out more about the rendering order:
    http://docs.unity3d.com/Manual/SL-SubshaderTags.html

    so the best order i can think of would be:
    - draw water first
    - then draw the billboards
    or can there be any billboard which should be hidden by water? i guess no.
    (well, i can think of trees placed very close to the border or even in the water – that would simply be not possible)

    so open the billboard shader and look for:
    "Queue" = "Transparent-100"

    open also your water shader and look for
    "Queue" = "Transparent....... xyz"

    "Queue" = "Transparent-100" is the queue which is also used by the original billboard shader and i do not really know why it is set to this (well, of course in order to solve some other z fighting issues but i do not know which exactly).
    so i would recommend to set you water shader to:
    "Queue" = "Transparent-101"

    that should solve your problem.
    but of course it could introduce some other problems depending on your level geometry and the used shaders.

    you will have to find out.

    lars
     
  14. PiAnkh

    PiAnkh

    Joined:
    Apr 20, 2013
    Posts:
    126
    Hi Lars,

    According to your documentation AFS is compatible with Skyshop up to 1.06 but what about the latest skyshop version 1.08? I am getting some weird effects when I have both is the same project (black tree billboards for example) so I am wondering if that is related.
    Do I need to delete the Skyshop grass replacement shader for example to ensure that the AFS shader is used?

    I have the impression that AFS is not compatible with DX11. Is that correct? I am getting flicking tree shadows if I use DX11.

    Thanks

    Ronan
     
  15. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hi there,
    right now version 1.08 of skyshop is not supported but i am looking into supporting at least diffuse ambient lighting using spherical harmonics instead of a diffuse cubemap.
    skyblending will most likely not be supported as i do not think that it is implemented very efficiently right now.
    not to mention that – if i do not want to skip supporting opengl – it simply does not work.

    you have to delete the skyshop grass shader, yes.

    dx11: i personally do not have any problems with dx11, sorry. which lighting path do you use?

    lars
     
  16. PiAnkh

    PiAnkh

    Joined:
    Apr 20, 2013
    Posts:
    126
    Ok, so I need to see if I can get back to Skyshop 1.06 for the two to work together right?
    I am using forward lighting. Strange than I am getting flickering then. I tested it out in a new project using your demo scenes. Maybe it is my graphics drivers.
     
  17. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    going back to version 1.06 is probably the best idea for the moment. the new update will cost me some time which i do not have right now.
    as far as dx11 is concerned: which shader produces flickering? i have just had a look at the demo scene and everything works like expected…

    lars
     
  18. bluemoon

    bluemoon

    Joined:
    Dec 14, 2012
    Posts:
    85
    Opps missed your reply. I was wondering were I could learn more about the Differed renderer shaders Depth normals ect.
     
  19. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    sorry, but i do not know any resources that deal with those shaders except from some threads on the forum.

    lars
     
  20. Grand-Alchemist

    Grand-Alchemist

    Joined:
    Aug 19, 2014
    Posts:
    1
    Does anyone know of any tutorials using Blender + AFS in Unity? I cannot seem to wrap my head around vertex color painting. I feel like I am missing something important, or that Blender's vertex painting is not very flexible. Any help would be greatly appreciated!
     
  21. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Well, Skyshop compatibility is fundamental to me until Unity5 comes out:
    Will AFS support the Unity5 ImageBasedLighting-workflow?

    What´s the latest Skyshop version that AFS are compatible to right now?
     
  22. larsbertram1

    larsbertram1

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

    afs supports skyshop 1.06. upcoming release will support some features of 1.08 like diffuse ambient lighting stored in sh – but no skyblending.

    as far as unity 5 is concerned: i am pretty sure that afs will support all unity 5 lighting features.

    lars
     
    Cascho01 likes this.
  23. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Blender does not have a flexible vertex painting system.

    -You can only paint one side so you have to start with a one-sided leaf model.

    -While there are curves you can use to edit to make a gradient you can only paint what is directly in front. So no easy full bending painting.

    -No alpha color.

    -Probably the most annoying part is that you can only paint with a brush. You cannot select vertices and make them a color.

    I have not been working with it forever so if anyone finds any issues that I was incorrect with let me know.

    What I have been doing is going to my leaf texture in GIMP and creating two black texture layers(green & blue) below the leaf layer. You can also export the uv layout of the leaf plane and put that on top of the leaf texture.

    I then paint the green(edge fluttering) on the edge vertices. Make sure you are on paint and not air brush.


    Then make your paint bush as big that the pointer will be at the top of your texture and the outer ring will be at the stem of the branch. Make sure to be using paint and the default GIMP brush Hardness 050 or Hardness 025. Paint blue(main bending) on the top corners and the center top. So you should just click three times. Sure there are better ways of doing this part so anyone let me know if I am not using the best method.


    Delete the branch layer and the uv layer. Then add a new layer, make it black, and name it red. Desaturate the blue and green layer and then change the image mode to greyscale. Then go to color-components-compose. Export that image anywhere you want.

    In Blender go to your tree or plant that uses that branch. Apply this new texture to the leaf material and set the mapping to extend. If there is bark add a black texture on that material. Then go to bake, change bake mode to Texture, and check Bake to Vertex Colors. You should see the correct colors in vertex paint mode.

    For the red I go to Add paint mode and choose red for the color. Lower the strength to something like .01. Then paint as carefully as you can the leaves you want to bend differently. Remember to paint on a one-sided leaf models. You can then make them two-sided after you are done with vertex painting. Sorry for the crazy long and confusing tutorial. If someone has a better way of doing it let us know. Hope this helps at least.
     
  24. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Almost forgot, when you are done with vertex painting go to the bottom panel next to the Vertex Paint mode you have View, Paint, and Brush. Click Paint then Smooth Vertex Colors in the open menu. That will get rid of any irregularities.
     
  25. larsbertram1

    larsbertram1

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

    for anybody who has been trying to make manually modeled trees behave like those created using the built in tree creator AFS might have been a help in the past.
    But now i have written a custom tree importer script which should make it much easier to get your trees into unity and benfit from all features you might know from the built in tree creator shaders including wind zones and advanced lighting.
    please have a look here:
    http://forum.unity3d.com/threads/coming-soon-custom-tree-importer.263224/

    lars
     
  26. WarGod100

    WarGod100

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

    Firstly thanks for a great system. We are currently building an underwater title and we using the AFS system for almost all of the underwater foliage. We have set-up a directional light with in the scene to project a cookie ( this is to create a water caustics effect). With a cookie set on the directional light, the foliage no longer uses the fog settings, illuminates brightly and does not fade out into the fog. Having the caustics project onto the plants really ties them into the scene and makes it very believable. How can we get this to work. Really appreciate any advice or help
     
  27. WarGod100

    WarGod100

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

    We have spent more time looking into this problem. If the Fog is set to White and you have A Cookie texture set on the Direct Light it works and the plants fade into the fog correctly. However if the fog colour is changed ( blue) and you have A cookie texture set on the direct light, Fog does not appear to work correctly. Please can you advise how we can get around this.
     
  28. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hi WarGod100,

    sorry for my late reply – i did not get any notification... sometimes the new forum just acts very strange.
    but back to your problem:
    have you set your player settings to "linear color space"?
    if so please switch to "gamma" and check if the problem has gone.
    it might be that unity just passes the color in the wrong color space...

    lars
     
  29. WarGod100

    WarGod100

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

    I tried setting the colour space to gamma and and the issue still persists ( i tested both).
    To make sure i am not doing anything wrong i am testing it out in your Pro touch bending scene.
    This is what i am doing to reproduce it.
    1- Open up the directional light and add a Cookie Texture, set the cookie size to something small so its easy to see on the plants and the Intensity to 1
    2- Enable fog in the Render settings
    3- Change Fog Colour to Red
    4- Set the fog density to 1

    I have attached a image for reference

    I am sure its something small, but its driving us nuts.
     

    Attached Files:

  30. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hi there,
    fog is a bit more complicated than you would expect as it is not documented at all.
    but i am working on it and it should be fixed with the upcoming update.
    however that could take a little while... i have to get anything up and running. ten there will be the approval process which alone might take up to 5 days.

    meanwhile you could try to edit the "Afs_CustomFog.cginc" file.
    (please make a back up first!!!!!!)
    select all code and replace it by the following:
    Code (csharp):
    1.  
    2. #ifndef AFSCF_CG_INCLUDED
    3. #define AFSCF_CG_INCLUDED
    4.  
    5. half4 unity_FogColor;
    6. half4 unity_FogDensity;
    7. half4 unity_FogStart;
    8. half4 unity_FogEnd;
    9.  
    10. void customFog (Input IN, LeafSurfaceOutput o, inout fixed4 color)
    11. {
    12.     fixed3 fogColor = unity_FogColor;
    13.     #if defined (UNITY_PASS_FORWARDADD)
    14.         fogColor = fixed3(0,0,0);
    15.     #endif
    16.     // Fog Exp2
    17.     #if defined (FogExp2)
    18.         float f = IN.myuv_MainTex.z * unity_FogDensity;
    19.         float fogFactor = exp2(-f * f * 1.442695);
    20.     #endif
    21.     // Fog Exponential
    22.     #if defined (FogExpo)
    23.         float f = log2(1 - unity_FogDensity);
    24.         float fogFactor = exp2(f * IN.myuv_MainTex.z);
    25.     #endif
    26.     // Fog linear
    27.     #if defined (FogLinear)
    28.         float fogFactor = saturate((unity_FogEnd - IN.myuv_MainTex.z) / (unity_FogEnd - unity_FogStart));
    29.     #endif
    30.     color.rgb = lerp(fogColor, color.rgb, fogFactor);  
    31. }
    32. #endif
    save the file and reimport all afs shaders.
    i have to admit that i am not sure if it will work for you as i have taken this code from my current development version (which is not the one you have). unfortunately i do not have access to the current version from the asset store.
    lars
     
  31. WarGod100

    WarGod100

    Joined:
    Mar 25, 2013
    Posts:
    8
    Works Like a charm. Thank you so much for this! This is really going to take our game to the next level.
    I really appreciate you taking the time to help us out here and going the extra mile.
     
  32. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
  33. Fatferret

    Fatferret

    Joined:
    Apr 20, 2013
    Posts:
    18
    Hi,

    I'm interested in buying this plugin but I would first like to know what happens with placement of foliage on objects if you move the object in the editor. Will it automatically adjust ? and what if the object moves up? Will the foliage end up inside?
     
  34. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hi there,
    moving objects:
    a) you could group foliage and object and move those together.
    b) you could move your object, then hit "realign" to reposition the foliage according to your object’s position.

    lars
     
  35. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Hi Lars,

    I have a problem with the shading of the billboards which strongly differs from the geometry shading:



    (Sorry for the awful gif)

    I believe it´s because of the self illuminated billboards which appear darker than the geometry trees.
    But I don´t find any way to adjust the billboards brightness/texture.
    The light reference is setup correctly to the sun.
    (I don´t want to adjust the main sunlight because it will affect the whole project...) .
    Could also be that it looks like there´s an unwanted specular on the geometry trees?

    Next thing is the dense shadow of the billboards compared to the geometry trees.

    Please help, thanks!
     
    Last edited: Aug 25, 2014
  36. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    I think i found out what causes the problem.
    I have placed the trees by script using the terraindata.class:

    terrain = GetComponent(Terrain);
    terraindata = terrain.terrainData;
    terraindata.treeInstances = new TreeInstance[instances.Count];
    terraindata.treeInstances = myInstances.ToArray(typeof(TreeInstance));
    terraindata.RefreshPrototypes();

    That way I can place (and modify) the trees in 3dsmax and import them as a dummy-list, which is a very
    convenient and save workflow to me. I was also setting a color variation with

    instance.color.r=1-Random.Range(0,0.1);
    instance.color.g=1-Random.Range(0,0.1);
    instance.color.b=1-Random.Range(0,0.1);

    Placing the trees with the AdvancedFoliageShaders of course still works but the trees shading behave like mentioned above and my coloring only apllies to the billboards.

    Any way out of this (Lars)?
     
  37. larsbertram1

    larsbertram1

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

    which color space do you use?
    afs should be optimized to work in linear color space.

    strong specular and gloss values on mesh trees will most likely corrupt the fading: mesh trees are lit per pixel, billboards are lit per vertex.

    as far as the shadows are concerned: you could edit the shadow texture of the tree leaf material.

    lars
     
  38. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    I was able to eliminate the color-problem by setting instance.lightmapColor instead of instance.color when instancing the trees by script.

    Thanks!
     
  39. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hmm, instance.lightmapColor definitely is not the right place to put color variation to.
    but as long as it works for you...
     
  40. AKAGT17

    AKAGT17

    Joined:
    Sep 8, 2014
    Posts:
    40
    Hi,
    Lars, I am currently using unity version 4.3.4f1 but downloaded the recent v3.02 which isn't working ( assets
    are black and no dynmics) due to incompatability. Is there a way of downloading an earlier iteration of your foliage shader as I wont be able to update my version of unity?

    Thanks much obliged :)
     
  41. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hi there,
    please send me your invoice number and i could provide a link to version 2.042.

    lars
     
  42. AKAGT17

    AKAGT17

    Joined:
    Sep 8, 2014
    Posts:
    40
    Hi Lars, I have sent a private message into your inbox with my invoice number thanks, please refer from there
     
  43. Jochen-Hanisch

    Jochen-Hanisch

    Joined:
    Oct 7, 2013
    Posts:
    25
    Hi Lars,
    don`t know if this is a Afs thing or is it more a unity problem ad all..
    In the picture you can see it. Sometimes there are holes in the billboards, which are popping. There - not there, correct rendering... Do you can imagine what the problem is?
    The hole setup is scaled to 1:10, may be this is a problem?

    tia jochen
     

    Attached Files:

    Last edited: Sep 10, 2014
  44. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hi jochen,

    as the name of your screen shoot says: it looks like a z-fighting problem.
    and i am sorry that i can not do anything about that: unity sorts the billboards, then those get rendered.
    as billboards use a transparent shader the is no z-testing in the shader itself. so the billboards have to be sorted correctly by the terrain engine.
    the only solution i can think of: lower the density of your trees...

    sorry about that,

    lars
     
  45. Jaqal

    Jaqal

    Joined:
    Jul 3, 2014
    Posts:
    288
    Hello Lars, I have an issue with AFS that I am hoping you can help me with. It may already have been discussed on this forum but I have not seen it. The tree on the left is using the simple terrain tree shader and has been vertex painted. The one on the right is using unity's default terrain shader. Both placed with the brush. As you can see the billboard is much wider making my billboard transitions quite ugly. The trees have vines hanging from them but unity's seems to work fine with them so I am assuming I missed something. What do you think the problem may be?

    UglyBillboard.jpg
     
  46. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hi jaqal,
    to me both trees do have the same resolution as far as the billboard texture is concerned and both look fine or ugly as you may say. so just to make it short: i do not get the point... sorry.
    so what do you exactly mean?

    lars
     
  47. Jaqal

    Jaqal

    Joined:
    Jul 3, 2014
    Posts:
    288
    Sorry if I wasn't clear. They are billboards of the same tree. As you can see the one on the left using the simple tree shader has no transparency between the trunk and vines. Its like one flat plane where but with unity's shader you can see through. So when the trees transition to or from the billboard it is extremely noticeable. The billboard with the simple tree shader has no "holes" in it like unity's so when it changes to a mesh it pops in and ruins the transition.
     
  48. Jaqal

    Jaqal

    Joined:
    Jul 3, 2014
    Posts:
    288
    The areas in the red circle should match to create a seamless transition between mesh and billboard.
     

    Attached Files:

  49. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hi jaqal,
    well, i can see some "holes" between trunk and vines but far less than on the tree rendered using unity’s shader ;-).
    and as you can see on the leafs: transparency is handled correctly by the shader.

    have you already checked your alpha texture? especially those parts which belong to the vines?
    you may try to sharpen those.
    this effects of course both: the rendering of the billboard texture and the rendering of the mesh tree.

    alternatively you may even edit the "AfsSimpleTerrainTreeRendertex IBL.shader".
    it uses a fixed _Cutoff = 0.5 value. raising this value will most likely seperate the vines from the trunk but at the same time it will make the leafs "shrink". so please have a look at your alpha mask first.

    lars
     
  50. Jaqal

    Jaqal

    Joined:
    Jul 3, 2014
    Posts:
    288
    Aha I should have seen that the leaves transparency was already being correctly handled...sorry I missed that!
    I did however fix my problem and it was very simple for once! If anyone else experiences something similar all I did was change my import settings to calculate normals. It completely fixed the problem and now the billboards fades perfectly with the mesh.

    Thanks for the help and great product lars!