Search Unity

Advanced foliage shader [released]

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

  1. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i do not have any idea... sorry.
    but you could send me your prefab – or better: a simple scene with your setup and the prefab.

    lars
     
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    unfortunately there is no way to push a hot fix to the asset store: any update always has to pass the regular confirmation process.
    sorry about that,

    lars
     
  3. wolfen231

    wolfen231

    Joined:
    Apr 22, 2014
    Posts:
    402
    That's ok. I think we will live. Performance isn't a high priority since this is a demo for a powerful machine in the future. I wish I could send you the model / prefab but it would be against my NDA.

    I do as usual want to express my appreciation and thanks for all your help though.

    I just got done with updating vertex colors and normal maps to the specifications and your shaders are just great. Thanks for all the hard work on them. =)
     
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i am glad that you have solved your problem.
    lars
     
  5. wolfen231

    wolfen231

    Joined:
    Apr 22, 2014
    Posts:
    402
    And yet another problem. Sorry, and thanks for your patience and help.

    I am using advanced groundlighting (not grass).

    I have a double sided geometry, very low poly. The bottom verts are black, top verts are a low blue. The normal is set up as described and it is very soft / light in depth on the normal.

    However when it comes in, it is jet black aside from the spec showing up. I tried adjusting the alpha verts which of course did nothing but it was worth a shot. Also messed with all the sliders on the shader / material for the object with no fix.

    I have a very similar set up on another model with no issues at all.

    Any suggestions on what to look into?
     
  6. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hmmm – groudlighting only works in conjunction with the afs combine children script as the ground normal has to be baked into the mesh.
    have you attached the script?
    and have you checked if the script captures the correct normal?

    lars
     
  7. wolfen231

    wolfen231

    Joined:
    Apr 22, 2014
    Posts:
    402
    That is correct. Normals looked fine, its under group with the script attached. It worked fine with the groundlighting grass no trans shader. Then when I went to switch it off to the advanced foliage shader (and updated its vert colors) it went all black.
     
  8. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    quite difficult to say anything about this – but i will try my best:
    - if you use the grass shader normals baked to the mesh do not play nay role.
    - if you use the ground lighting shader they DO.

    so you might check the mesh’s normals using any other shader or having a look at the mesh using the inspector: does lighting look correctly?

    another reason for the wrong shading might be incorrect vertex colors – especially vertex color alpha values.
    you may use the foliage tool to raise or reduce vertex color alpha and see if there are any changes.

    lars
     
  9. krillmcrawl0

    krillmcrawl0

    Joined:
    Jan 13, 2014
    Posts:
    35
    I'm using this great system mainly for placing lots of trees on custom terrain to benefit from billboarding, batching and so on. I made a script to replace massive amounts of gameobjects to be unity trees, the script is based on the Reposition terrain script found in the package. It works great!

    Since I have my own custom terrain meshes created in 3ds max I would like to hide the unity terrain object so it's not visible to the renderer and also make sure that it doesn't recive shadows since it's now only a dummy containing only the trees. Is this possible? I would be very happy for any help I can get regarding this.

    Thanks,
    Kristian
     
  10. larsbertram1

    larsbertram1

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

    i am not sure if you can "deactivate" the rendering component of the terrain – but since you are able to assign custom materials to the terrain you should be able to assign a very simple shader to the terrain which does not draw – anything.
    it would still produce some overhead but using a very low heightmap res, not assigning any detail textures and thinks like this should reduce rendering costs to an absolute minimum.

    lars
     
  11. krillmcrawl0

    krillmcrawl0

    Joined:
    Jan 13, 2014
    Posts:
    35
    Thanks Lars. Do you have a shader like that lying around? :) Shader programming are not my strong side

    Have a nice weeken!
     
  12. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    unfortunately: no...
    but i would start with the built in terrain shader and add an early clip command.

    lars
     
  13. wolfen231

    wolfen231

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

    Cant you tell me what settings i should use on the normalmap import in Unity?

    Also... with version 2 I had toned down the normal maps and got rid of a big glowing bug that showed up because of the bloom.

    Now with Version 3, I get that glowing stuff again. It just seems to be the bloom glowing on the spec highlights. Any suggestions on killing that as well with out having to get rid of bloom?
     
  14. Project-Mysh

    Project-Mysh

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

    Im enjoying your shaders!
    But there is something regarding the bending system you implemented:
    Reading your documentation, you are using blue chanel from vertex colors for main and detail bending. You do this to reserve the alpha channel for ambient occlusion, losing some control of the detail bending. But why not use the pivot point of the mesh as reference for the main bending? In my experience with UDK and Shader Forge in Unity this works very good.
     
    wolfen231 likes this.
  15. larsbertram1

    larsbertram1

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

    using the pivot point would be an option – in case you rendered each plant separately.
    but that would kill your frame rate because you could not use dynamic or static batching or even the combine mesh script…
    so in real life it is not an option – at least not on regular plants. plants using the touch bending shader will be rendered separately – but only if they are touched. untouched plants will be batched.

    lars
     
  16. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi there,
    depends on what color space you use.
    if you use linear color space import it as "advanced" and check: "bypass srgb" sampling.

    specular highlights should contribute to the blooming effect as far as i can say.
    what should be wrong about that?
    from the unity docs: "Blooming is the optical effect where light from a bright source (such as a glint) appears to leak into surrounding objects."
    http://docs.unity3d.com/Manual/script-Bloom.html

    you may however make your plant’s surfaces less smooth to reduce specular highlights.

    lars
     
  17. wolfen231

    wolfen231

    Joined:
    Apr 22, 2014
    Posts:
    402
    Lars,

    Yes, I am using Linear Space so I will try out the bypass of srgb.

    With my normals I am getting things like this. The normal map is really really low in detail. Almost at a level of 0. I consider this a problem haha. It happens on almost all of the foliage. That's why I am surprised it is now going nuts after I had toned it down already using your foliage ver 2 shaders. I realize quite a bit has changed in version 3 (i have even renamed the normals to have the _AfsNTR for that script). It's not like I am not reading your documentation as well. =)

    Edit: Yeah the bypass srgb helped with this. Its now reacting to my previous lower normals more like expected. =)
     

    Attached Files:

    Last edited: Jul 2, 2014
  18. larsbertram1

    larsbertram1

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

    when using linear color space it is absolutely needed to check "bypass srgb sampling" on all none diffuse = combined textures.
    otherwise the normal map extracted from the combined normal spec roughness tex will be corrupted.

    sometimes i forget about this myself too...
    so it might be a good idea to print this post and stick it to your screen ;-)

    lars
     
  19. krillmcrawl0

    krillmcrawl0

    Joined:
    Jan 13, 2014
    Posts:
    35
    Thanks, I posted regarding terrain transparency in the shaderlab forum since I have no clue where to start modding really.

    However I have another issue, I'm using this Camerasystem:
    http://u3d.as/content/kolmich-creations/kgfcamera-system/46q
    It's using LateUpdate and it seems to break the "Align Billboards to Camera" functionality. Can you think of something I might try to fix it?
    Regards,
    Kristian
     
  20. larsbertram1

    larsbertram1

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

    the "align billboards to camera" feature needs the advanced billboard shader and the setupfoliageshader script which passes some parameters to the shader like camera position and viewing direction.
    the script itself looks for a camera which is tagged as "main camera".
    may be it is as easy as that you have forgotten to tag your camera?

    lars
     
  21. krillmcrawl0

    krillmcrawl0

    Joined:
    Jan 13, 2014
    Posts:
    35
    Yes, maincamera is tagged and I'm using the "AFS Simple Terrain Tree ShadowFade" shader.

    I also have the Setup AFS script in my scene, but it was disabled:) Sorry about that, everything looks good now!
     
  22. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i am glad you made it!
     
  23. wolfen231

    wolfen231

    Joined:
    Apr 22, 2014
    Posts:
    402
    haha Yea. =D

    Thanks again Lars, you rock.
     
  24. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    you are welcome!
     
  25. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,260
    Hi,

    I'm using AFS with the Time of Day sky and I've set the light to the time of day light. I've placed a few trees in the terrain and tested the billboarding and the billboards are not matching the ambient lighting. See the video:



    Is this a limitation of AFS or am I doing something wrong? Thanks
     
  26. larsbertram1

    larsbertram1

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

    everything in your video looks pretty strange: no fading at all.
    no fading as far as the lighting is concerned but also no fading as far as the geometry is concerned.
    i have never seen anything like this before.

    but in order to nail it down: please check the demo scenes first (and remove all other packages you might have installed)
    i can not claim that any of your assets interferre with the foliage shaders.
    so please make sure that you get rid of any other shader that might be present in your projects.

    known issues: bhs’ unistorm will break the shaders as it ships with its own shaders.


    lars
     
  27. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    562
    Just getting used to AFS and loving it so far.

    Lars in the Setup Advanced Foliage Shader Script how do I enable Camera Culling Settings to work. I have the Enable Layer Culling check box checked and by default Small Detail Distance is 70 and Medium Detail distance is at 90. When in Run mode or in the editor no matter where I put these sliders at nothing changes. So what are the steps to get these 2 sliders to work and show up as I am changing those 2 values?

    Also if I am not using the unity terrain engine whats the best way to smoothly fade in and out like how grass renders but with foliage plants and trees that are around my scene as well? Thanks.

    -Miguel
     
    Last edited: Jul 4, 2014
  28. larsbertram1

    larsbertram1

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

    if you want to use camera culling you have to place your foliage on custom layers:
    - layer 8 for small plants
    - layer 9 for larger plants
    you have to define those layer before you can assign any objects to those.

    unfortunately fading out plants or even trees is not as easy as fading out grass as grass usually is not much more than a simple texture so we can gradually change the alpha cut off value.
    so for now you can only simply cull plants or trees.

    lars
     
  29. Project-Mysh

    Project-Mysh

    Joined:
    Nov 3, 2013
    Posts:
    223
    Hi Lars,
    I have managed to use object position (pivot point) for the main bending, and static batching its working correctly. Im not a shader coder, im using shader forge ( as I usually used UDK material editor for 2 years) but maybe its a limitation for surface shaders? i have tested it in many ways, and all plants gets batched. Are you sure that you cant use the pivot point for main bending? (I did it getting the distance between the object position (pivot point) and the world position(vertex position), then dividing it by a number ( to control the power ).
    Im interested on it cause your shader works amazing, and the optimized drawcalls are amazing too. I only want to help to get this package more amazing.
     
    Last edited: Jul 7, 2014
  30. larsbertram1

    larsbertram1

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

    thanks for your efforts.
    but i have to admit: i do not know why it "seems" to work for you:
    if your meshes get batched statically they all all combined into one big mesh whose pivot will simply be ... somewhere – probably at the center of that mesh.
    but not at the pivot of every single plant of that mesh of course. so it can not work theoretically: if you batch objects you do not get the position each single submesh in the shader but just the position (or pivot) of the combined mesh.
    that is the reason why we have to bake all needed information to the vertex data (position, normal, tangent, color, uv, uv2).

    so i really, really doubt that your objects get batched or that they bend correctly.

    btw: if you create a shader that does vertex animation using shader forge do real time shadows and image effects like ssao work correctly – especially in deferred lighting? i simply can’t imagine they do…

    lars
     
  31. laurent-clave

    laurent-clave

    Joined:
    Jul 18, 2011
    Posts:
    280
    Hi Lars,

    Are you sure that the specular works with tree creator?

     
  32. larsbertram1

    larsbertram1

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

    yes, i am.
    but the tree creator shaders use the original specular term and not the physically based one like the foliage shaders do.

    lars
     
  33. laurent-clave

    laurent-clave

    Joined:
    Jul 18, 2011
    Posts:
    280
    Ok. Il don't have a solution ?
     
  34. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    brighten the "Gloss" texture!(?)

    lars
     
  35. adsamcik

    adsamcik

    Joined:
    Jan 13, 2013
    Posts:
    37
    Hi,
    Anyone has any idea what can be causing this? I think it's texture related since it appears on only some textures but it started to appear all at once. I didn't change anything on the texture and on the screenshot is grass (terrain-no billboard-texture) with texture that has completely black alpha. Thanks. grass.JPG
     
  36. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    what is your problem? the yellow sky, the green floor, the short lines everywhere?
    lars
     
  37. adsamcik

    adsamcik

    Joined:
    Jan 13, 2013
    Posts:
    37
    the problem are the lines, I wouldn't bother you with sky or green floor :D Those two might look bad but with other components they are not that bad ;) The lines are pretty much the top of the grass texture, but I can't find reason why they are here.
     
  38. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    those lines are probably caused by texture filtering (and pretty common on grass textures in unity...) and the texture atlas:
    especially at grazing angles the shader might sample some pixels from textures placed right next to the grass texture.

    so if you use mesh grass please make sure that your uvs do not hit the borders of your grass texture – but make them a little bit smaller so you get a gap of may be 8 – 16 pixels between texture border and uvs.

    lars
     
  39. adsamcik

    adsamcik

    Joined:
    Jan 13, 2013
    Posts:
    37
    Nah for this one I am using only Textures because it looked fine and I felt like it might save some triangles.
     
  40. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    well, using only texture IS the problem as unity generate triangles whose uvs fit with the texture’s border...
    so use a custom mesh instead. it just can be a simple quad split into 2 triangles then the vertex count will be the same as using textures (switch to "textured wire preview" to see what’s going on).
    if you want to add more complex foliage to the terrain (like the fern from the demo) you will have to create your own texture atlas – and add a second texture using the setup scrit which contains spec, roughness and translucency information.

    lars
     
  41. adsamcik

    adsamcik

    Joined:
    Jan 13, 2013
    Posts:
    37
    Ok Thanks, I was trying to avoid this, because it will cause repainting a lot of grass, but I guess I have no choice.
     
  42. SkermunkelStudios

    SkermunkelStudios

    Joined:
    Dec 29, 2012
    Posts:
    156
    Hi Lars,

    I upgraded to Unity 4.5.2 last night and when I opened my project this morning I just noticed these 2 errors keep repeating themselves non-stop and they are slowing down the project and making it very difficult to work in the editor:

    Maximum number (64) of shader keywords exceeded, keyword TREESHADOW_NO_EDGEFADE will be ignored
    UnityEngine.Shader:EnableKeyword(String)
    SetupAdvancedFoliageShader:afsUpdateTreeAndBillboardShaders() (at Assets/Advanced Foliage Shader v2.042/Scripts/SetupFoliageShader v2.042/SetupAdvancedFoliageShader.cs:210)
    SetupAdvancedFoliageShader:Update() (at Assets/Advanced Foliage Shader v2.042/Scripts/SetupFoliageShader v2.042/SetupAdvancedFoliageShader.cs:124)

    Maximum number (64) of shader keywords exceeded, keyword TREESHADOW_EDGEFADE will be ignored
    UnityEngine.Shader:DisableKeyword(String)
    SetupAdvancedFoliageShader:afsUpdateTreeAndBillboardShaders() (at Assets/Advanced Foliage Shader v2.042/Scripts/SetupFoliageShader v2.042/SetupAdvancedFoliageShader.cs:211)
    SetupAdvancedFoliageShader:Update() (at Assets/Advanced Foliage Shader v2.042/Scripts/SetupFoliageShader v2.042/SetupAdvancedFoliageShader.cs:124)

    I never got them before, is there some kind of conflict with AFS in Unity 4.5.2? I am currently running on AFS 2.042.

    Please any help on the matter would be greaty appreciated
     
  43. SkermunkelStudios

    SkermunkelStudios

    Joined:
    Dec 29, 2012
    Posts:
    156
    Nevermind, after just exiting Unity and restarting the project, everything seems to work fine now. Sorry for the bother.
     
  44. konsnos

    konsnos

    Joined:
    Feb 13, 2012
    Posts:
    121
    Hello lars,

    I have one question. Does this tool batches the draw calls of grass painted on the terrain or only manually added grass?
     
  45. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi konsnos,
    the combine children afs script only combines manually added grass objects which are child objects of a certain patch into one mesh = 1 draw call (or 3 in case you use real time shadows).
    so it is more or less the same that the terrain engine does: it combines all grass meshes of a given patch into one mesh and sends it to the gpu.
    i wished that the terrain engine would even combine different patches (if possible) but unfortunately that is nothing and can change.

    lars
     
  46. broesby

    broesby

    Joined:
    Oct 14, 2012
    Posts:
    118
    Hi all and especially you djweinbaum ;-)

    Those are absolutely amazing screenshots.

    I would like to know how your performance / FPS is when walking around those scenes??
    And do the trees look good when seen from above - flying, that is :) ??
    And lastly - are there colliders on the trees?

    Actually it is more of a general question for all: What is the best way to proceed making a large terrain - preferably really large. For instance Terrain Composer and RTP3 creators made a 900 sq mile terrain !!

    I am using the combination of WC/TC + RTP3 and made some great terrains already.
    Now I also bought AFS and looking forward to using it ;-)

    I have the potential problem that I want too many trees. Your forests djweinbaum seem to be fairly dense, that's why I ask you about performance.

    ... and the collider problem: In know the limit of 65000+ colliders will be lifted when unity 5 arrives. But the colliders themselves must really draws on performance. Would't it be possible to make sort of "collider LOD system"?? After all you don't really need colliders on stuff until you are close to hitting them...

    Sry for unstructured post, but I am working and a bit in a hurry ;-)

    Best wishes
    Jesper, Denmark
     
  47. larsbertram1

    larsbertram1

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

    tree colliders are a problem, right.
    Would't it be possible to make sort of "collider LOD system"??​
    yes, i think so. simply do not add any collider to your trees.
    then loop through the array in which all trees are stored and generate a new – may be quad tree based – array for the colliders.
    set up a pooling system with may be 100 members and use this in combination with your quadtree array at runtime to place the tree colliders around the player.

    lars
     
  48. broesby

    broesby

    Joined:
    Oct 14, 2012
    Posts:
    118
    Hi Lars,... A really intriguing solution - did you actually try it??

    To be fair i must say that I am not a coder. I am on a steep learning curve reading up on anything I can find about terrain creation. But I need to rely on Playmaker, other assets and sometimes modified snippets of code/scripts for my game.

    Until now I succeeded with most of what I wanted by trial and error.

    I haven't actually had any performance problems yet with my trees, but I didn't really try the dense big forests that I want yet.
    And I just expect them to happen sooner or later as my terrain gets big enough so I have been reading a lot on this...

    I think I can almost grasp what you mean but I am not sure I can pull it off on my own :-(

    I have a few questions?

    1) I got the impression, probably wrongly, that once a collider is instantiated it will draw on performance no matter what - even if disabled? Is that true?

    2) Do you think I could use something like Pool Manager for the pooling of the colliders?

    3) Is the quadtree array something like this: http://gamedevelopment.tutsplus.com...ct-likely-collisions-in-2d-space--gamedev-374

    I am sorry for being a non coding-newbie :-/ ;-)


    Jesper

    PS: Are you from a scandinavian country, Lars?
     
  49. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    unfortunately: no.
    i am not sure but i think that each active collider will cost performance (that is the reason why 10000 trees will kill your framerate).
    i do not know about disabled colliders.
    however using a pooling system will always give you the exact same amoutn of tree colliders present at a given time and depending on the size of your pool.
    [/QUOTE]

    i think so, yes.


    That is exactly what it is.
    not really: germany.

    lars
     
  50. TimBorquez

    TimBorquez

    Joined:
    Mar 18, 2013
    Posts:
    81
    do any of the shaders not cull the back faces?