Search Unity

Advanced foliage shader [released]

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

  1. AlexanderElert

    AlexanderElert

    Joined:
    May 31, 2017
    Posts:
    26
    Hello. How are you?

    I'd like to know what I'm doing wrong here.

    I have a prefab with AFS material / foliage shader

    I try to use it with the detail paint (render mode: vertex lit) of unity ground but incorrect shadows appear.

    screenshots (on the left detail paint - to the original right prefab) increasing the environment lighting but the problem persists:
    1.jpg 2.jpg

    *Its doest happend with the tree paint on terrain

    Thanks!
     
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,955
    unfortunately details added to the terrain do not cast any shadows: unity simply does not render them as shadow casters – no matter which shader you assign. trees do cast shadows.

    so the black something you see at the bottom of the fern is not a shadow but most likely ambient occlusion, which then would be way too high. please make sure that if you have enabled "legacy bending" in the setup script you use a proper model on the terrain which has bending only in vertex colors rgb and occlusion in alpha. also make sure that dry and healthy color a within a proper range.

    look here for more details:
    https://docs.google.com/document/d/...Y5H46FtpSDM1UQdRk/edit#heading=h.vss7ysh7n64e
     
  3. AlexanderElert

    AlexanderElert

    Joined:
    May 31, 2017
    Posts:
    26
    UPDATED: I fix it, the black something is a bad configuration of Translucency/AO post effect/Lightmap sethings.
    * I provide shadows to details added to the terrain with SSS (http://www.sonicether.com/screenspaceshadows)

    Thanks!

    3.jpg
     
  4. totrider

    totrider

    Joined:
    Jul 25, 2014
    Posts:
    13
    Not ideal as i still loose complete control, but i imagine it should work. Will try it out next time i have time and see what i can make out of this.

    Ok, so i went to the cast scene again, but it didn't initially sort itself out by going into play mode. However, i hadn't ticked the "Enable GPU Instancing" button, as it is off by default and i have only a vague idea of what it actually does. If it is not enabled, the ghosting effect persists in play mode as well. If you mentioned this earlier, it might have slipped through when i tried to debug.

    It wouldn't have been a big deal anyways, as i am not using the cookie version light while setting up the scene. It makes it easier to determine if i match colors and such right as there wont be any interfering "noise".

    Tried removing that script, but the issue is still caused by AfsFoliageToolEditor, so this doesn't work. Isn't the "GrassMeshPostprocessor" also what enables us to do stuff like: plant_01_AfsGM05? cause that is super useful for simple grass and plant meshes.
     
  5. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,955
    it gives you a lot of control :)

    hmm, unity 2017.3 does not even let me deactivate instancing.
     
  6. lGillot

    lGillot

    Joined:
    Apr 11, 2013
    Posts:
    1
    Hi,
    I've just bought AFS5 and imported it in my project. My terrain and grass was already there and working fine. I just wanted to upgrade the shader. And here what I get now.



    Does somebody have a clue of what's going on? I guess there's something simple to tweak ?

    Thanks
     
  7. fgardler

    fgardler

    Joined:
    Jun 11, 2016
    Posts:
    12
    I inadvertently bought V5 when the asset I wanted to use it with requires V4. Is there a way to easily convert the V4 assets to work with V5. Currently I get no shading on those assets (all V5 demo scenes work well).

    Alternatively, since I paid the price of V4 + upgrade can I get a copy of V4 until the other asset is update?
     
  8. totrider

    totrider

    Joined:
    Jul 25, 2014
    Posts:
    13
    Interesting. So i got a better look at it today and it seems like the trees don't wobble when it is ticked... maybe i should just try to update Unity to a newer version or do a fresh install? xD But they seem to work more like intended now, the trunk doesn't wobble, the trees sway more like your examples, so all is good it seems.

    You still get the original weird bend seen in the highlight when selecting objects in scene view, but that doesn't matter ofc.
     
  9. Game-Armada

    Game-Armada

    Joined:
    Apr 29, 2013
    Posts:
    62
    AFS_unityTreeTest.jpg
    Randomly placed Unity3D trees with AFS
     
  10. Game-Armada

    Game-Armada

    Joined:
    Apr 29, 2013
    Posts:
    62
    a quick test

     
    boysenberry likes this.
  11. Ranter1337

    Ranter1337

    Joined:
    Nov 4, 2015
    Posts:
    15
    i have an issue where when i walk around grass placed and the player animates, i get a weird reflection/ghost effect and was wondering what is causing this, only happens when the camera is set looking at the player and directly at the grass, using deferred rendering with the shaders set up properly
     
  12. swredcam

    swredcam

    Joined:
    Apr 16, 2017
    Posts:
    106
    I'm using this asset with Yughues Underwater Plants and it looks great, however I can't set the wind motion nearly as low as I want. I want a slower wave frequency and much less bending /motion than occurs now. I am using the V4 foliage shader and have the two "wind settings for foliage" set to minimum. I'm not sure if any other sliders impact foliage but I have tried all of them at each extreme and there is always just too much action. Is there anything I can do to reduce motion? I don't have any other wind sources.
     
    hopeful likes this.
  13. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,301
    Would first make sure there is no edge fluttering. Vertex green. After that might have to get into the code for speed, wave size. Can not remember right now if that is exposed. Just not sure how to get it looking right with underwater and above water plants in the same scene. Vertex green would be a part there and keep the main bending low but otherwise would have to be a transition above to below water to windzone speed, wave size.
     
  14. swredcam

    swredcam

    Joined:
    Apr 16, 2017
    Posts:
    106
    I don't see a setting for vertex color in the setup script. This is V4 so maybe that is not present? Also, at the moment the plants are all fully submerged so I only need to deal with the single motion case. I like what I see now, it just needs to be much slower. The plants bend wildly right now, and at way too high a rate.
     
  15. swredcam

    swredcam

    Joined:
    Apr 16, 2017
    Posts:
    106
    Guys, I figured out my problem. I had not been seeing the "W" component of the wind vector as that line is so much wider than the others -- it was not visible in my windowed Inspector. Also, the descriptor for that field was not readable so I did not see that it was for intensity. Once I maxed out that window I noticed it and that really lets me slow down the wind. Thanks for your help!
     
  16. swredcam

    swredcam

    Joined:
    Apr 16, 2017
    Posts:
    106
    OK slightly different question. For WebGL builds linear space is not an option. When I build with gamma space, the plants look fine up close but at a distance the separate models are visible and it looks like the plant is jumping around at the base. It seems like it is very close to working since it looks fine close up. Is there a way to correct this or is the only option sticking to close-up plants? Everything looks fine for an x86 build and the only difference is the color space.
     
  17. ryanflees

    ryanflees

    Joined:
    Nov 15, 2014
    Posts:
    24
    Hi, I'm trying to learn how you implement translucency in deferred rendering for a few days.
    It seems that you are using gbuffer2.a to transport the value to deferred lights, but if I'm not remembering wrong, gbuffer2 is in format of ARGB2101010 so the A channel in gbuffer2 should be 2bits.
    The official doc.
    https://docs.unity3d.com/Manual/RenderTech-DeferredShading.html

    And here are some codes from the AFS lighting fuctions, I don't know how you succeed to put 0.75 and 0.66 to it. (outNormal is the gbuffer2 here)
    outNormal = half4(s.Normal * 0.5h + 0.5h, 0.75h);
    outNormal = half4(s.Normal * 0.5h + 0.5h, 0.66h);

    And also read it from gbuffer2
    half TransMat = floor(gbuffer2.a * 3 + 0.5f) == 2 ? 1 : 0;
    If the A channel is a 2bits value it wil always be either 0,1,2,3 none of them can trade the floored value to == 2.

    There is also a code where translucency set to gbuffer3.
    emission = half4(s.Emission + c.rgb, translucency);
    But it seems never get read from deferred lights. I don't know why it's done this way.

    Sorry I'm still a noob shader programmer so I just want to find the answer. Thanks for reading this.
     
  18. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,955
    it will be ramapped to 0.0-1.0 on the gpu. it does not have an idea about integers.
    that is for other deferred lighting solutions - maybe uber or alloy.

    afs writes a material id into gbuffer2.a. and then remaps the gbuffer1 accordingly.
     
    ryanflees likes this.
  19. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,955
    do you have a screen shoot of the ghosting effect?
     
  20. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,955
    hmm, i never tried gamma. but how can plants in the distance look differently? and jump around?
    do you have a screen shoot?
     
  21. swredcam

    swredcam

    Joined:
    Apr 16, 2017
    Posts:
    106
    I solved my problem with the jumping, it's not a problem with the shader. Underwater Plants comes with a bunch of prefabs, including some intended for AFS specifically. I am using the AFS prefabs but it seems like a few have LOD issues. When the LOD level changes the plants go from waving normally in the wind to wild gyrations, with the base of the plant moving around. Because I have a relatively fixed distance for viewing of these I just deleted the LOD and everything seems fine now. Thank you.
     
    hopeful likes this.
  22. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,955
    great!
     
  23. Game-Armada

    Game-Armada

    Joined:
    Apr 29, 2013
    Posts:
    62
  24. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,955
    have you assigned the deferred lighting and reflection shaders that ship with the package?
     
  25. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,053
    Hello! dry grass is pink and I got this error on import...

    Shader error in 'AFS/Foliage Shader': texld/texldb/texldp/dsx/dsy instructions with r# as source cannot be used inside dynamic conditional 'if' blocks, dynamic conditional subroutine calls, or loop/rep with break*. at line 216 (on d3d9)

    Compiling Fragment program with DIRECTIONAL EFFECT_BUMP
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP UNITY_COLORSPACE_GAMMA


    ?
     
  26. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,955
    which version of unity do you use?
    which version of afs?
    and what is your target platform?
     
  27. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,053
    latest 5.6 . latest realease. pc
     
  28. Teosis

    Teosis

    Joined:
    Jan 24, 2018
    Posts:
    20
    Hi. I'm getting some funny results with Alloy deferred lighting/reflections. I have uncommented #define Alloy as the documentation suggested. I did re-import the demos. (Afs_Camera-DepthNormalTextureis is applied, ColorSpace is Linear.)
    Switching to the AFS lighting/reflections does fix the artifacts but not the problem with Alloy. Any help with that? Am I missing something?

    Picture below taken from the Foliage Shader Overview Demo Rainy scene (Trees' leafs offcamera are of the same strange color as the grass[Added new picture to showcase it]).
    Same occurring for the following demos: 02 Touch Bending Demo (Same weird color), 03 Tree Demo (esp with LODs: As camera moves closer the trees would become this weird color as on the picture below), 07 LOD Groups demo, 08 CTI for AFS demo.
    But, I see no noticeable difference between Alloy/AFS lighting/reflections in the: 01 Foliage Shaders Overview (not rainy), 04 Wind Demo and 06 CTI Demo.

    1. https://imgur.com/a/xeR9q
    2. https://imgur.com/a/8Qf81

    Unity 2017.3.0f3
    Alloy 4.3 (Last one atm, basically)
    AFS 5.077 (Judging from the last change-log entry)

    ADDENDUM:
    1. I've re-tested everything in the blank project with only AFS and Alloy imported, I can confirm aforementioned issues have still persisted.
    2. There is additional setup which Alloy provides to make use of its Skin and Transmission deferred shaders to display correctly. For this to work one have to add Alloy Deferred Skin ( << I'm more interested in this one) or Alloy Deferred Transmission instead of the standard Alloy Deferred Shading shader in the Project Settings/Graphics/Deferred.
    In which case on top of the aforementioned issues I've got a white fill superimposed on the tree and grass:
    https://imgur.com/a/pUGHY
     
    Last edited: Apr 12, 2018
  29. Fluffy-Tails

    Fluffy-Tails

    Joined:
    Jun 28, 2009
    Posts:
    114
    Can this asset be used to create fur on animals?
     
  30. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,955
    most likely: no...
     
  31. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,955
    you should upgrade to afs 5.078 – as my first attempt in 5.077 did not really work out...
    nevertheless you screen shoots look pretty strange and it seems as if the shaders still are using the afs gbuffer layout.
    so after enabling alloy in the lighting function you have to reimport all afs shaders.
     
  32. Teosis

    Teosis

    Joined:
    Jan 24, 2018
    Posts:
    20
    Thank you! Re-importing the shaders indeed got the issue resolved
    P.s. Turns out my current AFS version is actually 5.078, not 77; I should have just checked it in the asset store, not in the change-log.
     
    Last edited: Apr 13, 2018
  33. ArthurForst

    ArthurForst

    Joined:
    Oct 30, 2015
    Posts:
    3
    Hello lars,

    I am using the afs5 shaders in my current project.
    They have really brought some life to the environment.
    As development progressed I came to implement a day and night cycle.
    It was then that I noticed that the tree billboards are casting shadows but are not receiving them.
    This makes distant trees in the shadows of a mountain look as if they were glowing and also ruins the otherwise beautiful transition.

    I have also tested this with a completly fresh setup; no luck.
    Is there any way to make the billboards receive shadows?
    I have tried to look into it, but I can't seem to find a simple solution for this that I am able transfer to your shaders :\

    Trees as billboards (notice that the ones behind the cube are not receiving shadows):
    NotReceiving.PNG
    Just to show you that they are really in the cubes shadow range, here is a screenshot with a greater mesh range.
    Receiving.PNG

    I am using unity 5.6.5f1 and the latest release of AFS 5.
    The current billboard shader I am using is the cutout one.

    I hope you can help me out. Thank you.
     
  34. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,955
    afs billboards are based on unity built in ones and are pre lit in an offscreen pass, so that the billboard textures already contain lighting.
    adding real time shadows on top of this is possible but really looks odd on nearby billboards (like 50–80m).
    so i stopped looking further into this.

    regarding your screen shoots: i would suggest that you hide the missing shadows by adding fog.
    even if you would not need it to hide anything fog will add much more depth to your scene.
     
  35. ArthurForst

    ArthurForst

    Joined:
    Oct 30, 2015
    Posts:
    3
    Thank you for your response, Lars.

    I have added fog, and yes, that makes the scene looks much better and more natural.
    It was still not to my liking though as shadow popping effects could be seen in the distance.

    So I decided to get into shader coding and voila:
    I now have made a derivate version of your shader, which supports lighting on billboards via AutoLight.cg.
    Of course I am not going to post the modified shader as the base is not free, but everyone who is new to shaders will very likely get it going by carefully reading the explanations in this thread (you have to add about 5 commands to the shader):
    https://forum.unity.com/threads/ple...hadow-casting-receiving-sprite-shader.477358/
    I wonder why i did not get into this stuff way earlier as it is not that complex when working with already defined libraries. Everything just seems to be poorly documented.

    For everyone interested, here is a screenshot of the same scene with fog and billboard shadows (also unity 2017.3.1f1 this time):

    Billboard shadows.png
     
    Last edited: Apr 16, 2018
    hopeful and Game-Armada like this.
  36. patrick-holder

    patrick-holder

    Joined:
    Nov 16, 2013
    Posts:
    2
    Hi there,

    I'm using the Megascans assets which are already vertex painted, although they are painted in reverse to the models in the foliage shader package (https://quixel.se/megascans/help/PlantSetup.pdf). For example the green flutter is more intense on the bottom of the plant as opposed to on the tips of the leaves, meaning that the plant wiggles around at the bottom like crazy.

    Is there a way to reverse this somehow without having to repaint a ridiculous amount of the MegaScans models?

    Thanks

    VertextPaintedExample.png
     
  37. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,955
    you would have to edit the foliage shader.
    look for the vertex function "AfsFoligeBendingGSFull" which calls the bending function "AfsAnimateVertex". bending params are passed using the vector4 variable "bendingCoords".
    r = phase
    g = edge flutter
    b = branch bending
    a = primary bending

    so in order to reverse e.g. edge flutter you would write:
    bendingCoords.g = 1.0 - v.color.g;
    but i am not sure what you could derive from vertex color blue and red. all vertex colors seem to have just a simple gradient from bottom to top – with slightly different contrast.
    you should however map one of these colors to primary bending -> bendingCoords.a in order to make the hole plant sway along the wind direction.
     
  38. patrick-holder

    patrick-holder

    Joined:
    Nov 16, 2013
    Posts:
    2
    Thanks for your reply, unfortunately after many hours I've tried to add this code into the shader code and I'm having no luck. I'm more of an artist and not a programmer.

    Would it possible to send me the shader with the edge flutter reversed please? Or tell me which line/s to remove/add and where?

    It'd be awesome if you could add a Megascans compatible version of the shader in a future update :)
     
    Last edited: Apr 26, 2018
  39. kepesh

    kepesh

    Joined:
    Dec 29, 2017
    Posts:
    77
    Hi,

    Does AFS grass shader work with Vegetation studio? I'm only seeing a foliage shader, not a grass shader.
     
  40. Fabbs

    Fabbs

    Joined:
    Dec 2, 2013
    Posts:
    25
    Hi! Any news on getting AFS to work with HD render pipeline? Thanks
     
  41. reggie_sgs

    reggie_sgs

    Joined:
    Jun 29, 2014
    Posts:
    182
    Can you tell me what the difference is between your Shader v.4 and v.5 packages? I'm not really looking for a feature list difference but just wondering which I would need. Is the v.5 the most recent and v.4 just around for legacy support? Since both are still active, I wasn't sure if you needed both or just one depending on what you're doing.
     
  42. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,955
    only the foliage shader supports vegetation studio so far.
     
  43. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,955
    unity 2018.1 still has not been released.
     
  44. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,955
    yes.
     
  45. Fabbs

    Fabbs

    Joined:
    Dec 2, 2013
    Posts:
    25
    It has now :)
     
  46. reggie_sgs

    reggie_sgs

    Joined:
    Jun 29, 2014
    Posts:
    182
    One of the issues I've had with Unity's terrains is the framerate loss with grass and trees. Does this replace the default terrain grass and tree system? What I need is a way to improve the performance for these two areas. If it does replace the Unity terrain system, is it compatible with terrain tools like Gaia?
     
  47. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,955
    it does not.
    grass uses the built in functionality – if you want a replacement you may have a look at my advanced terrain grass asset.
    regarding trees: afs only supports tree creator trees, which are – compared to speed trees – quite fast out of the box.
    yes.
     
  48. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    527
    Hi @larsbertram1

    I bought his AFS asset and I was starting to play with him a bit.
    Is there any way to create more prefabs with different grass models? A video would be very helpful.

    Another question. Is AFS compatible with the new Unity 2018 render pipelin? If not, when do you plan to include it?

    I await your response, regards.
     
    Gabriel_SG likes this.
  49. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,955
    it is all about custom meshes and prefabs. use the foliage tool, the grass model postprocessor and your 3d app to do so following the instructions provided by the docs (regarding vertex colors etc).
    it is not compatible with the srp and i do not know when i will look into this: all pipelines are marked as "preview" as well as the shader graph. so a lot of things may change...
     
  50. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    527
    ok. Thanks!