Search Unity

Stylized Grass Shader [URP] ☘️

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

  1. Noogy

    Noogy

    Joined:
    May 18, 2014
    Posts:
    132
    Sorry for this weird layout but I figured I'd leave it up for anyone who runs into these two issues. I was able to solve the first part when I realized that I needed to manually material.SetVector(v4) within GrassBender.cs/Update;

    The original problem is as follows:

    The second issue was regarding sorting. Again, I hadn't realized that I needed to manually GrassBender.cs/UpdateProperties() for my script to modify sorting layers.

    Those issue figured out, I have to say I'm loving this new update, the near/far fading is fantastic and I'm looking forward to the improved performance.
     
    Last edited: Oct 26, 2022
  2. ScorpioGamer

    ScorpioGamer

    Joined:
    Oct 14, 2012
    Posts:
    9
    Apologies for the late reply, we got it fixed by changing the directional mode in the lightmapping setting.
     
  3. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    That's puzzling. The sphere can turn out pink if the shader failed to compile (this would prevent you from building). Or the material is missing, this may happen if the Grass Bender component looses the "Renderer" reference. In which case, the script ducks out and never gets to create a material instance. But this is also unlikely, since the component lives on the same GameObject.

    May be worthwhile to add this at the end of the SetupMaterial() function in the GrassBender script, as a sanity check:
    Code (CSharp):
    1. #if DEVELOPMENT_BUILD
    2. Debug.LogFormat("[GrassBender {0}] Renderer:{1} - Material:{2} - Shader:{3}", GetInstanceID(), renderer, material ? "True" : "False", material ? material.shader.name : "None");
    3. #endif
    I'm not familiar with Addressables unfortunately, so I can't determine what kind of effect that may have.
     
  4. gr3chu

    gr3chu

    Joined:
    May 15, 2019
    Posts:
    5
    Hi,

    Thanks! This was helpful as it showed me null reference exception being logged in runtime :)

    I investigated your code further and finally I've managed to resolve my issue!
    Sadly I did it by adjusting your code a bit.
    Here is more detailed info if you wish to explore my findings:

    So as it turned out you are using Shader.Find method which is not recommended as it is not reliable. Especially considering all possible resource and asset management flows in Unity.

    I'm saying this based on this entry:
    https://docs.unity3d.com/ScriptReference/Shader.Find.html

    To resolve my issue which was associated with bend shader not being included in the final build, I had to remove editor script wrapper for bender component and expose sphere bender so that I can reference the shader directly (solution 1 from the link above):
    spahre bender issue - removing editor for bender component and exposing bending shader.png


    Worth mentioning that I tried solution 2 from the URL but I started to got build errors around usage of HideFlags in your script flags: https://docs.unity3d.com/ScriptReference/HideFlags.html

    spahre bender issue - dont save flag.png


    Finally to ensure that property based references is utilized by other part of logic I switched static helpers into normal methods so that Shader.Find can be removed from them as well:

    spahre bender issue - removing Shader Find.png

    I also left hideFlags commented out as this doesn't seems to change anything for me in this case.


    Anyway now everything WORKS and I'm really happy!! :D

    Thanks for your support and thanks for this great asset!
     
  5. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    Thanks for sharing! This means the spheres must have ended up pink because the materials didn't have a shader. The shader is normally references on the Grass Bender component, to ensure it is included in a build. But I suppose if you are instantiating the prefab itself, that wouldn't happen.

    Glad to hear you've got it sorted out! :)
     
  6. ratking

    ratking

    Joined:
    Feb 24, 2010
    Posts:
    350
    Heya, I really love how the grass looks with this shader - unfortunately I got a problem that is actually mentioned and marked as "fixed" in the Troubleshooting section, but I'm using Unity 2021.3.12f1 and I get flickering shadows with my terrains. It only appears when I don't have the Scene view active at the same time as the Game view, and when Distance Fading in the grass shader is active (and only when I move the camera). Any ideas how to solve this?

    EDIT: After some more tests I noticed that the flickering also stops when I remove all trees from my terrains. o_O
     
    Last edited: Nov 11, 2022
  7. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    This type of behaviour was attributed to a bug in URP, where the camera's position wasn't correctly sent to shaderland. Specifically when the terrain's vegetation system was being used (even if its not for grass). I can't find the exact bug report, but this should have been fixed already. 2021.3 saw some changes in the vegetation system, so perhaps the same bug was unintentionally introduced back in.
     
  8. Hermetes

    Hermetes

    Joined:
    Jan 6, 2016
    Posts:
    12
    Hello after first install :

    Assets\Stylized Grass Shader\Runtime\GrassBender.cs(107,17): error CS0103: The name 'GrassBendingFeature' does not exist in the current context

    Unity Version : 2020.1.0f.1
     
  9. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    Do you have the Universal Render Pipeline package installed? Without this, these sort of errors can pop up.

    Worth noting that Unity 2020.1 would not be supported either way, a minimum of 2020.3 is required.
     
  10. Hermetes

    Hermetes

    Joined:
    Jan 6, 2016
    Posts:
    12
    Thanks for your answer. I will update it soon.
     
  11. Setmaster

    Setmaster

    Joined:
    Sep 2, 2013
    Posts:
    239
    Is this compatible with the Vegetation Engine? Mostly interested if I could make it work with VE's wind.
     
  12. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    I believe Vegetation Engine is a full vegetation shader suite, so it would replace this grass shader. There's a video they made I just noticed outlining the details:
     
    Setmaster likes this.
  13. DigitalAdam

    DigitalAdam

    Joined:
    Jul 18, 2007
    Posts:
    1,209
    @StaggartCreations
    Hey, I just picked up your Stylized Water 2 as well as the underwater effect. Is there a way to have the underwater effect only appear within the size of the water prefab?

    The problem I have is if the water is placed higher on the terrain, say in a mountain area (protruding rocks in my screenshot), the underwater effect shows everwhere below that. So the path leading up to the water pool is underwater until the player gets above the pool, in which it renders correctly. Thanks.

    Underwater-Problem.jpg
     
  14. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    Please see this post, I believe that delves into the exact same situation!
     
  15. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    Version 1.3.2 is now available!

    Added:
    - Support for Unity 2022.2
    - Support for the Forward+ rendering path
    - Support for dynamic wind directions from a Wind Zone component
    - Wind: Gusting speed material parameter
    - "_Seed" parameter for use with the Hybrid Renderer in DOTS (0.5.0 and 1.0.0+)

    Fixed:
    - Min/max material parameters not displaying override options on material variants
    - Grass bending pass no longer executes for overlay cameras.
     
    Salja likes this.
  16. Salja

    Salja

    Joined:
    Mar 23, 2017
    Posts:
    353
    that's really nice thanks for that =)

    I would really like to see you burn/cut the grass like in Zelda BOTW did you ever plan to do that?
     
  17. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    Thanks goes to @deshowiz for proposing a viable technique :)

    Cutting can basically be achieved by exaggerating the grass bending. To the point where the grass gets pushed below the terrain, and seems to disappear. The Height Offset and Flatten Strength (>1) parameters will can have this effect when ramped up. Paired with a particle effect that sprays some grass blades I bet it looks convincing enough :)

    I feel for burning, its much easier to achieve this by using Decals, since is a native feature so will affect any and all shaders, and is very flexible with Shader Graph at its back.
     
    deshowiz likes this.
  18. moorelika

    moorelika

    Joined:
    Nov 16, 2021
    Posts:
    2

    Thank you very much!

    However, grass doesn't receive any shadows in Unity 2022.2.2f1, URP 14.0.4. is there any additional configuration I need to do to make it working?
     
  19. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    Ah, good catch! Quite unintentional, but appears to be specific to 2022.2+. It actually occurs when shadow cascades are disabled in a build.

    A workaround is to always enable them, by having a value of >1:
    upload_2023-1-13_14-46-7.png

    In the StylizedGrassShader.shader file at line 175, you can change:
    Code (CSharp):
    1. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
    2. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
    to (all on one line):
    Code (CSharp):
    1. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
    This will actually break the use of no shadow cascades in Unity 2020.3, but works fine is any newer version. A necessary sacrifice it seems, but I'll have to see if I can find a way around this!
     
    moorelika likes this.
  20. moorelika

    moorelika

    Joined:
    Nov 16, 2021
    Posts:
    2
    Wow! That resolves all my issues!
    Thank you for the insight and all your help
     
    StaggartCreations likes this.
  21. deshowiz

    deshowiz

    Joined:
    Mar 28, 2015
    Posts:
    22
    @StaggartCreations

    Hey Staggart! I was wondering what colorspace you demo all of your scenes with? I seem to have been defaulting to linear this whole time but I realize an environment artist on my team has been working in gamma colorspace when creating assets, so we keep having to go back and iterate for color correction. I was wondering if you knew a way to fix this issue while possibly keeping linear colorspace? Or if you use gamma for your demos, if switching to gamma for a stylized project is preferable.

    Thanks :)
     
  22. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    All the content is indeed authored based on the linear color space. As of Unity 2019 that is now the default, so has the best chance of things looking exactly like in the screenshots.

    I personally do like the visual character of Gamma-color space, but it's not the correct way to work with Tonemapping+HDR. I find (at least) doubling light intensity and using ACES tonemapping yields a similar aesthetic.
     
    deshowiz likes this.
  23. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    Version 1.3.3 is now available

    Added:
    - Integration for Nature Renderer 2021

    Changed:
    - Vegetation Studio Pro integration is no longer default, as to not interfere with the Hybrid Renderer.

    Fixed:
    - Preemptive shader error fix for Unity 2023.1.0a26+
    - Shader warning thrown in 2021.2+ related to using the Graphics Debugger
    - Materials not receiving shadows, or showing banding artefacts, when a single shadow cascade is used. (In Unity 2021.3.15+, or versions released after December 15th 2022)
     
    Salja likes this.
  24. Salja

    Salja

    Joined:
    Mar 23, 2017
    Posts:
    353
    i get a error sice the last update Unity 2021.3.11f1 URP 12.1.7


    Screenshot_1.png
     
  25. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    It seems like something went wrong during the submission process. The version on the store isn't exactly the version as intended. A hotfix will be available shortly!
     
    Salja likes this.
  26. Datlis

    Datlis

    Joined:
    Aug 11, 2021
    Posts:
    2
    upload_2023-2-1_14-23-38.png upload_2023-2-1_14-25-55.png

    Hi, so i've been testing out the grass (which is amazing btw) but i've not managed to be able to get it blending seamlessly similar to one of your examples, any recommendations? Also the grass seems to have this shadow below it and no matter what setting I change it doesn't dissapear.
    Thanks.
     
  27. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    I'd say that's blending fairly nicely! If you're looking to achieve blending in a way that the grass appears almost invisible, that would only be possible by forgoing any sort of lighting in the scene. The soft shadows you're seeing are likely coming from an ambient occlusion post-processing effect that's active.

    You can see here as well that's makes a difference:
    upload_2023-2-2_12-23-32.png
     
  28. mr_president

    mr_president

    Joined:
    Jun 28, 2015
    Posts:
    23
    I upgraded to 1.3.3 today from 1.3.1, and I have a strange issue with the new wind direction feature: The scrolling gust texture always indefinitely accelerates in speed. Even when I set the ambient and gusting speeds to 1 (since it's a multiplier according to the docs, nothing should happen doing x1?) the texture movement starts out completely static, then over several minutes turns into a windstorm. This even happens in the scene view without playmode if I let it sit long enough. The only way to stop it is to set gusting speed to 0.

    Unity 2020.3, URP 10.9, also using Vegetation Studio Pro to render although changing the wind settings in VSP seems to have no effect.
     
  29. deshowiz

    deshowiz

    Joined:
    Mar 28, 2015
    Posts:
    22

    I actually wrote a fix to this @mr_president @StaggartCreations can check the recent private conversation for a solution. Assuming my fix doesn't break anything else. But my tests haven't shown any issues.
     
  30. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    A known issue unfortunately, but is on the shortlist for being addressed. Hopefully this week if time permits!
     
  31. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    Version 1.3.4 is now available!

    Added:
    - Colormap Renderer, texture detail parameter. Allows to filter out high frequency details.
    - Stylized Grass Renderer component, wind zone Main and Turbulence multipliers. Allows wind to be normalized to match potentially other wind-enabled shaders using the same Wind Zone.

    Changed:
    - Colormap Renderer, will now restore the terrain's original vegetation drawing setting after rendering (Nature Renderer use case).
    - Colormap Renderer, will no longer enable Directional Lights that were intended to remain disabled (eg. lighting system with a disabled moon during daytime).
    - Colormap Renderer, now creates a temporary empty renderer through script, to prevent any third-party post processing effects from interfering

    Fixed:
    - Console warnings about demo scene scripts not being part of an assembly
    - Wind gusting accelerating over time when tied to a Wind Zone

    Deleted:
    - Stylized Grass Shader/Runtime/Renderers folder, now obsolete
     
    deshowiz likes this.
  32. shotoutgames

    shotoutgames

    Joined:
    Dec 29, 2013
    Posts:
    290
    I created three variants with different colors for placement in scene.
    Looks and works great in a regular scene however I have DOTS/ECS Project and when I place the Grass in a subscene all the colors are the same???
    So it doesn't appear to be compatible with subscenes?
    Thanks!
     
  33. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    I can't say I have any hands-on experience with DOTS, outside of Unity's Hybrid Renderer samples project. The shader code follows the layout of Unity's built-in shaders for DOTS 1.0.0-pre5. So may no longer work in 0.5.0.

    Color is curious, because its the one material property that's set up to be controllable through a component.

    You could try commenting out stuff at the bottom of the Stylized Grass Shader/Shaders/Libraries/Input.hlsl file. Which is responsible for remapping material properties, to DOTS-enabled properties.
     
    shotoutgames likes this.
  34. Salja

    Salja

    Joined:
    Mar 23, 2017
    Posts:
    353
    @StaggartCreations I would be really interested to know if they have new assets planned for the future or any major updates, their assets are of really good quality and I'm very excited to see if there's more to come
     
  35. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    Pleased to hear it! I can't say assets are planned as much are they are works in progress, with release potential. In between updates/support for existing assets there's room for R&D, but arguably not much. Some evidentially make it as far as the actual asset store fortunately.

    Currently pet-project is a procedural waterfall geometry tool, hope to publish it this year, followed by a river tool in the same vein.
    upload_2023-2-23_11-29-59.png
     
    Salja likes this.
  36. Salja

    Salja

    Joined:
    Mar 23, 2017
    Posts:
    353
    wow that's really very cool and i'm really happy that maybe more will come from you, waterfalls are a great thing i'm really looking forward to that, just please don't stop your assets are all really well thought out and have a really good quality which you can't say about other assets
     
  37. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,980
    Anyone got tips on how to spawn grass using nature renderer and mapmagic?

    I can spawn some but it's so sparse, trying to spawn thick grass like when using the grass node
     
  38. skelpd24

    skelpd24

    Joined:
    Aug 17, 2020
    Posts:
    2
    Hello, I have a question about the functionality of this asset, so I'm leaving a comment like this. Can I erase or redeploy a grass installed at runtime on this asset? And can I make the grass transparent through the Color Alpha value of Material?
     
  39. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    Typically, sparse grass, despite painting at 100% opacity (or procedurally spawning in this case) is attributed to a low detail (Unity's name for grass lol) resolution on the terrain.
    upload_2023-3-30_13-17-55.png

    Here the detail resolution equals the terrain width/length. Meaning there's a minimal distance of 1 unit between each grass mesh instance. So the detail resolution should either be equal or double the terrain size.

    It's a terrain setting, so MapMagic is bound to expose these settings somewhere.

    A grass prefab would technically be the same as a prefab containing a cube. So adding/removing a piece of grass would work the same as it would for other type of GameObject.

    The main color's alpha channel would not have any effect, since grass is rendered as opaque (cutout/alpha tested) geometry.
     
  40. skelpd24

    skelpd24

    Joined:
    Aug 17, 2020
    Posts:
    2
    I have one more question. Currently, our project uses a 1024 x 1024 size terrain. After purchasing and testing this asset, we found that when grass was planted in most of the terrain of that size, performance was very low. I was wondering if there was any other way to stably plant grass on a terrain of that size.
     
  41. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    If you haven't seen this already, the documentation includes a page regarding rendering performance here: https://staggart.xyz/unity/stylized-grass-shader/sgs-docs/?section=placing-grass. I'd recommend to give that a glance.

    If you're using the terrain system, it would be a good idea to consult the Frame Debugger and check how many draw calls are being issued for rendering vegetation.
     
  42. wechat_os_Qy07oG6LBuLwxrt0ao4ZkEwPc

    wechat_os_Qy07oG6LBuLwxrt0ao4ZkEwPc

    Joined:
    Jun 28, 2021
    Posts:
    17
    My terrain(mesh) is generated at runtime,How can Blend Color to Grass at runtime? I noticed that there are methods in the editor script that call blending,But hard to use.
     
  43. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    Runtime baking of a color map isn't supported at the moment. This happens to be a particular feature added to an upcoming v1.4.0 update. After which, you're able to assign Terrain/MeshRenderer objects to the component, calculate a rendering area, and call a render function.

    There is still one item in the backlog, but I'm aiming to submit this update to the asset store before the end of the month.
     
  44. deshowiz

    deshowiz

    Joined:
    Mar 28, 2015
    Posts:
    22
    I got the colormap to work during runtime, and then the build. There was an issue to overcome if you were generating the colormap during runtime in the build where if you were taking a snapshot of instanced terrain then the camera wouldn't be able to see it and the resulting colormap would be red. The easiest way to bypass this issue is uncheck "instance terrain" if you come across this problem. It's possible that there may be a need for an extra shader include to get instanced terrains to work with the colormap during runtime in a build, but I haven't tested that yet.
     
  45. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    That's interesting, I ran into the exact same issue. Your findings are spot on.

    What happens is that Unity does not see the Unlit terrain shader being used on any (instanced) terrains, in any scene, during the build process. Thus strips the instancing-enabled shader variant. As a result, any instanced terrain using the shader turns invisible. I've gotten around this by temporarily disabling instancing on terrains, during the rendering stage.

    Puzzling little quirk :p
     
    deshowiz likes this.
  46. Lee1384

    Lee1384

    Joined:
    Jun 8, 2014
    Posts:
    11
    bendshader.png
    The description of version 1.3.0 says Benders can benefit from the SRP Batcher.
    But bender's SRP batcher doesn't seem to work.
    Is there a way to enable the grass bend shader's SRP batcher?
     
  47. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    Ah, indeed! That's definitely an oversight. The fix is fortunately easy to make.

    In the Stylized Grass Shader/Shaders/Bending/Common.hlsl file, replace every occurrence of the word "Props" with "
    UnityPerMaterial".

    upload_2023-4-14_9-49-41.png

    Both GPU Instancing and SRP Batcher will work afterwards. I'll be sure to include this fix in the upcoming update.
     
    Lee1384 likes this.
  48. VolvoMan

    VolvoMan

    Joined:
    Dec 17, 2022
    Posts:
    9
    Hello

    Thanks for this asset. I just bought this asset and have tested a couple diifferent ways to place grass on a terrain or game object. Placing grass using polybrush seems to be somewhat alright for performance. I don't have Vegetation Studio and I'm wondering how valuable it would be to have vegetation studio when it comes to performance. Basically, how much better would my game run if I use Vegetation Studio compared to if i just go the simple route and place grass using something like Polybrush?

    Thanks
     
  49. deshowiz

    deshowiz

    Joined:
    Mar 28, 2015
    Posts:
    22
    I would use GPUInstancer instead of VSPRO. VSPRO's original creator abandoned the asset a while ago. There is some support and development going on in their discord but GPUInstancer is preferable. For my use cases it performs better as well. Both are GPU instancing, which essentially will turn the drawing of many thousands of tufts of grass into a single draw call.

    GPU Instancer also has a demo you can check out. Go to the YouTube videos for GPUInstancer to get a good idea of performance changes. Once you purchase it, there are very helpful demo scenes summarizing different use cases.

    I have used both assets for over a year with about the same setup, and I think using VSPRO when GPUInstancer is available is a mistake.

    I use this grass asset with GPU Instancer and I render a couple hundred thousand terrain detail grass meshes used in this asset at almost no performance cost at all, as opposed to not using an instancing solution. I even render them all at LOD0 from any distance.
     
    VolvoMan likes this.
  50. VolvoMan

    VolvoMan

    Joined:
    Dec 17, 2022
    Posts:
    9
    Hi

    I got the GPUInstancer and it seems to help a bit but I thought I would get more of a performance increase. How do you work with it? I use the GPUInstancer Prefab Manager for my grass prefab that I have painted onto the world with Polybrush. The game world is very simple right now, basically just lots of grass on a plane game object. Yet, the fps is only at about 200 FPS using GPUInstancer. If the game would get a bit more advanced, I'm sure there would be some issues running the game well. I've been playing around with the culling, etc., but it's not that successful. I have frustum culling enabled, too.