Search Unity

Advanced foliage shader [released]

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

  1. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    471
    Hey Lars,

    Any chance some users get to help you beta your latest update in 5 before you release it to the asset store. I'm working on nothing but outdoor vegetation scenes in unity 4 and wanting to make the switch to 5 but anything vegetation unless you want to use speed trees is severely broken right now. I would def be willing to be in an early adopter and pay to beta as well. If so PM me or email me at mjbenitez001@msn.com. Thanks.

    -Miguel
     
  2. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    754
    Hi Lars,

    I have now a script that throws grass objects onto a mesh. I require this behavior because I want to create some city stuff that own a lot of smaller and larger grass areas. This is not hand-able manually piece by piece.

    I want to place your really great grass on some park-side areas, about 100 x 100m, this result in a lot of objects itself.
    The single grass objects are placed inside a game-object in the hierarchy.
    I saw also a combined mesh script is used on foliage containers.

    * Can these objects be handled like the culled grass on terrain?
    * Does your package provide any mechanism to cull the combined meshed in a predefined radius?

    For sure It would be interesting to know, how cull the grass on terrain is technically handled.

    Thanks
     
  3. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,427
    hi quantum1000,

    if you want to populate a 100x100m area you should probably subdivide it into 8 x 8 chunks.
    each of the chunks has one combine children script attached so in the end your may 100000 grass objects will be combined to just 64.

    as far as culling is concerned: the package itself does not ship with any specific culling functionality.
    but you can use the built in "per layer culling". please have a look at the docs.

    lars
     
  4. DirtyHippy

    DirtyHippy

    Joined:
    Jul 17, 2012
    Posts:
    205
    While you refactor for U5, could you remove the StartCoroutine in each update for touchbendplayerlistener? Move the start coroutine to start (), remove the update call, and make the coroutine loop. You may want to handle enable/disable as well. Starting coroutines pressures the GC with ~40 bytes, so starting them every frame is not good.

    Edit: also, why is this not in LateUpdate with no coroutine?
     
    Last edited: Mar 22, 2015
  5. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,427
    thanks for pointing this out: fixed.
     
    seansteezy, hopeful and OnePxl like this.
  6. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,427
    hi there,

    just another quick and preview on the upcoming version showing the tree and billboard shaders:
    the tree shaders will ship with improved bending which stops them from being stretched while bending.
    billboards support SH ambient lighting which – combined with all other features of the tree shaders like light and wind fading and camera aligned billboards – will give you just a perfectly smooth transition between mesh tree and billboard.

     
    astrand130, Paulohmm and hopeful like this.
  7. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    471
    Hey Lars any way you can have an option to not have the billboards face the camera? Just let them billboard and not face/move with the camera they just stay still at whatever angle they billboarded. Reason I ask for this is the oculus rift does this crazy thing with billboards and as your head moves inside the rift tree billboards go way up down left right almost like there dancing around you. You don't see that on normal desktop only inside the rift.
     
    MS80 likes this.
  8. MS80

    MS80

    Joined:
    Mar 7, 2014
    Posts:
    335
    Hi Lars! I need this, too (and everybody who wants to use tree billboards with the oculus rift)!
    I think what Migueljb means is the option to use a custom lookat position for billboards instead of the camera. Problem with the Rift is looking up and down rotates billboard x-axis, looking left and right rotates billboard y-axis. I tried to show the problem with the attached screenshots...
    OR_tree_billboard_problem.jpg
     
    Last edited: Mar 22, 2015
  9. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,427
    unfortunately: no... but i do not really know what the rift really does to billboards.
    do you have the chance to capture a video?
     
  10. MS80

    MS80

    Joined:
    Mar 7, 2014
    Posts:
    335
    have a look at my screenshots, I tried to show the problem with the OculusRift.
     
  11. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    471
    Ya thats right on MS80. Thanks for showing that. If you never get to see inside of an oculus when a tree is billboarding Lars all we need is the billboard to do nothing but just billboard not move at all then transition back to 3d based on the distance slider. I know its not any easy task being you need the billboard to face the camera to have smooth billboard to 3d transitions. If you could figure that out trust me every oculus user would buy your system. All of us oculus users have to battle this that use the unity terrain system with different tricks. Comeon Lars we need you buddy you can do it:)
     
    seansteezy likes this.
  12. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,427
    well, you can’t make a billboard do nothing – as it would simply do not show up!
    the terrain engine feeds in some camera / billboard params and these i guess just do not fit...
    and as i do not own a rift i can hardly do anything about that, sorry.
     
  13. Ali-Nagori

    Ali-Nagori

    Joined:
    Apr 9, 2010
    Posts:
    138
    looking forward for v 4 , can you provide the date so i can manage my work schedule
     
  14. MS80

    MS80

    Joined:
    Mar 7, 2014
    Posts:
    335
    "nothing" is the wrong term! Is it possible to give the billboards another facing direction? If a billboard could look at a custom 3d vector (empty game object / other camera ) instead of the current camera the problem would be solved...(I assume this should happen in the billboard shader itself?!)
     
    Last edited: Mar 23, 2015
  15. seansteezy

    seansteezy

    Joined:
    Nov 28, 2013
    Posts:
    115
    You may be able to include the vector3 checkboxes for something like Freeze Billboard Rotation (x,y,z)? so that when they are billboarding, you can limit their rotation to 1 or 0 axis? With VR, you definitely don't want them rotating when you move your head up and down, or maybe it is the tree mesh that is not centered properly? I'm all about VR and didn't even realize this was a problem! Could you use the camera's starting position/rotation to always make billboards look at that direction? It may get sloppy though, maybe update their rotation origin at intervals? Just throwing out ideas :) Lars, you would know more than anyone, so if what I say is dumb, sorry!
     
  16. MS80

    MS80

    Joined:
    Mar 7, 2014
    Posts:
    335
    @lars: I know you dont have a oculus rift, just wanted to say if you need someone to test whatever, it would be a privilege to me... :)
     
  17. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    471
    Thats goes double for me Lars. Count me in I have an oculus DK2 and unity pro if you need beta testers. You have a huge potential customer base in not just oculus but VR in general for this... needing this.
     
  18. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,427
    hi there,

    no oculus patch/support for the upcoming release, sorry. but if there is one oculus user nearby my location (hamburg/germany), please let me know. may be we can figure something out.

    nevertheless: the upcoming version should be feature complete now (which i thought at least 3 times before).
    right now anything i have been working on seems ready to ship and i am glad to announce that the upcoming version will support leaf turbulence—which means that the frequency (and not only the amplitude) of the leaf bending will change according to the given wind strength giving you a much more believable contrast.

    lars
     
    hopeful and Baldinoboy like this.
  19. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,427
    Improved leaf bending:

     
    astrand130 and Baldinoboy like this.
  20. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,427
    version 4 submitted to the asset store... now it is pending.
     
    John-G and Baldinoboy like this.
  21. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    471
    Hey Lars can you give us an idea of how enlighten works with your new version 4? Can we bake lighting in on the terrain or does it all have to be realtime with your system as well.
     
  22. CubicleNinjas

    CubicleNinjas

    Joined:
    Apr 5, 2014
    Posts:
    15
    Chiming in on the desire for Oculus billboard support and agree with Bacon Neck on the freeze rotation checkboxes. This would be the only solution in the market to solve this! :)
     
  23. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,427
    the foliage shaders of afs 4 support GI and all kind of baked lightmaps – however: transluceny will be lost...
    grass supports lighmapping as well. trees do not by design as they use uv2 to store bending information.
     
  24. omgeric

    omgeric

    Joined:
    Aug 18, 2013
    Posts:
    18
    will there be options for alpha-blending in later updates? I find "cutout" to be too rough for some grass models/textures.
     
  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,427
    definitely no.
    alpha blending is no option as it does not support real time shadows. and it does not fit at all with deferred rendering.
    it would be forward only. and give you a lot of z-fighting/sorting issues.
    but as it is all about deferred nowadays i guess that unity will come up with some proper anti aliasing post effects sooner or later.

    lars
     
  26. astrand130

    astrand130

    Joined:
    Nov 9, 2014
    Posts:
    21
    Whats wrong with the algorithms supplied in the current anti-aliasing post processing shader? just curious.
     
  27. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,427
    it is just not up to date...
     
  28. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    754
    Hi,

    great bending stuff! In my opinion the y movement for leaves on higher wind strength becomes to too high.

    As much more the power of wind affects leaves from x,z direction, so more energy will be subtracted from the y movement of the branches. You can compare this effect while holding a rubber band between hand with weight in the middle. Pulling the rubber band x,z cause decrease the y movement of the weight.

    The new Speedtree producing this effect very extremly. Looks like they start to hopping on higher wind power like on earthquakes. ;)

    Great to see you working on V4!
     
  29. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    754
    There is a legacy shader in U5 that called transparency > cutout > soft edges unlit. This shader produce a softer cut. It use a semitransparent pass and from what I see it does not have z-fighting issues and it's double sided.

    To fix the unlit, you can use the script to transform the main light intensity onto the main color on the shader.

    Untitled-1.jpg
     
    Last edited: Mar 28, 2015
    OnePxl likes this.
  30. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,427
    it is double pass i guess (just like the old vegetation shaders from 3.x) to get around the z-issues.
    and what is about real time shadows? global illumination and all the rest?
    personally i would just say goodbye to alpha blending: it does not fit into the lighting and rendering pipeline at all.
     
  31. astrand130

    astrand130

    Joined:
    Nov 9, 2014
    Posts:
    21
    Hello, the most recent release of AFS 4 for Unity 5 is giving me some serious visual artifacts when used with post processing effects (such as SSAO). It seems to draw the legacy bending and in the z-buffer and is treating the foliage as if it was semi-transparent.

    System specs:
    Nvidia GeForce 840M (driver version 332.70), Intel Core i7, Windows 7
    Unity Specs:
    5.0.0f3 Pro (Renderer: DirectX 11)
    Camera/Scene Settings:
    Deferred Rendering, ColorSpace: Gamma, Dynamic&Static batching enabled, HDR: Off

    Foliage Shader Overview Demoscene.unity
    The camera has the default Unity SSAO script attached and the background color was set to white for demonstration.
    AFS Post FX Depth Glitch.jpeg
     
    Last edited: Mar 31, 2015
  32. DirtyHippy

    DirtyHippy

    Joined:
    Jul 17, 2012
    Posts:
    205
    U5p3 deferred/linear, DX11, HDR.

    ----------------

    Request on V4, to support pooling, I have a few minor requests that amount to about 4-5 lines of code changed:

    In touchBendPlayerListener:

    1) Make start a protected virtual

    The reason for this is everything I do is pooled, and I have my own pooling methods that mimic start/destroy. This way I can derive from this class, override Start with an empty method, and handle the startup on my own and then include this derived component as my listener instead of yours.

    2) Pull the contents of Start into a separate protected method, e.g.:

    protected void StartListening () {...}

    And put a call in your Start to StartListening (This allows derived classes to maintain the original implementation without copy and pasting).

    3) Change the coroutine to lateupdate. Is there a reason this is a coroutine at all? Changing it to LateUpdate doesn't seem to change the behaviour, and everytime you yield the coroutine it pressures the GC with ~35 bytes.

    ---------------

    I see artifacts with unity's default bloom on the touch bending banana plant. If I knew anything about shaders, I could probably fix it. But I do not. So any ideas how to mitigate this?

    ---------------

    It would be awesome if the AFSCombineChildren could handle the case where patches maxed out their vertex count, and create another patch automatically. I haven't tested this yet in V4, but I imagine the behaviour hasn't changed. Just a pie-in-the-sky wish :)


    More to come, but I am nearing re-integration of V4. Looks great!
     
  33. MS80

    MS80

    Joined:
    Mar 7, 2014
    Posts:
    335
    Congratulations, V4 is great!!! Thanks for bringing all those features to Unity5.

    I can confirm this issue, tried unity standard ssao and ssao pro, both show the background color.
     
  34. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,427
    thanks for reporting this issue.
    right now i am working on the fix.
     
    astrand130 likes this.
  35. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,427
    i will have a look into this.

    might be caused by the fact that in the shipped package the material does not have any normal/trans/smoothness texture assigned.
    it works fine for me after assigning that texture.
     
  36. DirtyHippy

    DirtyHippy

    Joined:
    Jul 17, 2012
    Posts:
    205
    Another note:

    Messing around with on a test terrain I have noticed that non-billboarded grass textures were randomly dissapearing, as if the internal patches were incorrectly getting culled. This also happened with some detail meshes. Deleting your hidden grass shader returned the behaviour to normal.

    I also noticed this dropping your own terrain engine grass mesh in your sample scene now that I think about it (when I first downloaded AFS).
     
  37. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,427
    hi there,
    fortunately ;-) i can not reproduce this bug. so do you have have some more info for me?
    - any special image effects?
    - any other shader packages?
    - have you added the setup script to your scene?
    thanks, lars
     
  38. DirtyHippy

    DirtyHippy

    Joined:
    Jul 17, 2012
    Posts:
    205
    This was with a new scene, and a blank terrain, recentered around 0,0,0. I was just a test scene for mucking with billboard grass/detail meshes that I created last night.

    No image effects. I searched for other shaders in my project that were overriding the hidden shaders and there were none. I did not add the setup script to my scene, however. For some reason I guess I was figuring that for dropping non-billboarded grass textures in for testing that it would not matter.

    I will re-import the shader and see if the setup script resolve the issue.
     
  39. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,427
    without the script you will have no wind on grass – even if placed on the terrain.
    but at least the shader should now at which distance to fade out the grass. strange…
     
  40. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,427
    ops, grass textures only? well, those are not supported – at least not if you also want to add foliage using the vertex lit shader.

    from the docs:

    Usually you would just add single textures or models to the terrain and let the terrain engine create a texture atlas for all given details automatically. Unfortunately this will not work in case you want to use the AFS grass and foliage shaders within the terrain engine as at least the foliage shaders need a second texture containing the combined Normal/Translucency/Smoothness maps.
    For this reason you will have to create the texture atlas manually and map all objects—no matter if they use the grass shader or the foliage shader—to that atlas.

    Please note: Using a manually generated atlas won’t let you use any grass rendered as billboard or simple texture, because adding this kind of grass would add a second texture to the internal texture atlas of the terrain engine and corrupt the texture lookup within the manually setup atlas.
     
  41. PiAnkh

    PiAnkh

    Joined:
    Apr 20, 2013
    Posts:
    110
    Lars,

    I am having exactly the same problems as DirtyHippy. I have a scene with various terrain grass meshes and textures and depending on the distance and/or angle they all disappear and reappear. This happens in mass. They are all there or all gone. They are all set to the grass shader not vertexlit. I am not using the grass meshes manually. Do I need to make a texture atlas and the second combined texture for this?
    Will that solve the problem with the disappearing grass meshes?
     
  42. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,427
    does this happen in the scene view window as well or just in game view?
    if it happens in scene view as well you could switch the viewing mode to "shaded wireframe" as see if the textures disappear but not the wireframes – or if it is or both.
     
  43. PiAnkh

    PiAnkh

    Joined:
    Apr 20, 2013
    Posts:
    110
    I
    It happens in both scene view as well as game view. I tested it in shaded wireframe and the meshes remain. Only the textures disappear.

    By the way, a new problem has occurred. I added another grass mesh and subsequently deleted it. The textures have been replaced with a white texture (with some pink banding depending on the location. Strangely even if I load the demo scene I now see the same white textures.

     
    Last edited: Mar 31, 2015
  44. MS80

    MS80

    Joined:
    Mar 7, 2014
    Posts:
    335
    I have the same problem (editor + runtime). It happens in the demo scene as well (01 Shader overview), just walk around the grass, there a several agles where the grass will disappear.
    grass_disappear.jpg

    I found another issue with the grass and oculus rift: shadow on grass switches from correct shadow to incorrect flat shadow depending on view?!
    grass_shadow_ovr_problem.jpg
     
    Last edited: Mar 31, 2015
  45. astrand130

    astrand130

    Joined:
    Nov 9, 2014
    Posts:
    21
    Ya, I'm having the same issue with terrain instanced grass dissapearing as well.

    It happens in both the scene view and game view but the geometry doesn't actually disappear in shaded wireframe, just the rendered pixels.

    Same Computer, Same Unity Version, Same Demo Scene.

    but for some reason when I closed unity and opened the scene again the terrain instanced grass turned pink and white which i tried to re-bake the lighting, changing render settings, and closing unity but it's still pink even though it was perfectly normal the last time I had it open i didn't touch anything. (which was slightly due to the grass healthy/dry color but still with it set to white the grass appears to be pink and white)

    Demonstration of visibility problem based on viewdirection:
    AFS Grass Cull Options.gif
    Hopefully this information might help.
     
  46. MS80

    MS80

    Joined:
    Mar 7, 2014
    Posts:
    335
    @lars: This would really help, do you think this would be possible(freezing rotation axis checkbox)?
     
    Last edited: Mar 31, 2015
  47. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,427
    hi there,
    i did a bunch of tests again. and everything works fine – at least on opengl / os x.
    so it might be dx9/dx11 problem which i will have a look into tomorrow when i am back at the office.

    btw: ssao problems are solved and will be patched with the next version.

    lars
     
    astrand130 likes this.
  48. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,427
    freezing rotation means 2 completely different things:
    referring to the screen shoots you have posted:

    1) looking up or down: billboards turn down
    this might be caused by the "align to camera" feature. you might simply try to uncheck "align billboards to camera"

    2) looking left: billboards rotate left.
    i am not really sure if i get this right. and i might be totally wrong. but billboards do not rotate. they are always aligned to the camera.
    in order to produce the illusion to view trees from different viewing angles the terrain engine simply shows different billboard images which more or less fit the given viewing angle.
    so – as the billboardtextures are generated and fed by the terrain engine – this is nothing i can do anything about shader wise, sorry.
    but as said before: i might not get the problem correctly and it is not the rendered texture but the billboard plane.

    lars
     
  49. MS80

    MS80

    Joined:
    Mar 7, 2014
    Posts:
    335
    Thanks lars for your detailed explanation!
    => 1.) I tried this already without success, but I will give it a another try tomorrow, just to be sure!
    => 2.) Did not know that there are more than one billboard images generated by terrainengine, I thought there is only one billboard image aligned to the camera. Can a billboard aligned to a custom camera via shader or will a billboard always be aligned to its rendercamera?

    Sorry to tackle this again! I just want your smooth blending tree / billboards inside the oculus! :)
     
  50. PiAnkh

    PiAnkh

    Joined:
    Apr 20, 2013
    Posts:
    110
    I think it may be related to the use of DX11. I switched the project to DX9 and the grass reappeared and the white/pink colouring was replaced by the texture.
     
unityunity