Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Stylized Grass Shader [URP] ☘️

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

  1. nu51313932

    nu51313932

    Joined:
    Oct 28, 2016
    Posts:
    83
    do you have the builtin verson of shader
     
  2. jmattarock_unity

    jmattarock_unity

    Joined:
    Mar 10, 2018
    Posts:
    28
    Is there a good Demo of the Bend and flatten feature?
     
  3. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,303
    This was never made, so the short answer is no :p

    Not currently, this would have been linked on the store page. Could stand to make a proper demo build, but for now I've made a build of the included demo scene: https://1drv.ms/u/s!AlkpXXlKu-02xfknEpC_jx18D46sXw?e=u7URpB
     
  4. JulienCh

    JulienCh

    Joined:
    Apr 3, 2018
    Posts:
    6
    Hi ! I just bought the stylized grass shader on the asset store wich is a nice asset but I am wondering how you guys get your cool grassfields with a buch of grass prefabs without killing performances. I am working on a big open world and I tried to use the Unity tree system to populate my terrain but I can't expect more than dozen grass clumps with this method. GPU instantiate and SRP are activated. Do I need a third party instancier as Vegetation studio or GPU instancier ? I would like to achieve something like Genshin Impact. Thanks !
     
  5. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,303
    Glad you like it! There's a section in the documentation that covers achieving large amounts of grass in a practical sense: https://staggart.xyz/unity/stylized-grass-shader/sgs-docs/?section=placing-grass

    Personally, my recommendation always falls on Vegetation Studio, since it handles both spawning and rendering and does both very well. Unity's vegetation system is simply too outdated, and was designed around the ~2003 era where grass in games was generally very sparse.
     
  6. JulienCh

    JulienCh

    Joined:
    Apr 3, 2018
    Posts:
    6
    Thanks ! Also, the grass colormap renderer break my terrain tiles when I use it. Do you know what can be the problem ?
    Capture.JPG
     
  7. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,303
    There's an explanation for this, seems like you've run into a bit on an edge-case. The terrains are temporarily moved up 1000 units, so objects like rocks and buildings don't inadvertently get rendered into the texture. This only happens when the "Use Layers" option isn't checked.

    After rendering, the terrains are moved back to their old position. Though, the original height is based on just the first terrain, since terrains share the same height position, conventionally speaking. Out of curiosity, what did you use to create the terrains? As they all appear to be a different height.

    Nothing that can't be taken into account though! What I'll do is save the original height value, per terrain, so they all get positioned back exactly as they were, on an individual basis. I'm preparing an update for the asset, so I'll be sure to include this change moving forward.
     
    Last edited: Apr 30, 2021
  8. JulienCh

    JulienCh

    Joined:
    Apr 3, 2018
    Posts:
    6
    Great ! I understand now thank you ! I use Houdini PDG to generate my terrain into Unity. And it is true that some of the tiles got a weird Y value... I never noticed that.
     
  9. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,303
    Thanks, that's certainly a logical explanation. I've meanwhile added and tested handle terrains are different individual heights, I'll PM you a package with the modified script, but this'll also be included in next update.

    Thank you for the review, highly appreciated!
     
  10. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,303
    Submitted v1.1.6

    Added:
    - Preliminary support for Deferred rendering in URP 12+. Due to its nature, translucency will not work with this rendering path
    - Configured _BaseColor as an exposed parameter for Hybrid Renderer v2 (more can be added following the same structure in the Input.hlsl file)
    - Support for LOD crossfading in Vegetation Studio Pro beta 1.4.2.1

    Changed:
    - Improved LOD fading + workaround for URP bug where cast shadows flicker during the transition
    - Color map rendering now supports terrains with varying height positions
    - Trail grass benders now have their position slightly jittered, so their lifetime always updates even when stationary

    Fixed:
    - Material UI now showing the correct current wind strength, when a Wind Zone is used.
     
  11. Animmal

    Animmal

    Joined:
    Oct 8, 2017
    Posts:
    39
    Hello, great looking pack.
    Does it works with Standard render pipeline? old one, not URP or SRP
     
  12. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,303
    It's built on the Universal Render Pipeline's shader library and rendering API, so exclusively works in URP-based projects.
     
  13. KostiaLiakhov

    KostiaLiakhov

    Joined:
    Mar 13, 2021
    Posts:
    13
    Hi! Using your beautiful shader with Nature Renderer and getting a strange effect when Procedural Instancing is enabled - I can see Ambient Occlusion through the grass for some reason. Not sure what causes it - shader, Nature Renderer or something else, but I thought i'd ask if you have any idea? :)
     

    Attached Files:

    • AO.jpg
      AO.jpg
      File size:
      285.7 KB
      Views:
      323
  14. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,303
    There seems to be a potential bug with the system that activates the third party integrations. In the StylizedGrassShader.shader file, all the way the the bottom, these two lines should be uncommented
    upload_2021-5-13_9-13-45.png

    The first time around, these weren't for me, even they're uncommented everywhere else. Any subsequent tries, everything worked correctly. So you may have run into the same fluke!
     
  15. KostiaLiakhov

    KostiaLiakhov

    Joined:
    Mar 13, 2021
    Posts:
    13
    It was commented indeed! Thank you for the fix, love your work guys! :)
     
  16. Loupyboy

    Loupyboy

    Joined:
    Dec 23, 2015
    Posts:
    6
    Hi! Very good looking asset!
    I was wondering, would you be interested in sponsoring a game jam? Namely the Community Bolt Jam?
     
  17. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,303
    Feel free to shoot me an email ;) https://staggart.xyz/support/contact/
     
  18. JAMiller

    JAMiller

    Joined:
    Apr 2, 2009
    Posts:
    78
    Hello, I'm having an issue with the bending in my scene. For some reason it appears to draw the benders as a faint shadow to the screen, on top of the meshes using GrassSingle meshes.

    For example with a trail, it looks like this:


    (The one on left is the trail directly from the BendingDemo scene).

    The actual bending does apply (hard to see in the screenshot), but the overlay makes it look strange.

    Happens whether I disable all post processing, use BendParticleTrail, etc. Everything I can find about the scenes is the same (even using the same SRP renderers)...

    One thing I notice that is different is in my scene the bending map renders Green, where the demo scene its pink/purple.



    Could this be why its rendering as a shadow on the main camera?

    Any idea why this might happen?

    Unity 2020.3.12, URP 10.5, NatureRenderer
     
    Last edited: Jun 28, 2021
  19. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,303
    What you're seeing is the bending tint that gets applied. By default it's set to a light gray, which gets multiplied over the grass color. If you set it to full white, it won't be visible at all
    upload_2021-6-28_9-23-26.png

    The green color in the vector map represents the Y-position of the trail, so its perfectly normal to see different colors there between different scenes ;)
     
  20. JAMiller

    JAMiller

    Joined:
    Apr 2, 2009
    Posts:
    78
    Ah, thanks for the fast response. You solved it for me! I *thought* I had it as white already, but now I rechecked all my detail meshes and found some were using one of the demo materials, not the material I thought I was using. Also softened up my trail and it blends much better with a light tint. Looks great now, thanks!
     
    Last edited: Jun 28, 2021
  21. sentenello

    sentenello

    Joined:
    Feb 14, 2021
    Posts:
    1
    Hello there.
    Yesterday i realised my grass is floating above ground. When my ground ia flat i have no problems, grass perfectly on the ground, but when ground is slope, half of the grass is above terrain and half is under. When i look closer the problem is obvious. Grass is not rotating to match the ground angle. Any idea how to fix it?
     
  22. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,303
    This really depends on what you're using to place the grass. The "GrassPatch" prefab is the biggest mesh, so works well for relatively flat surfaces. On slopes or edges, you could use the "GrassSingle" prefab, which isn't as large
     
  23. AvatarMars

    AvatarMars

    Joined:
    Dec 31, 2018
    Posts:
    3
    Does this asset have support for removing/adding grass during runtime? I'd like to include scything down grass in my game.
     
  24. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,303
    Not specifically, adding or removing grass instances would be something handled by the same system that renders the grass, a shader has no control over this.

    You could exaggerate the bending so it looks like grass is being cut, see this post
     
  25. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,303
    Version v1.1.7 is now available

    This mainly does some housekeeping and usability improvements. With the coming of URP v12 in Unity 2021.2 the shader needed rigorous reworking. Finding a workable middleground between URP 7 through 12 was quite an undertaking, but it now also works in the beta version (no longer in the alpha versions). Good chance it'll break again when 2021.2 actually releases, but I'll verify this when the time comes.

    Support for 2019 LTS is ending in the spring of 2022, and as much as I'd like to support the widest range of versions, I'll be bumping up the minimum supported version to 2020.3 LTS a bit earlier. This will drastically cut down on complexity and maintenance, especially since URP's shader code tends to diverge with every release. For now, I've bumped up the minimum version to 2019.4.0 (URP 7.4.1)

    Added:
    - Flatten normals parameter added. Lighting will treat the mesh as if its normals are pointing straight up.
    - Build preprocessor script which strips shader variants for features only available in newer URP versions, improves build times
    - Specular highlights toggle and smoothness parameter
    - Support for Rendering Debugger and Decals in 2021.2.0b1

    Changed:
    - Bending renderer can now follow the current camera rendering, so is no longer limited to a single area
    - Bending renderer, Mask Edges option is no longer needed, functionality now is incorporated into the shader, which is ultimately faster.
    - Normals of grass meshes are now hard-shaded. This is required for the depth-normals pass in URP10+ and greatly improves the SSAO behaviour.
    - Added option to disable jittering for trail benders (Force updating)

    Fixed:
    - Shader errors in Unity 2021.2b1 (alpha version is now obsolete, and will break instead).

    Removed:
    - Shadow bias correction option, unfortunately required to make room for newer URP features and reduce shader variants

    ------

    I've tested everything as best as I could, various Unity versions and set ups. Should anything explode, please let me know so I take a look at it! :)
     
    Last edited: Jul 26, 2021
  26. bearcoree

    bearcoree

    Joined:
    Mar 8, 2016
    Posts:
    72
    Heya! Loving the grass so far!

    We did find that the shader displays pink in webgl though.

    Is this expected behavior / is webgl supported?

    I've also noticed this error message in the browser console:


    We're using Unity 2021.1.15f1 and version 1.1.6 of the grass shader.
     
  27. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,303
    I looked into this recently, and it seems WebGL only works starting from Unity 2020.2. Mysterious, but looking at it now I can see why, due to a simple oversight. I've made a few minor adjustments and can now build for WebGL in 2019.4, though only WebGL 2.0 would be supported. I've just pushed an update with a hotfix for these issues (v1.1.8)
     
    bearcoree likes this.
  28. bearcoree

    bearcoree

    Joined:
    Mar 8, 2016
    Posts:
    72
    Wow!!! I just made a new build with your 1.1.8 hotfix and it totally fixed the issue! Thank you so much for the blazing fast support!! ❤️
     
    Last edited: Jul 29, 2021
    StaggartCreations likes this.
  29. Sir_patrickl

    Sir_patrickl

    Joined:
    Jun 24, 2013
    Posts:
    62
    Hi, I'm looking to buy this asset along with the stylized water 2 shader but I'm also after a matching tree shader to work along with them. I noticed some great looking trees in some of the screen shots for this asset and just wondering if that is the same shader from the fantasy-adventure-environment asset or something else? Are there any plans for a new URP tree shader?
     
    StaggartCreations likes this.
  30. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,303
    I tend to use the tree shaders from the FAE package since I always have them handy and they serve my needs. Though for trees there are other options available such as the Nature Shaders and Vegetation Engine asset.
     
    Sir_patrickl likes this.
  31. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,303
    Version 1.1.9 is now available. Pains me to make so many small and frequent updates, but unfortunately there were some regressions since overhauling a lot of code in 1.1.7. All vital fixes as far as I'm concerned, but totally flew under my radar in my test scenes/projects :oops:

    Fixed:
    - Color map renderer not being able to find the necessary renderer when first set up
    - Grass bending not taking affect at higher elevations
     
  32. GameOracle

    GameOracle

    Joined:
    Mar 3, 2020
    Posts:
    1
    Error.PNG

    Hi,
    Im using unity 2020.2.3 and URP 10.3.2 and ever 2 or so mins i get the above message. Any idea on how to fix it?
     
  33. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,303
    The dialog is prompted when URP isn't installed through the Package Manager. If you're using a GitHub fork, you'd have to add the "URP" scripting define symbol to the Player Settings. Similarly for the (major) version you're using (URP_10_0_OR_NEWER, etc)
     
  34. AvatarMars

    AvatarMars

    Joined:
    Dec 31, 2018
    Posts:
    3
    It seems that perspective correction is not working for me, even when I have it turned all the way up to one it looks the same no matter the camera angle. Is there something else needed to make it work other than setting the value in the material?
     
  35. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,303
    It may not appear to have any effect for an orthographic camera, since the position of the (currently rendering) camera is used. For orthographic camera's, the Z-position becomes somewhat irrelevant. But otherwise you should see it taking full effect when viewing from top-down
     
  36. AvatarMars

    AvatarMars

    Joined:
    Dec 31, 2018
    Posts:
    3
     
  37. Noogy

    Noogy

    Joined:
    May 18, 2014
    Posts:
    133
    Hi @StaggartCreations, I've updated to the latest version of the asset and have noticed that my grass seems to darken under the influence of a grassbender. Is this expected behavior and can it be changed/removed?

    It almost seems like the grass is 'bruising' which would be a neat touch but more than I need, thanks.

    Also, and I know this is probably a big ask, but would it be possible to have the option to fade foliage out as it approaches the camera (in addition to the current distance fade)? I'm rebuliding my vegetation system and would love to have certain LODs only visible near the horizon, so the ability to fade it out as it gets closer or further from a set point would be fantastic.
     
  38. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,303
    Under the Color tab there is a "Bending tint" parameter. By default this is set to a light gray, setting it to a pure white would make the effect invisible entirely.

    That's certainly possible. I'd think it more targets the case where the camera is right up in front of the grass, and it needs to fade out in order to not be an obstruction. But the distances can be configurable either way. Using an empty LOD0 would be more efficient though, since grass that's being made invisible through the shader is in fact still being rendered.
     
    Noogy likes this.
  39. Noogy

    Noogy

    Joined:
    May 18, 2014
    Posts:
    133
    @StaggartCreations, ah perfect, bending tint. Can't believe I missed such an obviously named option.

    Regarding the fading, I guess I should be more specific, and perhaps I'm approaching this wrong anyway. So I'm building up my own vegetation placement system for my needs. I quite like how Breath of the Wild will use larger low-poly brush-like patches of grass as the camera gets further away. These actually sink into the ground as you approach, making way for the single blades of grass to start popping in. It's very effective at keeping the illusion of large tufts of grass. You can actually sometimes see these tufts up close if you position the camera directly above.

    So I guess there's actually no 'proximity fading' going on there. I had hoped I might mimic the effect using fading and my cell-based vegetation placement so I'm not rendering more than I need.

    Edit: BTW, don't worry about the opacity stuff, the shader is fantastic as is, and I really wouldn't want anything to impact performance.
     
    Last edited: Sep 1, 2021
  40. MHS-JProgrammer

    MHS-JProgrammer

    Joined:
    Sep 1, 2019
    Posts:
    6
    Hello, I'm having an error after update Vegetation Studio Pro and your Stylized Grass shader. Now your script "StylizedGrassShaderController" says that some namespaces are missing. I never had this issue.

    Do you have any idea of what could cause it?
    Now i'm looking into the assembly definition assets. But I don't know how they work exactly.
     

    Attached Files:

  41. Noogy

    Noogy

    Joined:
    May 18, 2014
    Posts:
    133
    Hello @StaggartCreations, I've finished building my own vegetation spawning/rendering system, however I'd like to migrate from DrawMeshInstanced to DrawMeshInstancedIndirect.

    I'm comfortable with the former system but not terribly familiar with the latter. Specifically, I'm not sure where to pass the ComputeBuffer to the shader via SetBuffer(string, ComputeBuffer). Do I need to set something up within the shader to allow for instancedIndirect? I used to use Veg Studio Pro and know it supported it, and am unsure if I'm missing something, thanks.
     
  42. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,303
    This has been happening to several people before, when upgrading to VSP 1.4+, see: https://discord.com/channels/374537133584678913/808400646402867220/838986498904686592

    Can't say I'm very familiar with the implementation, but you can replicate the set up used in the grass shader for third-party renders like VSP.

    For VSP, the "setup" function is used to bind several matrices to custom buffers. Swapping out every occurrence of these lines (one per pass) with your own should be the only required modification.
    upload_2021-9-12_13-36-45.png

    On account of the "fading", I've added a toggle to invert the start/end distances. Though it'll still perform alpha clipping, rather than sinking the mesh into the floor. This is technically possible, but involves some breaking changes resulting in some material settings reverting to their defaults. Though, visually the difference between the two techniques seems to be negligible.
     
    Noogy likes this.
  43. MHS-JProgrammer

    MHS-JProgrammer

    Joined:
    Sep 1, 2019
    Posts:
    6
  44. Noogy

    Noogy

    Joined:
    May 18, 2014
    Posts:
    133
    Hi @StaggartCreations, I'm working on wind and wanted to double check. You wrote this some time ago:

    The wind strength can be controlled by assigning a wind zone to the Stylized Grass Rendering component. This'll multiply the ambient/gust wind strength value of the material by the wind zone's "main" value. Speed and direction can't be changed, since this would cause the grass to jitter, until the values are fixed.

    It seems that windspeed and direction still can't be changed without jittering. I'm working around this by temporarily decreasing ambient strength and the gust settings so that the direction change isn't noticed. I just wanted to double check that there's no other way to change windspeed and direction without the jitter, correct?
     
  45. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,303
    This is actually from the VS discord, but it says this:
    upload_2021-9-14_9-54-20.png

    Yes this would still be the case, it's mainly a limitation of the trigonometry used. Afaik the only way to change wind speed/frequency smoothly over time is to calculate the wind twice in the shader with two sets of settings, then blend/lerp between the two results.

    Other techniques delve more into a unified wind system, which would actually be more beneficial for Unity to build into the engine, since it could be used for anything by anyone.
     
    Noogy likes this.
  46. daedal

    daedal

    Joined:
    Dec 19, 2013
    Posts:
    31
    Hey @StaggartCreations, is it possible to temporarily modify the grass shader parameters on the grass in a specific location without using GameObjects? Would any of the supported third party plugins help with this?

    Specifically, I'd like to have the grass respond to environmental effects such as burning, wetness, freezing, etc.. I don't need anything too fancy. Just changing the color and reflectivity would go a long way.

    Thanks!
     
  47. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,303
    MaterialPropertyBlocks is likely the best way to achieve this. It'll allow you to override material settings for individual Mesh Renderers, without actually changing the material or modifying it.

    Though when not using GameObjects such as with Vegetation Studio or Nature Renderer it gets more complicated, since you need a way of finding specific instances and modify them, which tends to be specific functionality that needs to be incorperated into these systems.
     
  48. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,303
    Version 1.2.0 is now available, changelog:

    Added:
    - Translucency
    * Offset parameter. Controls how much the effect wraps around the mesh
    * Falloff parameter. Controls the size of the effect (previously hardcoded to a value of 4, which is now default)
    * Indirect strength parameter. Shading can now also be performed for light hitting the front of the grass.
    - Parameters to control normals are now available in VSP (requires the prefab to be refreshed)
    - Option to invert the fading distance

    Changed:
    - When activating the Nature Renderer or GPU Instancer integration. Filepaths in the shader are now automatically rewritten based on their current install location
    - Grass bending now fades out at a constant 2 units towards the edge of the render area, no matter its size.

    Fixed:
    - Translucency shading being wrongly affected by the grass color as it appears after lighting
    - External material changes (eg. source control) not being reflected in the material UI
     
  49. Noogy

    Noogy

    Joined:
    May 18, 2014
    Posts:
    133
    Sweet, looking forward to trying the latest. I had a question about wind, I'm having a little trouble differentiating the wind effects on the X and Z axes. I'm getting the right gusting effect, I can see it move in the right direction, but the vertex displacement doesn't seem to be working right. The effect is that my foliage all seems to deform back and forth on a single axis regardless of the wind direction.
     
    natbug likes this.
  50. Syharka

    Syharka

    Joined:
    Jul 12, 2017
    Posts:
    2
    Run into a few bugs, updating to the latest version doesn't seem to have solved, so posting here for reference.
    1. When using multiple terrains with non-standard shading only one of the terrains is drawn to the colourmap renderer. When switching non-standard off, all the terrains are drawn to the colourmap correctly but have visible banding.
    2. When using Microsplat with non-nonstandard terrain shading, the colourmap option appears far darker leading to the grass not matching the terrain colour

    Screencap contains both these bugs for reference: upload_2021-10-15_11-28-7.png