Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Advanced foliage shader [released]

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

  1. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Just tried the newest version. Well done!
    Haven't tested it in detail yet. But the interactive bending in combination with static batching looks interesting! Just replacing the material during the interactive bending looks like a really decent solution!
     
  2. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Nice work Lars.
     
  3. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,974
    thanks dantus,
    in fact i was surprised that rendering did not get broken doing it this way…

    lars
     
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,974
    thanks janpec!
     
  5. Caliber-Mengsk

    Caliber-Mengsk

    Joined:
    Mar 24, 2010
    Posts:
    689
    I may have to buy this. Wouldn't work at all with my current project (scifi moba game) but may be useful down the line.

    Looks pretty awesome. Is there any way that you know of to place say, a bunch of grass on the terrain and still have it have the touch bend? (Beside my main moba project, I'm messing with the Oculus rift. It'd be really cool to have this working with the oculus rift and such.) Have you thought about maybe making a tool to place the objects like the terrain brush? Just something that raycasts and places stuff based on that?.... Just curious.

    Keep up the awesome work.
     
  6. larsbertram1

    larsbertram1

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

    thanks a lot!
    depends on what you mean with "bunch of grass"… the package already handles a lot of objects on which touch bending is enabled without a significant performance touch.
    there are already a bunch of tools on the asset store doing exactly this, so i have not focused on creating my own one. this might change in the future but is not top prio right now.

    lars
     
  7. larsbertram1

    larsbertram1

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

    while version 2.01 is still waiting to be approved by the asset store team bringing advanced wind animations which will give you much more variety even on manually placed game objects i have nearly finished version 2.02 which will come with advanced touch bending supporting the handling of multiple collisions on the same game object so animations will look much smoother if a plant is touched while still being in the touch bending animation of the first touch.

    watch the first preview: http://dl.dropboxusercontent.com/u/2322017/afs_v2/afs_v2_touchbending/afs_v2_touchbending_202.html

    lars
     
  8. larsbertram1

    larsbertram1

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

    i would like to just share a screenshoot from "ghost of a tale" – currently developed by seith using the advanced foliage shader v2 and touch bending.
    visit http://www.ghostofatale.com to find out more about the game.

    $vegetation01.jpg

    @seith: many thanks to you for being such a great "beta tester"!

    lars
     
  9. Play_Edu

    Play_Edu

    Joined:
    Jun 10, 2012
    Posts:
    722
    Looks pretty awesome.
     
  10. knocks

    knocks

    Joined:
    Jul 1, 2012
    Posts:
    23
    Will the afs Foliage Package be updated?
     
  11. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,974
    thanks!
    although i think that this acclaim belongs to seith.
     
  12. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,974
    yes, it will be.
     
  13. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I just played a little with the static foliage in combination with the interaction. It works like a charm when I select Standalone.
    When I switch to the Web Player, the bending becomes a little strange. It also happens with your demo scene "02 pro - touch bending demoscene_static batching enabled".
     
  14. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,974
    hi dantus,
    have you checked the player settings for the webplayer? static batching has to be enabled for this platform too.

    lars
     
  15. larsbertram1

    larsbertram1

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

    version 2.01 of the advanced foliage shaders is online which brings:
    - advanced wind animations giving you much more variety even on manually placed game objects
    - fixed terrain engine shader (specular power)

    lars
     
    Last edited: Aug 5, 2013
  16. knocks

    knocks

    Joined:
    Jul 1, 2012
    Posts:
    23
    Top stuff, thank you.
     
  17. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Ouch, thanks Lars. Don't know why it wasn't enabled...
     
  18. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,974
    puhh – i am glad that it was not a bug…
     
  19. larsbertram1

    larsbertram1

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

    i am still working on the next update of the package which will be a little bit delayed due to the fact that i have just started to implement a completely new feature: the afs grass shader

    this shader/script based solution will let you add grass like objects anywhere to your scene – not only on top of terrains – and supports procedural wind animation, translucency and real time shadows. but the most important feature is the adoption of the lighting of the underlaying geometry.

    as grass like objects mostly consist of some upright orientated planes standard lighting usually does not look very convincing.



    in order to improve the lighting the afs grass shader does not lit the models according to their own normals but takes those of the underlaying geometry into account. so if you place a grass model on a slope the shader takes the slope’s normal to lit the model – comparable to the way unity’s built in terrain engine lits grass.
    translucency which is computed using the original normals enhances the look even more.

    nice bonus: all this is done pretty fast for your grass models do not produce a lot of overhead as far as the handling of a bunch of game objects is concerned. you simply create some clusters of grass, combine all children so each cluster will be rendered with just one draw call.

    lars

    $01_placement.jpg

    $02_placement.jpg

    $03_slope.jpg

    $03_slope__lighting.jpg

    $04_pricision.jpg
     
    Last edited: Aug 6, 2013
  20. Deleted User

    Deleted User

    Guest

    Amazing stuff! Will the touch bending also affect the grass shader in your next update?
     
  21. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Great job! The new grass feature looks really interesting! :)
     
  22. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,974
    most probably: no. that would be a bit too expensive.
    but of course you can still use grass like meshes with the regular touch bending shader.

    lars
     
  23. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,974
    thanks seith.
    i think "independent" grass has been missing for a long time and i hope to fill this gap soon.

    lars
     
  24. larsbertram1

    larsbertram1

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

    just another little update on my current progress:
    i have been working on porting the "underlaying geometry adopting lighting" from the grass shader to the original foliage shader which turned out to request a different approach as this shader also supports specular lighting and normal mapping but finally i have got a version which i am quite happy with.

    so if you have some smaller mostly uprightly orientated plants placed on rather steep terrain slopes or any geometry this version of the advanced foliage shader will take care of much better and realistic lighting.

    Lighting on slopes: grass shader and advanced foliage shader side by side (both disabled and enabled)

    $06_lighting__grass_foliage.jpg


    Lighting on slopes:
    the left image shows how ground based lighting reacts to dynamic lighting for the direction of the sun has changed.
    the right image shows how ground based lighting reacts will react to multiple lights.

    $07_lighting__grass_foliage.jpg

    lars
     
  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,974
    btw.:
    it is not much encouraging to get that less feedback… :-(
     
  26. Rastar

    Rastar

    Joined:
    Sep 14, 2012
    Posts:
    73
    Oh no, don't be discouraged: The upcoming grass feature just tipped me over and I bought this shader from the asset store. Looking forward to the update!
     
  27. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,974
    thanks.

    the update will still take a little while.
    but meanwhile you can play with touch bending ;-) how do you like it so far?

    for your eyes only: normal debugging for grass and foliage shader

    $normal_debugging.jpg
     
  28. Boomsma1995

    Boomsma1995

    Joined:
    Mar 21, 2011
    Posts:
    95
    Hey larsbertram1,

    I am planning on buying your foliage shader but do you maybe know if its compatible with the Relief Terrain Pack.
     
  29. larsbertram1

    larsbertram1

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

    i have not tested it, but i am pretty sure that both packages are fully compatible. they just deal with completely different parts of the terrain engine so there is absolutely no interference.

    lars
     
  30. larsbertram1

    larsbertram1

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

    while version 2.02 is still under review of the asset store team and will probably come within the next days i have ported a very nice and handy tool that will help you to manually place any game object onto any terrain or geometry.
    the original version of this script called "Geometry Brush" has been posted by Matt McDonald, Owner, Chief Creative Officer and President of Heavy Water, www.heavyh2o.com a few weeks ago at:
    http://forum.unity3d.com/threads/183224-Using-Tree-gameobjects-vs-Unity-s-built-in-system/page10

    I only made several changes mainly in order to make it work with Unity 3.5 and to fit the needs of the advanced terrain shaders v.2. It now supports instantiated prefabs which keep their links as well as objects that do not have a collider.

    I hope you will enjoy it,

    lars


    Geometry Brush AFS v1.0
    https://dl.dropboxusercontent.com/u/2322017/GeometryBrushAFS.v1.unitypackage

    $geometrybrush.jpg
     
    Last edited: Aug 12, 2013
  31. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Great!!!
     
  32. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,974
    thanks, but most of the work was already done by Heavy Water.
    the geometry brush will be a great help for the upcoming new grass and ground lighting shader. it feels a bit like using the terrain engine but it gives you much more control as each object can be repositioned, scaled, rotated and deleted by hand of course.

    lars


    i will have to adjust the texture to make the manually placed grass fit the grass from the terrain engine but…

    $path.jpg


    just to show the resolution of the terrain’s detail texture: it is already 1x1m. of course you could easily raise it but that would end in a ridiculously high number of draw calls whereas manually placed grass always is 1 draw call per patch (or 3 if you have real time shadows) plus some overhead.

    $path1.jpg
     
    Last edited: Aug 12, 2013
  33. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Lars nice i really liked CE3 placement of plants on any object you wanted not just terrain and now you nailed it with new feature. Just a little suggestion would you be interested in doing far distance rendering as next feature especially for trees, where they can be rendered very far across terrain. It is really needed to get proper look of natural surface and would be appretiated as long as performance is OK.
     
  34. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,974
    hi janpec,

    thank you!
    as far as ras distance tree rendering is concerned: it is all about billboarding.
    basically unity biilboard system is not that bad as it handles a lot of different cases (fps/flightsim) ok.
    but personally there are 2 things i do not like about unity’s billboards:
    - billboards do not get aligned to the viewing angle when viewed from a first person perspective: they are always upright.
    this might be fixed by just tweaking the shader – but unfortunately that is out of my boundaries as whenever it comes to math...
    - billboards are not shaded correctly for if you have unity pro and realtime shadows enabled billboards do not even get selfshadowing.
    that is something only unity can fix – unless you drop translucency to make it less visible.

    so i would really like to see a billboard system similar to c4 engine or speedtree: real time lit billboards with normal maps, depth and shadow textures.
    but again: unfortunately this is nothing i can do on my own.
    may be the day will come and unity updates the terrain engine.

    cheers,
    lars
     
  35. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Woah, that vegetation placement tool allied with your shaders looks really cool! Lars, you are closing the gap with the CryEngine real fast. And I couldn't be happier about that... :)
     
  36. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,974
    hi seith,
    thanks a lot!
    i am glad that you find it useful.


    lars
     
  37. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Good joke :D
     
  38. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Well, just speaking for myself I might be able to use Unity's terrain engine IF:

    - It were possible to export the terrain as a plane mesh that you could tweak in a 3D app (being careful to only move vertices in the world up axis) and then re-import it into Unity. For me, using height maps is just not precise enough.

    - If you could easily create holes in the terrain by hiding some faces so you can create caves as meshes and put them under the terrain.

    - If the vegetation system worked as Lars' shaders with touch bending and all.

    - If you could manually place vegetation models exactly where you want them.

    Now there might very well be other reasons for which Unity's terrain doesn't seem to be well regarded in the community. Actually I'd be very curious to know what other limitations/problems you guys can think of.
     
  39. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,043
    The terrains were also performing like crap on mobile platforms. Not sure if it's the case anymore, but they were unavailable on mobile initially for a good reason. Lack of holes/caves are why I finally invested in a voxel engine instead!

    I bought this shader a little while ago, and must say I'm surprised the author hasn't been recruited by the Unity people yet, what with all the improvements he makes which should have been in the engine.
     
  40. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,974
    thanks for the flowers!
    a short review on the asset store might be a good start ;-)

    lars
     
  41. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,974
    and in order to push it a little bit further:
    i have added an advanced grass shader which 100%ly mimics the one from the terrain engine – so adding some very precisely positioned grass next to the one painted onto the terrain will be just a pleasure.
    the upcoming feature "reposition objects" will let you make changes to the terrain or any other underlaying geometry and keep your manually placed objects in sync just with a single click.
    applying "dry" and "healthy colors" to your grass objects will complete the advanced grass shader.

    the blue square shows the smallest detail brush (1x1m) in order to demonstrate that you would not be able to paint such a precise line of grass in the middle of the path as shown in the picture just using the terrain engine tools without causing a ridiculously high number of draw calls by raising the detail resolution of your terrain.

    $old_path.png

    lars
     
    Last edited: Aug 13, 2013
  42. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,043
    I'll be going on a review spree once I have time to work on the appropriate projects, and actually see everything working ;)
     
  43. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,974
  44. larsbertram1

    larsbertram1

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

    version 2.02 has just been approved by the asset store!

    it ships with:

    Advanced Touch Bending
    Touch bending now handles up to 2 overlaying animations giving you much nicer transitions if a plant is touched while still being in the touch bending animation of the first touch.

    Advanced Grass Shader
    Lets you add grass like objects anywhere to your scene – not only on top of terrains – and supports procedural wind animation, translucency, real time shadows and ground based lighting.

    Advanced Foliage Shader supporting ground based lighting
    Use this shader to enhance the lighting of smaller plants placed on steep slopes.

    lars
     
  45. larsbertram1

    larsbertram1

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

    now as version 2.02 is online i have found some time to put up a little demo for the ground lighting feature.
    i hope that it shows how you might benefit from the precise placement of grass objects, ground based lighting of grass and smaller foliage (you will have to rotate the sun!) and the advanced bending functions.

    you will see grass placed within the terrain engine in conjunction with manually placed grass objects, ground based lit foliage and some models using the regular shader.

    http://dl.dropboxusercontent.com/u/..._v2_groundlighting/afs_v2_groundlighting.html

    lars


    $demo_groundlighting.jpg
     
    Last edited: Aug 15, 2013
  46. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,974
    Hotfix for v2.02
    and even the upcoming v2.03

    when using the "advancedGrassShader Groundlighting v2" and a light intensity > 1.0 you probably will see some strange colors on the grass meshes due to a bug in the "GrassLighting.cginc".

    in order to fix this please open the cginc and find line:
    Code (csharp):
    1. c.rgb = s.Albedo * (translucencyColor * 2 + nl);
    you have to add the following line above:
    Code (csharp):
    1. nl = saturate(nl);
    so you will get:
    Code (csharp):
    1. nl = saturate(nl);
    2. c.rgb = s.Albedo * (translucencyColor * 2 + nl);
    save the cginc, then mark the "advancedGrassShader Groundlighting v2" in the project tab and recompile it using RMB click –> "Reimport".

    sorry for the inconvenience and thanks to gotstyle to make me aware of the problem,

    lars
     
    Last edited: Aug 24, 2013
  47. larsbertram1

    larsbertram1

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

    version 2.03 is online which mainly improves the wind animations and adds dry and healthy colors to grass as well as some very nice usability features.


    Changelog

    Setup Foliage Shader script
    - Enhanced wind animation: 2 sin waves that do not affect the y axis any more.
    - "WindMultiplierForGrassshader" and "WaveSizeForGrassshader" added

    Combine Children AFS script
    Advanced foliage shader
    - - Bake random bending values (main and secondary bending, edge fluttering and pulse)
    - - Bake scale so smaller instances will get less bending
    Advanced Grass shader
    - - healthy and dry colors for objects using the advanced grass shaders added
    - enhanced ground normal sampling function which will give you much better results on terrains
    - incorrect normals will be displayed yellow
    - you can simply realign your models with a single click
    - custom editor added

    Advanced Grass shader
    - Corrupted preview in deferred lighting mode fixed
    - "no Transluceny" version added: faster and perfectly fits the terrain engine grass

    Advanced Foliage Shaders
    - Primary bending along the wind axis will never go down to 0 if there is a windforce > 0. You might have to lower the general wind force a little bit (Setup script).

    AFS Foliage Tool
    - Completely redefine primary and secondary bending just using this tool. You do not have to do this using an external tool anymore.

    Make sure you apply the patch mentioned in my latest post.
    update is coming.

    lars
     
  48. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Great job, Lars! Can't wait to try it when I go back to work on vegetation assets... :)
     
  49. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,974
    thanks seith!

    lars
     
  50. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,974