Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

[Released] Stylized Grass Shader (URP)

Discussion in 'Assets and Asset Store' started by StaggartCreations, Jan 5, 2020.

  1. squallfgang

    squallfgang

    Joined:
    Sep 13, 2016
    Posts:
    9
    Thanks for the quick reply,

    now its working but it seams to be some kind of offset so it doesn't blend at the point where it should be (offset is in X/Z axis). I used the create Render Arrea from terrain button and the maps seems good but somewhere else it must be a caluclation mistake.

    Yes I'm using the Nature Render, but the distance fading wasn't the problem, It got a little better without it but didn't solve the problem. What helped make it disappear completely was putting the Value for Alpha Clipping to a much higher value.
     
  2. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,023
    It seems you are right, I made an elementary school level mistake, that's what I get for not paying attention in school :oops: This wasn't noticeable in my test cases, so went right past me, apologies!

    There's a small change you can make in the Color.hlsl file found in the Stylized Grass Shader/Shaders/Libraries folder. Where you can change line 24 from
    Code (CSharp):
    1. return  (b.xy * b.z) - (-wPos.xz * b.z);
    to
    Code (CSharp):
    1. return (wPos.xz * b.z) - (b.xy * b.z);
    I'll be sure to include this change in the following version.

    About the shadows, it sounds like you were using low resolution shadow settings. The grass casts very fine shadows because of the individual blades and may less than 1 pixel in the shadow map. This can result in popping or flickering, commonly referred to as "pixel swimming". Increasing Alpha Clipping value is one way to mitigate this, since the grass blade shadows will cover a larger area.

    An alternative is to improve the shadow quality in the pipeline settings by enabling soft shadows and using at least two shadow cascades. But I'll leave it up to you to decide what works best for your project ;)
     
  3. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,023
    Version 1.0.6 will feature a "Perspective correction" parameter. Which controls the amount by which the grass is gradually bent away from the camera as it looks down. Useful for better coverage in top-down perspectives.



    Grass will appear to be longer, but it's merely an optical illusion :p
     
    Lars-Steenhoff likes this.
  4. indieDoroid

    indieDoroid

    Joined:
    Jan 25, 2016
    Posts:
    268
  5. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,023
    Hi, not exactly. Much like any other shader, it will render without needing a Unity terrain. It can be placed on meshes as well. You can find more details on grass placement here.
     
  6. unity_No-zOCWa3BL-DA

    unity_No-zOCWa3BL-DA

    Joined:
    Apr 16, 2020
    Posts:
    1
    Hello, @StaggartCreations
    I bought this asset yesterday, but I have problem.

    all materials and prefabs colored pink (missing).
    Could you tell me how to fix this problem??

    my unity version is 2019.3.0f6(64bit)
    URP version is 7.2.0
     
  7. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,023
    One thing you could check is if there's a pipeline currently active, without this, shaders will fail to compile


    Additionally, you can check if the grass material is actually using the grass shader
    upload_2020-4-17_10-6-27.png

    But is already set up in the package. If anything is missing, be sure to import all the files from the package.
     
  8. DaleEidd

    DaleEidd

    Joined:
    Aug 11, 2019
    Posts:
    13
    • Stylized Grass Shader 1.0.5
    • Unity 2019.3.9f1
    • URP 7.3.1

    I noticed crippling performance issues in the demo scene when evaluating. I couldn't seem to get rid of it. Turns out there is 15 hidden cameras (GrassBendCamera) in it. Is this normal?

    There is an issue with MSAA and translucency. It is more prominent when combined with HDR. See images:

    Grass.jpg
    No HDR or MSAA

    Grass MSAA and HDR.jpg
    HDR and MSAA

    I am evaluating for Single Pass VR usage. In the demo scene after removing the hidden cameras, disabling the bend renderer, disabling the terrain, setting up GPU Instancer and disabling grass shadows, I was still experiencing lower than expected performance on the GPU. On a 2080Ti I was incurring about 2.5ms for the grass alone in VR which is more than the ocean renderer I am using. This doesn't seem right to me, but I am pretty green to all of this. It looks like the demo scene doesn't use LODs like the other prefabs you have provided. Would this make much of a difference?

    Looking forward to your thoughts. Asset looks really nice.
     
  9. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,023
    Thank you for the screenshots, these are always very helpful!

    I think the hidden cameras are a leftover from development. Normally, this camera is hidden and not saved with the scene, so there's always just one, and deleted when necessary. I'll look into cleaning up the scene, thanks for the headsup!

    I'll have the chance to test the case with MSAA and HDR tomorrow, and share my results. It may be worth to try and adjust the mipmaps of the grass alpha texture. You can enable "Fadeout Mip Maps" on the texture's import settings. Ideally at far distances, the texture would use a mipmap low enough so that it doesn't causes noise-like flickering.
    upload_2020-4-22_10-26-50.png

    The performance bottleneck you're experiencing may be related to overdraw, rendering multiple non-opaque pixels over each other. To mitigate this, the grass density can be reduced. Devices like Oculus Quest are particularly susceptible to this.

    What you can try, is to switch the shader on the grass material to the Lit or Simple Lit shader, and check "Alpha Clipping". If in this case the render time is still fairly high, it'll tell you if the bottleneck isn't the grass shader (it should be slightly faster than the URP shaders).

    Note that using the SRP batcher also influences performance, I've had better luck with turning it off. As I understand it's only suited for situations where there's a lot of material variants that use the same shader.

    I've added LODs to the demo scene prefab, and this does reduce render time by 1ms. But increases CPU from 6ms to 10ms, because the amount of GameObjects are tripled in this case, that's always the tradeoff of using LODs. But GPU Instancer doesn't use any GameObjects, so LODs in that case are still beneficial.
     
  10. maarcinn

    maarcinn

    Joined:
    Aug 13, 2013
    Posts:
    9
    Hey!
    Do you have any e.t.a. for this update? :D That's exactly what I was waiting for!
     
  11. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,023
    I was holding off, trying to implement another feature, but didn't work out. So I can probably submit a update this week, which will include this feature ;)
     
    maarcinn likes this.
  12. maarcinn

    maarcinn

    Joined:
    Aug 13, 2013
    Posts:
    9
    Awesome, can't wait to test it! :)
     
    StaggartCreations likes this.
  13. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,023
    Submitted v.1.0.6. Changelog:

    Minimum required URP version: 7.2.0. Tested in 7.2.1/7.3.1/8.0.1 (no issues in 9.0.0 so far, but too early to officially support)

    Added:
    - Perspective Correction parameter. Controls the amount by which the grass is gradually bent away from the camera as it looks down. Useful for better coverage in top-down perspectives

    Changed:
    - Improved visual quality of demo scenes through added color grading LUT and skybox

    Fixed:
    - Bug when using an override texture on a color map asset would cause it to be modified when re-rendering
    - Bug where grass would still sample a color map when switching to a scene without one active
    - Deleted hidden cameras from demo scenes, which caused a significant performance drop (development remnants)
    - Bright pixels at tip of grass in situations where translucency is prominent and MSAA is used. @DaleEidd
    - Bending render area being flipped in URP 7.3.1
     
    DaleEidd, maarcinn and Lars-Steenhoff like this.
  14. decoy98

    decoy98

    Joined:
    Aug 30, 2011
    Posts:
    31

    Attached Files:

    Last edited: Apr 24, 2020
  15. Mojo-Game-Studio

    Mojo-Game-Studio

    Joined:
    Sep 18, 2015
    Posts:
    76
    HDRP support please please and pretty please ;)
     
    r3ndesigner likes this.
  16. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,023
    A headsup, a bug came to light when using the grass in combination with the Unity terrain system and having perspective correction enabled. This causes shadows to flicker. Not an issue with other rendering methods.

    It's related to accessing the camera position (global value used in all shaders) in either the shadow or vertex stage of a shader. As far as I can tell this is a bug in the URP, where the camera position only updates when it's moving, otherwise resets to 0,0,0

    I already have a fix in place, but need to test it a bit further, to ensure it's not just a soggy patch :p

    Edit: reproducable in Shader Graph, filed a bug report, fingers crossed! You can vote on the issue here, if you're affected, this'll bump it up priority-wise
     
    Last edited: May 7, 2020
  17. maarcinn

    maarcinn

    Joined:
    Aug 13, 2013
    Posts:
    9
    Hey!

    @StaggartCreations The new update is great! Perspective correction is a cool addition :)

    So, I was thinking about adding grass bending feature to my project. I can have many objects in my scene which would bend the grass, probably up to ~50, maybe even more in the future. These objects have some basic physics. I'm not sure how heavy the grass bending can be, but is it a good idea to add it to so many objects in one scene? The player can see the whole scene, so it's possible to have many object affecting the grass on the screen at once. Can it be too heavy for the PC or it doesn't matter how many objects use grass bending feature?
     
  18. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,023
    Glad you like it!

    The grass bending is nothing to write home about, performance wise. Each grass bender does take up one drawcall, since batching the meshes is not very straightforward. Though, anything outside of the render area is skipped, so you can potentially have grass benders all across the world, without them being processed. There's no hard limit on how many grass benders can be active at a time, but attaching one to an army of 1000 individual soldiers would, for example, be stretching it.

    Manipulating the objects through physics won't have any adverse effects. In the end, the position of the object is what's being used.
     
    maarcinn likes this.
  19. maarcinn

    maarcinn

    Joined:
    Aug 13, 2013
    Posts:
    9
    Awesome, thanks for the answer. We're going to test it in the project then :)
     
  20. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,023
    Adding support for "alpha to coverage" in 1.0.7, which will be a toggle on the material. This only works when using MSAA, but reduces aliasing when used which is particularly helpful in VR.

    upload_2020-5-4_8-53-49.png
     
    Last edited: May 4, 2020
    DaleEidd likes this.
  21. HQF

    HQF

    Joined:
    Aug 28, 2015
    Posts:
    18
    Hi!i it does not support mobile totally? Or it's just not tested? Because you said above, that it's does not tested.. I need it)

    UPD:
    Ok i bought it..) lets try on Android first

    UPD2:
    Prefab from project (grassPatch_10m) works perfectly on Android build! So now i need to configure it for my game and test again)
     
    Last edited: May 3, 2020
    StaggartCreations likes this.
  22. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,023
    In the sense that I haven't tested it. I'm not planning on chalking up mobile as supported as this means I need to test every update on a stack of different devices, across multiple Unity versions. This has proven to take up an entire day :p
     
  23. HQF

    HQF

    Joined:
    Aug 28, 2015
    Posts:
    18
    So i tested it for you - on Android works well, but "Simple" mode works strange with point lights, but "Advanced" mode works as expected.
     
  24. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,023
    Submitted v1.0.7

    Minimum required URP version: 7.2.0. Tested in 7.2.1/7.3.1/8.0.1

    Added:
    - Alpha to coverage toggle to shader, reduces aliasing when using MSAA
    - Thick grass texture and prefab

    Changed:
    - Wind gust tint is now applied after translucency, resulting in more natural lighting behaviour.
    - Set all grass textures to "Clamp" to avoid thin lines at tip of grass at lower mipmaps
    - Expanded state of material sections are now saved until Unity is closed
     
  25. wechat_og5za0pR45Blod9q4CkxloeI6iow

    wechat_og5za0pR45Blod9q4CkxloeI6iow

    Joined:
    Dec 2, 2018
    Posts:
    39
    hello my friend ,i just bought this asset and it work very well!
    now I have a small question,that if i want to create the effect like character use knife cut grass or fire burn,in tranditional i have to add collider to each of grass,but I don't think it will have a great performance,so if I want to achieve it,what is the best way?
     
  26. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,023
    Burning grass isn't possible I'm afraid, this would require a specific implementation. Grass cutting could be possible (probably with a Trail Renderer), but it all comes down how you handle the trails.

    Here is a TrailRenderer with the GrassBender component attached to it. The Height Offset is turned all the way down, Strength to 3 and Push Strength to 0. This'll essentially push the grass through the ground and provides the illusion of being cut.

    upload_2020-5-8_10-19-34.png

    Once the TrailRenderer starts to move it also starts to die off, and the grass will start to spring back up. So it should be possible to turn the trail into a prefab, and spawn attached to a sword once it starts swinging. After the swing has finished, it should be unattached and left as is. I'm not savvy with animations, but it should be possible to tell when an animation starts, and when it has finished.
     
  27. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,023
    Submitted v1.0.8

    Changed:
    - Bending renderer now moves to follow target transform intermittently, rather than constantly. This eliminates any possible movement flickering in the grass.
    - Corrected settings for BendParticles prefab, it can now also be used as a child object.
    - Wind gust tint no longer applies to emission, so will respond correctly to lower direct light intensity (eg. dawn/dusk/night)

    Added:
    - Wheat texture and prefab
    - StylizedGrassRenderer script now has a static SetPosition(Vector3 position) function

    upload_2020-5-8_17-12-31.png
     
    Last edited: May 8, 2020
    rrahim and Lars-Steenhoff like this.
  28. wechat_og5za0pR45Blod9q4CkxloeI6iow

    wechat_og5za0pR45Blod9q4CkxloeI6iow

    Joined:
    Dec 2, 2018
    Posts:
    39
    hello my friend ,please help me, is there any way to modify the shader to support translucent texture but not Alpha Cutoff?
     
  29. rrahim

    rrahim

    Joined:
    Nov 30, 2015
    Posts:
    182
    Those wheat prefabs are exactly what I was looking for!!!
    Thank you!
     
    StaggartCreations likes this.
  30. Trigshady

    Trigshady

    Joined:
    Jul 18, 2017
    Posts:
    2
    Hi, I'm interested in your asset, though I have a question if this is compatible with LRP? (Lightweight Rendering Pipeline, from my understanding it's pretty much the same as URP), as I'm using a bit older version of Unity, I know I can upgrade/migrate my project to 2019.3 URP, but due to certain feature which remains with older Unity version, I would like to stick to my current setup. My Unity version I work with is 2019.2.21f1. Thank you.
     
    Last edited: May 20, 2020 at 6:06 PM
  31. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,023
    Afraid not, everything was written for the URP 7.2.0, and makes use of the shader library from that version onward. The differences between LWRP 6.9.2 and URP 7.2.0 are both minor and large, meaning things can only be made to work for one or the other.
     
  32. Trigshady

    Trigshady

    Joined:
    Jul 18, 2017
    Posts:
    2
    Appreciate prompt answer, will get the asset anyway for future projects, looks too good not to have :)
     
    StaggartCreations likes this.
unityunity