Search Unity

Advanced foliage shader [released]

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

  1. nhf75

    nhf75

    Joined:
    Apr 5, 2013
    Posts:
    35
    I made this video for best explanation
     
  2. larsbertram1

    larsbertram1

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

    thanks for the video.

    but as it clearly shows: most errors and warnings are caused by some unisky shaders – nothing i can do anything about.
    and the 1 warning that is related to ANY billboard shader is NOT related to the afs billboard shader: because if you select it in the project tab it shows up in the inspector and does NOT have any warnings or errors.
    so i guess that you have another billboard shader in your project that got errors but still overwrites the afs billboard shader unless you manually force it to be recompiled.
    solution: find the other buggy billboard shader and get rid of it.

    btw.: great that you are using xvid! i happen to know the mastermind behind it and i have to say: that is really a great piece of software.

    lars
     
  3. nhf75

    nhf75

    Joined:
    Apr 5, 2013
    Posts:
    35
    Problem solved!
    1. You are right! i removed the billboard shader of the Unistorm and your shader returned work again. I see the shadow in the game view and in the editor view. It works fine!
    2. Other shader has incompatibility too. The billboard shader of Terrain Composer's Demo.

    The curious is when i wore unity 4.3.4, it did not happen.
    And Yes! The xvid is fantastic!
    Sorry for my english.
    nhf75.
     
  4. larsbertram1

    larsbertram1

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

    you don not have to apologize for your english – at least not to me as my one is probably not better than yours.
    and i am glad that you have solved your problem.
    and i am also glad that it was not caused by the afs shaders ;-)

    unity 4.5 <> 4.3.4: shader compilation has dramatically changed.
    but of course this should not cause any side effects like the one you have described.
    may be you have renamed some folders?

    lars
     
  5. nhf75

    nhf75

    Joined:
    Apr 5, 2013
    Posts:
    35
    All i did is delete the Unistorm\Shader\Current\Billboardtree.shader. This file is started with line: Shader "Hidden/TerrainEngine/BillboardTree" {... This is the same line than your shader has, causing conflict because both shaders solving same thing. The shader of Terrain Composer too.
     
  6. laurent-clave

    laurent-clave

    Joined:
    Jul 18, 2011
    Posts:
    280
    Hi !

    I create a palm with blender



    The render of this tree is no bad.
    But, we can not create random rotation of tree.
    I think the best method is to create the tree with the tree creator, no ?
    But I could not have animations with shader (vertex paint)

     
  7. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    ups, how do the errors look like?
    lars
     
  8. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi laurent,
    i am not sure if i get you right. so sorry if i do not answer your question. nevertheless i will try to:

    using the tree creator to create trees enables you to use the (built in or afs) tree creator shaders – which will give you the nicest bending available.
    the tree creator lets you quickly model different versions from a given master but it is just a pain when it gets to details:
    changing the number of faces used for the trunk? making the branches always being connected to the trunk even with strong wind settings?
    the tree creator will automatically add vertex colors and a 2nd uv set to control bending and ambient occlusion.
    however: placing randomly rotated trees within the terrain engine is not supported due to the way billboards are handled.
    no matter how you create your trees, they never get rotated when added to the terrain. you will have to create rotated prefabs/models and add those to the terrain. but do not go crazy about this: any additional tree model will raise memory consumption and rendering time because extra billboard textures have to be calculated.

    lars
     
  9. ph0b0s

    ph0b0s

    Joined:
    Dec 18, 2013
    Posts:
    19
    Hi, we have an issue that, after many research and almost two days of work wasted, is related to AFS shader.

    Its really easy to reproduce, in an empty project you just need to import the afs plugin, create a terrain, add grass to it (grass for terrain of afs for example) and move the terrain. On the 0,0,0 world point, all looks great. But if you move the terrain the geometry is there but you cant see anything. In our project we have a large amount of tiles so its not an option to have all the tiles located on the origin. Here are some pictures that show the issue:
    afs_bug01.jpg

    afs_bug02.jpg
    afs_bug03.jpg
     
  10. larsbertram1

    larsbertram1

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

    indeed you have found a bug.
    sorry about that.

    hot fix:
    edit the "AfsWavingGrassTerrainEngine v3" shader

    find:
    fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * IN.color;
    o.Albedo = c.rgb;

    and replace it with:
    fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
    o.Albedo = c.rgb * IN.color.rgb;

    not perfect but it will make the grass show up again.
    i will look for a proper solution when i find the time to do so.

    lars
     
  11. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533


    Larsbertram1, your shader is awesome. Its like 70% of the stuff here. I'm also using this with skyshop so if anyone is curious about how they play together I think they mix fine. I'm using the non terrain one.
     
  12. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    thanks djweinbaum.
    your scene looks beautiful! i would like to see some more pictures.

    lars
     
  13. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    Thanks! You're partially to blame for that. I just came out of internet darkness with my game so I only have a few. These are the ones from my site so far.





     
    Baldinoboy likes this.
  14. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    amazing screenshoots and great assets!
     
  15. norby

    norby

    Joined:
    Jul 10, 2006
    Posts:
    277
    Hi djweinbaum

    Beautiful work, what do you use for your sky

    Thanks

    Norbert
     
  16. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    thanks. Its layers of domes with various shaders. A dome for the clouds, another for the atmosphere, then nearby celestial objects are actual geometry (even many stars are actual geo), then a final dome for far space and background stars. I used shader forge for the highly specialized shaders of each dome.
     
  17. norby

    norby

    Joined:
    Jul 10, 2006
    Posts:
    277
    Hi djweinbaum

    I have to say your environment looks beautiful , did you make your own trees ?
    Lars shaders do an excellent Job

    Norby
     
  18. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    Indeed it does. Yeah, I made all my own assets.
     
  19. wheels

    wheels

    Joined:
    Jan 20, 2013
    Posts:
    29
    Hey Lars, great stuff, would it be ok if i emailed you some questions? im having some issues with afs and I am kind of under nda so i dont want to just post screenshots on the forums just yet.
     
  20. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    ok, then send me an email.
    lars
     
  21. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    @djweinbaum

    Those are beautiful, its great to see this shader collection used so well. I'd love to, some day perhaps given i've no idea how open you wish your approach to be, have an insight as to what shaders you used and how, and how you used the pbr factors of the shaders if you used them to get such amazing results - extremely impressive and as i'm such a newcomer to using foliage specific shaders to get good results, insight would be invaluable
     
    djweinbaum likes this.
  22. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    And i just checked your site to find out you're making, since my experience with Dear Esther and the OR, my favourite kind of game. I'm really somewhat hoping No Man's Sky is this sort of thing should I choose and you're using AFS to great effect for this genre - exploration games by their very nature have to be visually amazing, i wish you a lot of luck and i'll bookmark your site. All I suggest is adding Oculus support if it's not intended already because it can have a profound impact on the experience of that kind of game.
     
  23. laurent-clave

    laurent-clave

    Joined:
    Jul 18, 2011
    Posts:
    280
    Thank Lars ;)

    Great work Djweinbaun !!

    My currents with AFS :


    I love this shader !!!
     
  24. Ramsdal

    Ramsdal

    Joined:
    Oct 18, 2013
    Posts:
    251
    Hi Lars

    I assume that there is something that I am doing wrong. However the "Translucency Color" options seems to have very little impact on the color since I updated to the new version.

    I have tried using a blank project only with your shader (both the old and new version) and in the new version changes to the "Translucency Color" is barely visible. Where in the old version it is much more obvious.

    I have tried to disable IBL and other things that I could think of. Is this change by design - or am I missing some option somewhere?

    Best Regards!
     
  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    well, the difference between translucency between v2 and v3 should not be that much.
    may be you have not setup the tans spec map correctly?
    if you use linear color space this texture has to bypass srgb sampling.

    but as i have completely rewritten the lighting it will look differently of course.

    lars
     
  26. bluemoon

    bluemoon

    Joined:
    Dec 14, 2012
    Posts:
    85
    Hello Lars,

    I'm getting a shadow error since updating to version 3.01.
    When in deffered rendering mode shadows show through foliage.
    The only chages I made to the demo scene is adding the Lux setup script and setting up RTP shaders.
    I'm using Liner Lighting and the error happens in both DX11 and DX9.

    foliage3_defferedShadowError01.jpg foliage3_defferedShadowError01.jpg


    Versions
    Unity 4.5.1
    Foliage 3.01
    Lux 1.011
    RTP 3.01c
     
  27. larsbertram1

    larsbertram1

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

    that definitely looks like a problem caused by the cameradepth and cameradepthnormal shaders:
    lux ships with its own replacement shaders just like afs does.

    so please make sure that you remove the cameradepth and cameradepthnormal shaders from the lux package.
    the shaders that ship with afs contain all render path definitions needed by lux.
    if you have any other shader package (rtp is not involved here) that ships with its own cameradepth and cameradepthnormal shaders make sure that you merge those files with the afs depth shaders.

    lars
     
  28. bluemoon

    bluemoon

    Joined:
    Dec 14, 2012
    Posts:
    85

    Thanks for the fix.

    On a side note do you know any good place to learn more about these kind of shaders?
     
  29. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    what kind of shaders do you mean?
     
  30. Teila

    Teila

    Joined:
    Jan 13, 2013
    Posts:
    6,932
    Hello, I purchased your Advanced Foliage Shaders and whenever I put them in my project, before assigning them or anything, the Unity Tree Creator trees billboards turn white. I delete the package and the billboards are fine. Again, I have not even applied any of your shaders to my my meshes yet.

    I really want to use your shaders so my grass meshes can move with the wind but I really don't want white tree billboards in the distance. I cannot use your tree shaders because these are trees released by Big Environment and the leaves and bark on not on separate textures. I tried this in another project and the leaves were bark colored. :)

    Anyway, is it possible to use your shaders only on grasses and not trees without it affecting my trees in the distance? Thank you.
     
  31. larsbertram1

    larsbertram1

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

    the afs billboard shader will automatically replace the built in one (as it has to!) whenever you import the package.
    so you would have to import the package (which will make your billboards turn white), then find: "Advanced Foliage Shader v3" --> "Shaders" --> "hidden Shaders" --> "AfsBillboardShader v3.shader" and rename it e.g. "AfsBillboardShader v3._shader" in order to disable it.

    however disabling the billboard shader won’t let you use smooth billboard transitions or camera aligned billboards.

    and as far as i know it is no problem to use the afs tree and billboard shaders on trees provided by the big environment package as those are modeled using the built in tree creator.
    (bark and leave textures are finally combined by the tree creator into one atlas which is just fine!).

    so i highly recommend that you read the docs and find out how to assign the afs tree shaders to already existing trees.

    and please have in mind: the afs tree and billboard shaders use their own fog function which also might lead to white billboards – depending on your general fog settings.

    lars
     
  32. Teila

    Teila

    Joined:
    Jan 13, 2013
    Posts:
    6,932
    Thank you. I did manage to get the white billboards to go away without doing really anything other than setting up the foliage shaders. Yay! I did read carefully through the documents but will try again with the billboard shader on the GE trees. When I created the new material previously, it required that I add the textures and that is when things looked odd. But as I said, I will try again. Oddly, I find with Unity sometimes a second try yields the best results. :) I appreciate your quick response.
     
  33. wolfen231

    wolfen231

    Joined:
    Apr 22, 2014
    Posts:
    402
    Hey there,

    With afs 2, I am using the afs grass shader no trans. For some reason the grass models are violently shaking. Any suggestions where to look to fix this on my end?

    As far as I know these have no vertex painting (are just simple triangles with textures on them).
     
  34. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902

    the grass shaders need also vertex colors. but here it is vertex color alpha which controls the bending.

    lars
     
  35. wolfen231

    wolfen231

    Joined:
    Apr 22, 2014
    Posts:
    402
    Thanks for the reply. I was afraid of that haha. Not sure how i will vert paint all this foliage.
     
  36. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    I love Blender but it does not believe in vertex painting. Along with a lot of vertex painting problems there is no vertex alpha:(. Strange that they do not address this.
     
  37. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    if blender does not allow to paint /export vertex color alpha you can modify the afs foliage tool to write to vertex color alpha (instead of vertex color blue which controls bending when using the foliage shaders)

    make a backup of "AfsFoliageTool.cs" and edit the original.
    find: "public void AdjustBending ()"
    there find:
    Code (csharp):
    1. colors[i].b = 0.0f;
    and change it to:
    Code (csharp):
    1. colors[i].a = 0.0f;
    find:
    Code (csharp):
    1. colors[i].b = Mathf.Lerp (0.0f, maxBendingValueY, curvY.Evaluate(vertices[i].y/bounds.size.y) );
    and change it to:
    Code (csharp):
    1. colors[i].a = Mathf.Lerp (0.0f, maxBendingValueY, curvY.Evaluate(vertices[i].y/bounds.size.y) );
    find:
    Code (csharp):
    1. colors[i].b += Mathf.Lerp (0.0f, maxBendingValueX, Length );
    and change it to
    Code (csharp):
    1. colors[i].a += Mathf.Lerp (0.0f, maxBendingValueX, Length );
     
    twobob and Baldinoboy like this.
  38. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Awesome. Thanks lars.
     
  39. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    your are welcome!
     
  40. wolfen231

    wolfen231

    Joined:
    Apr 22, 2014
    Posts:
    402
    So I seem to have the v alpha working (boy is it sensitive for the little grass blades. Had to paint down to 3 and it is still a bit "strong" looking. It's just not violent looking now.

    However, the grass is still showing as black. I can see the normals pointing up with the debug, and they are from what I can tell intersecting with the ground (if not just a tad above). Any suggestions on that fix?

    Oh also the directional light I use is a bit dark, but not THAT dark and its ALL the grass thats going black like that. It covers a good amount of area.
     
  41. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    black grass: make sure that vertex color rgb is set to 1,1,1
     
  42. wolfen231

    wolfen231

    Joined:
    Apr 22, 2014
    Posts:
    402
    Ahhh yes that did it. However, I also spotted another part of the problem. All the ones I was using had the main color set to black.

    Do you recall the default "main color"?

    One more thing. I can't get over this "jittery" shaking on the grass goundlighting shader. Its like its a micro seizure. I have the alpha at 2 now and it just seems so.... obvious and strange looking. Any suggestions?

    Anyhow thanks for the quick replies and help so far. You rock!

    Edit: Nevermind. I got it now. I was adjusting only the main wind stuff and not the ones for the foliage shader (which I did have on there, just not adjusting them haha)
     
    Last edited: Jun 23, 2014
  43. wolfen231

    wolfen231

    Joined:
    Apr 22, 2014
    Posts:
    402
    Sorry. I have a new problem haha.

    I am using a fern model now.

    -V Alpha set to 0 at base and 3 (on a 0-255 value) on the tips.
    -V Color set to all white (255)

    When I add the combine children to the game object group they are under they all just vanish. This is with either Advanced Foliage Shader or the Grass Groundlighting shader. When I look at the scene hierarchy they are all just gone. I don't see a combined mesh in the list. It is just emptied out.

    If I un-check destroy children they obviously don't disappear. So it seems to me the compile script is not compiling them for some reason. This behavior does not happen with the grass models.

    Any ideas?
     
  44. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    3 in a range from 0 – 255? that is pretty much nothing i guess…
    i would always use values around 128 (mid bending) and adjust the wind params to make grass fit the foliage.



    if you want to use the combine children script please make sure that your objects are NOT marked as "static".
    and please make sure that the generated mesh will not break the number of allowed vertices (65000).
    have a look at the console to find out what is going wrong.

    lars
     
  45. wolfen231

    wolfen231

    Joined:
    Apr 22, 2014
    Posts:
    402
    Yeah... I have a bunch of tweaking to do right now on the winds. :p

    They are definitely "not" marked as static and no errors / warnings are showing in the console. It is quite baffling. Maybe it has gone over the 65000 limit... but I just cant imagine that. Ill try to split the group up in half and see what happens.

    Thanks for the input again. You are an amazing dev to keep following up with your users so much.

    Cheers.
     
  46. larsbertram1

    larsbertram1

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

    if there are no errors logged in the console the script just should work fine!(?)
    the only 2 limits i have ever run into i have described above: static batching and vertex count limit.

    so i would suggest: check the demos first.
    if they run correctly: replace one single prefab with your own one.
    if the meshes disappear:
    - check your pivot points
    - check your vertex colors

    alternatively you can send me one of your prefabs so i will have a look at it.

    lars
     
  47. wolfen231

    wolfen231

    Joined:
    Apr 22, 2014
    Posts:
    402
    Yeah this is all what's baffling. I have a different group (that is a bunch of grass triangles and something a little more complex) that is combining just fine. In fact it seems to break that group into a few separate combined meshes.Can I not have two groups, two instances of the combiner script going?

    Fern... empty
    grass... two separate combined.

    This is so strange haha.
     

    Attached Files:

  48. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hmm, the script should automatically break up the assigned prefabs into several groups if you use different materials.
    so if you have grass and foliage grouped under one single game object the script should create 2 meshes: 1 for all grass objects and one for all foliage objects.
    does it do this?

    lars
     
  49. wolfen231

    wolfen231

    Joined:
    Apr 22, 2014
    Posts:
    402
    Yes, that explains the LD Grass section. There are two different textured models in that group. Still doesn't explain the ferns haha. Still need to split it up and see if that's the issue.
     
  50. wolfen231

    wolfen231

    Joined:
    Apr 22, 2014
    Posts:
    402
    Ok, so I broke the group into 3 total groups. (Duplicate, remove, then move a selection to new group). Total vert count in one of them is only about 20,000. So I am not sure why it's not working. The "prefab" is using the the grass shader ground lightning no trans. Not static.

    Should it be layered or tagged?