Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Advanced foliage shader [released]

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

  1. Crayox

    Crayox

    Joined:
    Dec 21, 2014
    Posts:
    9
    Sorry for being daft...but...I have an empty object to which all the grass and little plants are attached with Brush tool, so I put the combine children script to that empty object or to the grass prefab object before I start distributing it?
     
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,910
    yes. but you can also attach the script later on.
     
  3. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    Hi lars,

    I was wondering if you could make a version of this asset that will work with Unity 5.0? And when you get to that point, if you could make some wheat as a prefab? I still would love some wheat that reacts to your touch bending system! :)

    I imported the "Advanced Foliage Shader" package into my Unity 5.0 project, and I got two or three errors in the compiled shaders. All of my materials are default "pink", as in it won't display the shader. I'm wanting to use IBL and touch bending specifically if possible.

    I know some asset creators don't have Unity 5.0 yet, but that would be cool if you were able to update the package to work with 5.0!

    Thanks.
     
    ThunderTruck likes this.
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,910
    i am working on a version for unity 5. but as unity changes so much from beta to beta it won't be reased before the official release of unity 5: i have already rewritten the shadercode 2 or 3 times during the last 4 month which is not really fun.
     
    Deleted User likes this.
  5. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437

    I see. Thanks for the information. I'm glad you're going to update it for Unity 5.0 full release though. :)
     
  6. GenOli

    GenOli

    Joined:
    Apr 21, 2013
    Posts:
    139
    The Geometry Brush AFS link is down, can you reupload?
     
  7. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,910
  8. SwitchNZ

    SwitchNZ

    Joined:
    Jan 22, 2015
    Posts:
    3
    Hi Lars, is there anyway I can change the alpha value of a texture within the shaders, IE I want to make it transparent if there is a collision detected, I am not sure where the final pixel color and alpha are calculated, or is there no inherent transparency with this program ?
     
  9. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,910
    hi switch,
    the foliage shaders use alpha cutout – not alpha blending.
    so if you want to make them transparent on collision you will have to copy the touch bending shader, rework it so it uses alpha blending instead of alpha testing, create a new material that uses your reworked shader and assign this as "touch" material. but please notice: transparent objects will neither receive nor cast shadows.

    lars
     
  10. konsnos

    konsnos

    Joined:
    Feb 13, 2012
    Posts:
    123
    Hey again,

    I'm having some problems with billboards color. I have a day-night cycle and the billboarded trees only retain the color they have at the start. Can I fix that?

    Thanks for reading.
     
  11. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,910
    i guess you mean billboard lighting instead of billboard color.
    if so the answer would be: not really but somehow...
    unity only updates the billboard lighting if the camera moves or better rotates a little bit.
    so you could add e.g. an idle animation to your camera while you change lighting.
     
  12. konsnos

    konsnos

    Joined:
    Feb 13, 2012
    Posts:
    123
    thanks for the reponse @larsbertram1

    Hm, I tried to move the light source but I didn't get any update.

    My source is a Directional Light, which constantly changes its rotation, and its intensity based on time.

    When I start my scene from "night" the trees always remain black even when the whole other scene is lit up. When I start my scene from "day" the trees remain green even when the scene has become dark.

    I hope I was more descriptive.
     
  13. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Is the camera moving or is it completely static? Even in scene view you have to move to get the billboards to update with the lighting.
     
  14. konsnos

    konsnos

    Joined:
    Feb 13, 2012
    Posts:
    123
    It's constantly rotating. As I said above i tried to manually move it but it didn't update the billboarded trees. Shadows although keep updating all the time.
     
  15. konsnos

    konsnos

    Joined:
    Feb 13, 2012
    Posts:
    123
    Oh, sorry, you asked for the camera. My bad.

    Yes the camera is constantly updating its position.
     
  16. cowtrix

    cowtrix

    Joined:
    Oct 23, 2012
    Posts:
    322
    Hi lars. Quick question - I'm trying to find the piece of shader code that dithers grass out by distance. Is that handled by AFS? Any chance you could point me in the direction of that?
     
  17. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,910
    should be part of the include file of the grass shader.
     
  18. Tethys

    Tethys

    Joined:
    Jul 2, 2012
    Posts:
    672
    We have an issue with not being able to find a proper Billboard Tree shader that works with Linear lighting space and deferred rendering mode. In attempt to find one we bought this package, the V2 version of this package, Lux, Alloy and still have not been able to find a tree billboard shader that works in our setup. Here is our issue:

    A game that has changing lighting conditions, set entirely outside in the above mentioned lighting and rendering mode. The game takes place entirely on a voxel terrain that is generated procedural. Details and GO processors then impregnate the terrain with Trees, bushes and grass. So nothing exists in the scene on startup other then the Lighting/Day-Night system and the world generators. Our tree processor then generates billboard textures and creates an atlas and then swaps out GO trees with billboard trees at certain distances. So with everything being dynamic we really need a shader that just works without extra scripts and preexisting setup. With Lux, both the Leaves shader and and the two sided cutout is UNLIT it seems. Whenever I change the lighting conditions they just dont change, they are stuck on the color that was set and it doesn't seem to take into account ambient lighting or actual lighting changing. Perhaps I misunderstand the setup - but that is the result I get.

    Tree Billboards that are stuck on a static lighting - they are either bright or dark but cannot change is also what I'm getting with AFS 3. With AFS 3 we thought for sure it would work so loaded it up, changed the light and low and behold, grey tree billboards that don't change with changing lighting conditions. After reading more of the documentation it looks like maybe AFS will not work for us based on needing some static setup steps. Anywho, this was our results from trying both of these packages which we thought might provide PBR Billboarding trees for particular setup. Is there a shader out there that will take into account changing lighting conditions, work in Linear lighting mode with Deferred Rendering and be a transparent cutout that is double sided without the extra static setup steps with the scripts needed? I must have misunderstood what both of these packages do or we are just setting it up wrong - any advice is much appreciated. Thanks!
     
    Last edited: Feb 3, 2015
  19. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,910
    you do not have to precalculate anything but you wil have to pass lighting information to the leaves and bark rendertexture shaders i guess.
     
    Tethys likes this.
  20. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,910
    @Tethys: so you have managed to get your billboards lit correctly?
     
  21. Tethys

    Tethys

    Joined:
    Jul 2, 2012
    Posts:
    672
    Not yet, haven't had a chance to look at how to do this. I actually have a billboard shader that works fine in Gamma mode but we are in linear mode so considering just altering that shader to work in Linear color space. Thanks for the follow up!
     
  22. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    @larsbertram1 I'm very confused right now. How come in Unity 5 when I select the "Nature/Tree Creator Leaves" shader with afs in my project it looks different and animates according to the Setup AFS component? All the AFS shaders are broken and purple but the standard unity foliage shader looks like a perfectly working AFS shader?
     
  23. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    I know, that's exactly why I find this so strange! Nature/Tree Creator Leaves is not an AFS shader at all yet it responds only to the wind settings of the Setup AFS component. It looks amazing and responds perfectly to the scene lighting settings. When I delete the AFS folder from my project the Tree Creator Leaves looks like garbage and doesn't animate. Does this make sense? AFS shader are purple. Tree Creator Leaves (a shader that comes with unity and has nothing to do with AFS) looks and animates like an AFS shader.
     
  24. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,910
    somehow it makes sense as the afs shaders are built on top of the tree creator shaders.
     
  25. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    I haven't even authored the textures to fit the texture format for the material and it looks absolutely amazing. Tree Creator Leaves + whatever weird stuff AFS is doing to this shader is the most amazing vegetation shader I've seen in Unity. I'm trying to get some screenshot to adequately show it.
     
  26. mrwogs

    mrwogs

    Joined:
    Aug 20, 2014
    Posts:
    36
    Thanks for making this awesome tool. I read through the entire forum, but I didn't get a clear answer on whether or not AFS objects can interact with Unity wind zones? I have a player character with a radial wind zone attached to him. When he jumps/launches into the air, I'd like to AFS plants to start waving around wildly based off of the wind zone scripting we have in place for the jump/launch. Thanks!
     
  27. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,910
    hi there,
    wind zones only work with tree creator trees which never get batched or anything else, sorry.

    lars
     
  28. mrwogs

    mrwogs

    Joined:
    Aug 20, 2014
    Posts:
    36
    OK, thanks for the quick reply.
     
  29. mrwogs

    mrwogs

    Joined:
    Aug 20, 2014
    Posts:
    36
    I am struggling mightily to create a custom mesh (grass) in Maya and integrate it into the AFS system in Unity. I have followed your AFS Model and Texture PDF instructions, and can't figure out the process. If I record a short screen-cap video of my process, can I send it to you to check out? I'm hoping this would allow you to spot what I am doing wrong. Thanks!
     
  30. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,910
    you may do a screencap.
    but if you are just going to do a rather simple gass model (single sided) then you do not have adjust vertex colors in may: you can simply use the afs grass model postprocessor to get the vertex colors applied on import. please have a look at the docs.

    lars
     
  31. mrwogs

    mrwogs

    Joined:
    Aug 20, 2014
    Posts:
    36
    Thanks again for the quick reply. I have read through the docs, but I guess I am missing something, or I'm not fully understanding your instructions. You mentioned: "afs grass model postprocessor" - which doc is that referenced in? If I can't figure this out, I will record the video and send you a link to it on Dropbox. Thanks again.
     
  32. Jochen-Hanisch

    Jochen-Hanisch

    Joined:
    Oct 7, 2013
    Posts:
    25
    Hi lars,
    we switched a project from unity 4.5 to 4.6 and now the billborads from the terrain trees are really dark, too dark. Do they have changed the billboard shader? The scene uses also skyshop. With unity3d 4.5 i had found nice settings and the look was fine. But now...
    A little screengrab

    Tia,
    Jochen
     
  33. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,910
    sorry, but i haven’t looked into 4.6 so far...
    2 random thoughts:
    - it might be skyshop overwriting any of the afs tree creator shaders
    - it might be unity having done some changes to the way lighting is passed to the rendertex shaders (like they did with unity 5): so you may try uncheck "use linear lighting fix".
     
  34. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Looks very similar to the issue i had with my game that i did not manage to solve so far. Have not looked in to it in a while now though.
     
  35. Jochen-Hanisch

    Jochen-Hanisch

    Joined:
    Oct 7, 2013
    Posts:
    25
    .. think it's point 2... they have changed something.
    I have tried it without skyshop and have the same results. But i found a little workaround. With a separate distance light only for the trees i can tweak the shading a bit...

    Jochen
     
  36. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,910
    hi jochen,
    now i had a look into 4.6.3. using linear lighting. and as you have mentioned: billboards are too dark.

    so i tested the original tree creator shaders and it turned out that:
    - neither ambient lighting is passed correctly.
    - nor direct lighting.

    so this is a massiv bug in version 4.6.3. i guess – and it is probably worthless to work on a workaround right now as this will most likely be corrected in the next release of unity.
    meanwhile you could use gamma instead.

    sorry about the inconvenience,

    lars
     
  37. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Thats great to know : )
     
  38. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,910
    i do not think so ;-)

    in fact it is a bitter pill. but unity 5 meanwhile handles linear lighting pretty well—even if it comes to billboards—so i guess and hope that the current problems in unity 4.6.3. are only temporary.
     
  39. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Well, its good to know its not my fault or your fault, then i dont have to spend more time trying to figure it out : p
     
  40. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,910
    i see.
     
  41. malteins

    malteins

    Joined:
    Jan 31, 2014
    Posts:
    24
    Hi Lars, I've been having this issue with the grass. All the grass patches slowly fade to black and then back to normal. What can this be? This did not happen with the regular shader in unity.
    I'm using Unity 4.6.1, AFS3, RTP3. The grass is painted as a texture using the terrain editor.
     
  42. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,910
    hi malteins,
    adding grass as a simple texture to the terrain might cause the problem.
    you should always add grass as mesh – otherwise you will stop the advanced foliage shader for the terrain engine from working properly.
    so it might be the problem – as i have never tested this case. other reasons might be wrong vertex colors – but it is pretty difficult to say anything about this without any knowledge of your project (like other packages included, color space, render path, ...).
    nevertheless: you are the first one to report such kind of problem so i assume it has something to do with your set up.

    lars
     
  43. malteins

    malteins

    Joined:
    Jan 31, 2014
    Posts:
    24
    Thanks for your quick reply, I'll be checking this out in a while. So I shouldn't use textures no more. Would the grass meshes you mean, be like two intersecting polygons, with the texture on it? This will increase my polycount though, right?

    Thanks again for your time, sincerely

    Martin
     
  44. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,910
    hi martin,

    a custom grass mesh might be just a simple quad. so it would not increase the polycount.
    but of course it might be more complex – which i highly recommend.

    in case you add your own quad and do not rely on unity’s built in one you can specify the uvs which would let you create your own texture atlas: this is needed in case you also want to add plants using the advanced foliage shader.

    lars
     
  45. astrand130

    astrand130

    Joined:
    Nov 9, 2014
    Posts:
    21
    Hello, I am trying to Use the AFS 3.0 in Unity 5 and I am getting an error due to the change in the way fog is handled in Unity 5.
    Afs_CustomFog.cginc (4):
    declaration of "unity_FogColor" conflicts with previous declaration at /UnityShaderVariables.cginc(174)

    I am also receiving a bunch of Implicit cast warnings but those are not my main concern. (I figure somehow I need to remove the custom fog effect completely and replace it with a placeholder half4 value in the CGINC file but i have had no luck getting it to work) Do you have any suggestions on how I could fix it?

    Thank you.
    -Alex
     
  46. malteins

    malteins

    Joined:
    Jan 31, 2014
    Posts:
    24
    Ok, I've managed to setup some mesh grass. I've actually used yours, the ones that come with the package.
    I'm still getting the same problem, my grass start turning darker and then back to a very bright shade. I've also followed your guidlines and documentation. Might this be some sort of issue with Unity 4.6.1?
     
  47. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,910
    afs for unity 5 is in development...
     
  48. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,910
    hi martin,
    it might be an issue with 4.6.1 – as i have just checked it with 4.6.3. and everything works as expected.
    lars
     
  49. hwills

    hwills

    Joined:
    Feb 28, 2015
    Posts:
    11
    Hi, I saw that you were putting together an update to fix Unity 5 issues, and I was just wondering if there was an eta on when that would be ready, or if there was a quick fix for the fog color conflict mentioned earlier. Thanks!
     
    CaptainMurphy and konsnos like this.
  50. x_african_warrior_x

    x_african_warrior_x

    Joined:
    Jun 24, 2014
    Posts:
    80
    Hi Lars, tried to convert unity tree to afs tree, i followed your directions to the best of my knowledge. somehow, its not looking great for me, check out the pic. have i missed something? if i try to adjust the alpha cut off any further, trunk disappears. afs-tree.jpg