Search Unity

Stylized Grass Shader [URP] ☘️

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

  1. squallfgang

    squallfgang

    Joined:
    Sep 13, 2016
    Posts:
    21
    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:
    2,258
    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:
    2,258
    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. KarlKarl2000

    KarlKarl2000

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

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,258
    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:
    2,258
    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. D1234567890

    D1234567890

    Joined:
    Aug 11, 2019
    Posts:
    64
    • 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:
    2,258
    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:
    11
    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:
    2,258
    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:
    11
    Awesome, can't wait to test it! :)
     
    StaggartCreations likes this.
  13. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,258
    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
     
  14. decoy98

    decoy98

    Joined:
    Aug 30, 2011
    Posts:
    36

    Attached Files:

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

    Mojo-Game-Studio

    Joined:
    Sep 18, 2015
    Posts:
    111
    HDRP support please please and pretty please ;)
     
    Glader and r3ndesigner like this.
  16. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,258
    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:
    11
    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:
    2,258
    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:
    11
    Awesome, thanks for the answer. We're going to test it in the project then :)
     
  20. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,258
    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
    D1234567890 likes this.
  21. HQF

    HQF

    Joined:
    Aug 28, 2015
    Posts:
    40
    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:
    2,258
    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:
    40
    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:
    2,258
    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. ununion

    ununion

    Joined:
    Dec 2, 2018
    Posts:
    275
    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:
    2,258
    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:
    2,258
    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. ununion

    ununion

    Joined:
    Dec 2, 2018
    Posts:
    275
    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:
    206
    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
  31. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,258
    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.
  33. Osteel

    Osteel

    Joined:
    Jan 17, 2014
    Posts:
    59
    Hi!

    Just bought this asset and am in love with it, it looks great. Just a quick question: am I just missing it, or is there no way to alter the height of the grass without importing a new texture?

    Thanks. :)
     
  34. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,258
    Glad to hear you like it!

    It's currently not possible to scale the grass through the shader. The only way is to edit the mesh to make it longer. Scaling the prefab on the Y-axis is also possible, but this breaks GPU instancing, which requires a uniform scale.

    I still have an idea for setting how tall the grass should be, per terrain material. But it's kind of a stretch goal given the complexity to do this in URP.
     
  35. gdespaux2010

    gdespaux2010

    Joined:
    Feb 16, 2017
    Posts:
    34
    Hi! Just picked this up and was wondering if it's meant to be able to work with your FAE asset? I like the included grass with this shader, but the grass prefabs are large and aren't broken down into "single" placement meshes. They're great for mass placement but for fine details I'd really prefer the grass in your other asset. Thanks!
     
  36. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,258
    Yes, this possible, the meshes both have a vertex color gradient baked into them, which is the main requirement. And good point! I can add a smaller grass mesh variant, no problem!
     
    gdespaux2010 likes this.
  37. gdespaux2010

    gdespaux2010

    Joined:
    Feb 16, 2017
    Posts:
    34
    Awesome, I'll give them a try and see!

    Thank you! That's a big help :)
     
  38. gdespaux2010

    gdespaux2010

    Joined:
    Feb 16, 2017
    Posts:
    34
    Having an issue with Unity 2019.4.1, using URP 7.4. The grass bender seems to report a mirrored position to the renderer. This happens in the demo scene as well as in my game scene.
     

    Attached Files:

    • Bug.png
      Bug.png
      File size:
      855.8 KB
      Views:
      373
  39. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,258
    Thanks for the headsup! I didn't even release there is a 7.4 version now.

    The issue you're seeing isn't out of the ordinary, because so far, with URP version release the coordinates have to be flipped (and flipped back the next version) :rolleyes:

    I'm preparing the update for the package, so I'll be sure to test 7.4 and make any necessary changes.
     
    gdespaux2010 likes this.
  40. gdespaux2010

    gdespaux2010

    Joined:
    Feb 16, 2017
    Posts:
    34
    If Unity breaks this particular method often enough, you may as well add a checkbox for "Flip Coordinates" into the component :D

    Sounds good, I'll wait for the fix in the next update. Thank you!
     
  41. gdespaux2010

    gdespaux2010

    Joined:
    Feb 16, 2017
    Posts:
    34
    If anyone is using Nature Renderer from Visual Design Cafe, you can easily convert this to work with their Procedural Instancing. In the StylizedGrassShader.shader:

    Add

    "NatureRendererInstancing" = "True"


    in the "Tags" section of your shader, near the top.

    Then change all instances of


    #include "Libraries/VS_InstancedIndirect.cginc"
    #pragma instancing_options renderinglayer procedural:setup


    with


    #include "Assets/Visual Design Cafe/Nature Shaders/Common/Nodes/Integrations/Nature Renderer.cginc"
    #pragma instancing_options procedural:SetupNatureRenderer


    The multi_compile_instancing keyword is already there.
    Of course, if your NatureRenderer.cginc file is somewhere else, please use that path instead.

    Thanks to Staggart Creations for guiding me on how to change it!
     
    Last edited: Jun 24, 2020
    noriox and StaggartCreations like this.
  42. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,258
    Submitted version 1.0.9. Changelog:

    Verified compatibility with URP 7.4.1

    Added:
    - Support for Nature Renderer's "Procedural Instancing".
    * A option has been added at the bottom of the grass material to switch between Vegetation Studio and Nature Renderer integrations
    - "GrassSingle" model/prefab. A version of the GrassPatch prefab but with a single tuft.

    Changed:
    - Revised demo scene
    - When using the Simple Lighting mode, the color map is now also sampled per-pixel (texture would otherwise multiple over it)

    Fixed:
    - Bending area being flipped in URP 7.4.1
    - Scenario where objects other than terrains could be rendered into the color map
    - Sun light adding additional light when at a steep angle, causing color map to not match up with terrain
    - Translucency now handles HDR light colors better

    Revised demo scene (shader apparently works well for tree branches too)

    upload_2020-6-27_15-35-8.png
     
    gdespaux2010 likes this.
  43. Zagalcortez

    Zagalcortez

    Joined:
    Jul 3, 2020
    Posts:
    4
    fisrt time using this asset, and i am trying to use the bend trail, but after some time pass the grass start to flick, and it doesnt stop until i restart my project, any idea of whats hapenning?
     
  44. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,258
    Would you mind send a video/gif that shows this? That'll give me a better idea what the possible cause could be!
     
  45. Zagalcortez

    Zagalcortez

    Joined:
    Jul 3, 2020
    Posts:
    4

    Hi, thnx for the reply, this is the link, it occurs after a while has pass in the proyect.
     
  46. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,258
    Thanks for the video! Is your world by any chance very large (+2x2km), or moved away far from the world origin (0,0,0)? Does this also occur if you use a mesh or particle (BendParticleTrail prefab) for bending? That would tell me if the issue is specific to trails, or bending in general. Also, could you tell me which version of URP you are using? Lots of questions, but I need to try and reproduce the same issue, in order to figure out where something goes wrong ;)
     
  47. Zagalcortez

    Zagalcortez

    Joined:
    Jul 3, 2020
    Posts:
    4
    the terrain scale is 500x500x500, the origin is 0,0,0, tried both and the same result, the version is 7.4.1, and again thnx for your response.

    i dont know if a did it right but i also copied the same parameters from one of the demos, and still doesnt work for me.
     
  48. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,258
    I'm unfortunately unable to reproduce any issues like you're seeing, despite my best efforts. As a last resort, it would be most helpful if you could send me a repo project where the issue occurs (or the entire project). This way I'll be able to pick away and debug to find the cause. You could send this in a PM or contact@staggart.xyz
     
  49. Glader

    Glader

    Joined:
    Aug 19, 2013
    Posts:
    456
    Any plans to create an HDRP implementation?
     
    Mojo-Game-Studio likes this.
  50. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,258
    No plans I'm afraid, since URP and HDRP are very different in their shader libraries and rendering scripting. Perhaps in the future when surface shaders are a thing, it'll be more straightforward to do/maintain.