Advanced foliage shader [released]

Version 3.02 is available!

Version 3.02 is now available – including physically based shading, physically based wetness, image based ambient lighting, advanced multi touch bending, ground lighting and enhanced billboarding for terrain trees

The advanced foliage shaders gives you the possibility to use all modern features of vegetation shading on imported, handmade models – be it on top of the terrain or any other arbitrary geometry.

Watch the shaders in action
all shaders: http://dl.dropboxusercontent.com/u/2…demoscene.html
touch bending: http://dl.dropboxusercontent.com/u/2…nding_202.html
ground lighting and manually placed grass objects: https://dl.dropboxusercontent.com/u/…dlighting.html
tree and billboard shaders: https://dl.dropboxusercontent.com/u/…reeShader.html

Get them here

Key Features

  • Optimized for performance: Just 1 material per object = 1 draw call. Support for static and dynamic batching, occlusion and layer based culling as well as LODs. Combine Meshes statically or at runtime to increase performance and draw whole clusters of plants within a single draw call.
  • Unmatched visual quality: The shader not only enhances the visual quality of plants manually placed as game objects but also to your plants placed within the built in terrain engine. Plants are added as detail meshes and support all lighting features except from casting shadows.
  • Some more realism: Apply touch bending to any plant placed as single game objects to let it interact with your player and npcs.
  • Easily setup your models following the step by step instructions.

Simply paint your plants on top of the terrain or any arbitrary geometry
Make sure you get the free “Geometry Brush AFS” tool: a very nice and handy tool that will help you to manually place any game object onto any terrain or geometry – originally posted by Matt McDonald, Owner, Chief Creative Officer and President of Heavy Water, www.heavyh2o.com, but optimized for the use with the advanced terrain shaders.
https://dl.dropboxusercontent.com/u/...1.unitypackage




Changelog (version 2.04)
Enhanced billboarding for terrain trees.
Place terrain trees even on arbitrary meshes and benefit from the built in billboarding
AFS Foliage Tool improved.

Changelog (version 2.03)
Enhanced wind animations.
Get much more variety when using the AFS Combine Children script - like bending according to the instance’s size.
AFS Foliage Tool improved.

Changelog (version 2.02)
Improved Touch Bending.
Advanced Grass shader added.
Advanced Foliage Shader supporting ground based lighting added.

Changelog (version 2.01)
Improved Wind Variation.
Fixed: Specular Power now also works on plants placed within the terrain engine

Changelog (version 2.0)
Touch bending added.
Improved wind bending.
Specular power added to simulate wet effects.
Minor fixes and enhancements.

Old demo (version 1.0)
http://bit.ly/K0osHC

The old demo shows some other plant models like maple sapplings, blackberry bushes, weed and nettles all rendered with the advanced foliage shader (both: placed as single game objects and placed within the terrain engine) next to the new grass shader which allows even complex geometry without any restrictions in uv mapping.

lars

Hotfix for version 3.01
(or upgrade to version 3.02)

if grass disappears on your terrain (which happens if you have multiple terrains or move the one you have from 0,0,0 to any other position) you unfortunately will have to edit and fix the 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.
next version will come with a “real” fix.

Attached Images


2 Likes

Looks pretty sweet!

Sounds interesting indeed. Can’t wait to get to the office and check it out properly

Matt.

thanks!

Awesome just awesome. Now this isnt imitation of Cryteks shader, but this is one step beyond already especially for Unity users, becouse we can use AO and Cryengine users cant:smile: Lars one question though…How do you bake AO to vertex color alpha, if wind bending is already using it, or isnt it? Could you please explain shortly how do you bake AO in vertex color alpha with max for example?

hi janpec,

in fact vertex color alpha is not used for bending –*only for ambient occlusion.
(may be i will add a second shader which supports absolutely correct bending but no ambient occlusion in a later version.)
in order to bake ao i use a small script within unity.
you can find it here: http://adrianswall.com/shared/unity_vertex_ao.rar
and here is a short video showing it in action: http://www.youtube.com/watch?v=eeKQAXg-Qo8

lars

why are you so awesome?

Isnt his fault, he was probably born that way:P

Thanks for AO link, i will defenetly test it somewhen soon.

here the link to the asset store: http://u3d.as/content/forst/advanced-foliage-shader/2Sj

added some more words of explanation to the first post…

I’ve been playing with this stuff all night. Integrating it into our sandbox mmo project?p=906688&viewfull=1#post906688). And this is what I’ve come up with!

Damn Lars you’ve done it again, this stuff is awesome! It really helps bring the scene to life. :slight_smile:

I did some tweaks here and there, specular lighting is scaled down to 0.3 I could have fixed the ferns in photoshop too but they were practically glowing in my setup. I’m not sure 0.3 is the right number but 1.0 is certainly too high for my taste.

When recording at a fixed frame rate the leaf wave timing got seriously bungled by the SetupFoliageShader.js script. Line 36 should be changed to:

var WindRGBA : Color = Wind *  ( (Mathf.Sin(UnityEngine.Time.time * WindFrequency) + Mathf.Sin(UnityEngine.Time.time * WindFrequency * 0.975) )   * 0.5 );

So that it uses game time rather than real time. That does the trick both for recording at fixed frame rate and allows people to use stuff like bullet time. :sunglasses:

I’ve tossed the docs to Whatevernix who does all our models, can’t wait to see the plants he’ll cook up with this stuff… :sunglasses:

I give it both thumbs up, samples work out of the box and they’re straight to the point. Showing both usage with terrain and without. After looking at the ferns without shadows I decided to implement it without the terrain too, but I left the code in there so we can use the Terrain version on slower systems. The grass and mountain terrains are rendered with tweaked versions of the first splat in the shader. Mountains uses multiply between scaled layers, grass uses simple addition!

Cheers,
UnLogick

Just got a mail from Lars asking how the hell I managed to mess up his nice shader. (Well not really but he politely pointed out that something looked a bit off.) Turned out that I was using some of his old resources along with his new shader. Mental note: always delete old packs when importing new ones!

This is how it was supposed to look:

Don’t forget to change it to 1080 HD!

@Lars: Thanks for the heads up. :slight_smile:

Right now i am working on some more assets using the new shader.
Coming soon:

lars

Nice plants you got there man, also very good ground texture.

thanks janpec!

Nice plants, ground textures, trees, atmosphere and everything!

Have you ever considered making a tutorial? I mean that I wouldn’t mind paying for tutorial for making this kind of environments.

Thats what i already suggested to lars on his WIP topic, making tutorial for plant creation, terrain and generaly environment would be very much needed for beginners to plant modeling, becouse after all making good environment is not easy at all. There are already some good costly tutorials out there but nothing for Unity and this shader. So to make win-win situation it would be good to promote your shader with getting some tutorial up.

1 Like

@mk1978: i have already written 2 tutorials: one on terrains (pretty old by now… but it still contains some useful information about performance) and the other about the tree creator and i think i have already said all i can as far as unity’s terrain engine is concerned…

the most important things about terrain creation are:

  • good references
  • good assets
  • and some artistic talent.

next to that some good tools, as you won’t succeed painting/sculpturing a realistic terrain just with the built in tools. use external tools or at least get the terrain tools from sixtimesnothing or terrain edge: http://forum.unity3d.com/threads/118820-TerrainEdge-3-(need-testers-feedback-ideas-etc). those will help you sculpting the terrain and paint it.
terrain edge also comes with some shaders supporting bump mapping and uv mixing for better tiling as far as i know.
another starting point might be the advanced terrain shaders from the asset store (free!).

as far as the terrain from the images above is concerned: it is a pretty simple one: just 2 terrain textures (plus bumpmapping –*all included in the advanced terrain shaders), 2 different types of trees (30$ on the asset store ;-)) 2 mesh grasses and the new foliage plus foliage shader. plus one directional light, bloom and glow post processing image effect and some ssao.

lars

Is this shader compatibile with trees from Unity tree creator?

no, it is not: trees use 2 materials and use a second uv set to control bending. and why should you use it with trees?
in case you want enable batching on trees you can but it is a completely different work around.

lars