Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Stylized Grass Shader [URP] ☘️

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

  1. TragicallyCanadian

    TragicallyCanadian

    Joined:
    Mar 26, 2020
    Posts:
    9
    Hey there, my grass is not blowing/moving at all. Any idea what could be causing this?

    EDIT: Never mind! Fixed, it had an incorrect shader assigned after I updated my project.
     
    Last edited: Nov 26, 2021
  2. natbug

    natbug

    Joined:
    Jun 18, 2016
    Posts:
    1
    I've got the same issue, any ideas?
     
  3. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,009
    I've just checked it out, and this does in fact not appear to be working correctly. The gusts are moving in the defined direction, however the grass is pushed in the opposite direction. I'll be sure to correct this for next update!
     
    Noogy likes this.
  4. JordanCarter97

    JordanCarter97

    Joined:
    Aug 15, 2018
    Posts:
    13
    Hi there, I recently purchased Stylized grass shader and shortly after was suffering with massive Unity issues including maxed out memory even in an empty scene, regular freezing, and compile times that would take upwards of 5 minutes. After much trial and error I have isolated the problem to styleized grass as removing this asset returned the project to normal and then re adding the asset instantly spiked my memory usage back to 97 percent without even loading anything. For context I had been using this asset to place large amounts of grass using the Polaris terrain tools, not sure if this could affect it in anyway however as I stated above the issues present with this asset installed occur even when my scene with the placed grass is not open. I would really like to use this asset however currently I am unable too due to these issue, if you are able to shed any light on this situation that would be amazing.
    PC Specs
    GTX 3070
    Ryzen 5700g
    16GB of ram
    Windows 11

    Unity version
    2020.3.23f1 LTS
     
  5. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,009
    Already replied to your email ;)
     
  6. Krooq

    Krooq

    Joined:
    Jan 30, 2013
    Posts:
    175
    @StaggartCreations, I do really love your creations. Every single one is on point.

    I do have one bit of feedback, because I really can't get enough of your stuff.
    I really really really want some procedural way to do the color/terrain blending.
    Without it I am either limited to prebaked terrains or non-blended grass both of which are sad times.

    One other thing, I'm using GPUI, MapMagic2, MicroSplat in my pipeline and I just love that your stuff just works with these tools.
    Thanks a bunch for your amazing assets!
     
  7. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,009
    Thank you so much!

    I've been toying with the idea of realtime terrain color blending, which is definitely possible. It has many parallels with terrain blending for objects, which I started prototyping a while ago.

    The difficulty is, that terrains (unlike Mesh Renderers) cannot be rendered manually through Unity's graphics API. Which is a step required to render them from a top-down perspective into a texture. How this works exactly is neatly tucked away in the engine's source code. A poor man's solution is to simply use a 2nd camera, but this has way too much performance overhead compared to the alternative.

    I've nailed part of it, but have yet to figure out how to reconstruct the terrain's multi-pass shading for color, which is the corner stone of such a technique. Afterwards balancing resolution and render distance will be another challenge, solvable with cascaded rendering, but that's yet another tangent into its own little project :p

    So hopefully in the future as my codebase matures further!
     
    Krooq likes this.
  8. Devsagi

    Devsagi

    Joined:
    Sep 28, 2019
    Posts:
    33
    Hello, really liking this asset (for almost a year now)!

    I updated recently and it seems like in the new version emissive grass is not working.
    Last time it got mentioned in the patch notes:
    Or did it change how it's used now?

    I created a new project, here are my settings:

    glowgrass.png

    As you can see on the cube on the right, HDR is enabled in the pipeline settings and camera.
     
  9. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,009
    Glad it is to your liking!

    I clamped the color to LDR some time ago, since this could cause sparkle-like artifacts. This inadvertently also kills off emission. Makes sense now that you bring up, but totally flew under my radar.

    I'll have to add a separate color parameter for emission, much like URP's Lit shader. I'll add this to my backlog for next update.
     
    Devsagi likes this.
  10. Devsagi

    Devsagi

    Joined:
    Sep 28, 2019
    Posts:
    33
    Thank you for your fast response, looking forward to the fix!

    Would it be difficult to also add another texture (black/white) to decide which parts of the grass / flowers are emissive? Maybe this would be a nice feature for the future.
     
  11. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,009
    Wouldn't be difficult to add, though it's something that needs the option to be disabled, so it doesn't add any performance overhead if not in use.

    The shader currently already uses a lot of shader keywords, and more keep getting added every URP version (which can affect build time by hours). Hence I'm very careful with adding more, such as one for an emission map. I can likely just use the vertex colors to mask out the emission color (otherwise the root of the grass also starts to glow, and stick out from the terrain).
     
    Noogy likes this.
  12. slages

    slages

    Joined:
    May 16, 2017
    Posts:
    9
    Hi! First I want to say that I love the asset, it looks great!

    I'm trying to use it on a DOTS based game, and I'm having errors with the Hybrid Renderer V2.
    First issue was version compatibility, I had to update all #pragma target 3.5 to 4.5.
    But now I'm having these errors:

    Shader error in 'Universal Render Pipeline/Nature/Stylized Grass': 'LoadDOTSInstancedData_float4': no matching 1 parameter function at Shader/Shaders/LightingPass.hlsl(75) (on d3d11)
    Shader error in 'Universal Render Pipeline/Nature/Stylized Grass': undeclared identifier 'unity_DOTSInstancingF16_Metadata__BaseColor' at Shader/Shaders/LightingPass.hlsl(75) (on d3d11)
    A Hybrid Renderer V2 batch is using the shader "Universal Render Pipeline/Nature/Stylized Grass", but the shader is either not compatible with Hybrid Renderer V2, is missing the DOTS_INSTANCING_ON variant, or there is a problem with the DOTS_INSTANCING_ON variant.


    Any idea on how to fix it? Thanks!
    (Unity version is 21.2.7 and URP 12.1.2, Hybrid Renderer 0.11.0-preview.44)
     
  13. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,009
    I can't say I've dabbled with the HR too much, aside from testing compatibility in Unity's sample project. After adding the necessary changes to the shader it appeared to work there.

    Based on the error, it's tripping on accessing the _BaseColor property. Which happens to be a property I've set up for DOTS Instancing. Removing this from the Input.hlsl may do the trick:
    upload_2021-12-30_11-7-38.png

    This part is only important when looking to change the grass color on an individual basis using entities.
     
  14. slages

    slages

    Joined:
    May 16, 2017
    Posts:
    9
    Thanks a lot, it's working! I've just lost the Hue Variation feature, I'll try to investigate further to try to get it back but for now it's all good.
     
  15. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,009
    That's a little unexpected, but not entirely. The hue variation is based on each instance's unique localToWorld matrix. I assume this (or a random 0-1 value) would need to be passed to each entity when using the HR to replace this. Not knowing how the HR works under the hood exactly, that's a bit speculative though. Warrants some future investigation...
     
  16. slages

    slages

    Joined:
    May 16, 2017
    Posts:
    9
    Probably best to wait for the DOTS 0.5 release before digging too much into it, as things will probably change by then, I just hope that it won't break everything... :)
     
    StaggartCreations likes this.
  17. unity_dev3194

    unity_dev3194

    Joined:
    Apr 17, 2017
    Posts:
    74
    Getting some crazy build times in URP due to shader variant compilation. Mostly isolated to the Stylized Grass Shader. How can I go about improving this? Is there an easy method to disable keywords or shader features that aren't being utilized?
     
    Last edited: Dec 31, 2021
  18. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,009
    The number of shader variants in URP can increase quite drastically when using different pipeline assets per quality level. For example, shadows on/off, SSAO on/off, lightmaps, etc. Every URP release tends to release more optional features, increasing the amount of shader variants exponentially.

    I've ensured that these get stripped during the build process on older URP version (eg. URP 12 features/passes get stripped in URP 11). I really don't know how Unity is going to prevent this issue from growing worse (runtime shader compiling?).

    The solution isn't very elegant, but you can simply remove features from the grass shader file you know you're definitely not going to make use of.

    There's this part, which is specific grass features:
    upload_2022-1-2_12-23-36.png

    The rest is URP/Unity features:
    upload_2022-1-2_12-24-24.png
    _CLUSTERED_RENDERING for example is likely one that can go. Not sure if Unity strips this automatically...

    Lightmapping features should already be stripped, based on what you're using. But in Graphics settings you can force certain features to get stripped:
    upload_2022-1-2_12-25-51.png

    Using a fog post-processing effect? You can strip Unity's fog implementation (this adds ^3 variants otherwise)
     
    unity_dev3194 likes this.
  19. unity_dev3194

    unity_dev3194

    Joined:
    Apr 17, 2017
    Posts:
    74
    Fantastic, thank you for the detailed reply! Unity's way of handling URP changes is certainly questionable, but unfortunately I rely on URP for multi-platform performance.
     
  20. HighKeys

    HighKeys

    Joined:
    Jan 6, 2016
    Posts:
    24
    Hi,

    first of all a great shader! Looks so beautiful!

    But i have a small problem, i have a kart in my game added a Mesh Bender and as a child object i added a Tail bender to the wheels etc.

    when i got too much speed I'm faster then the bending, how can i fix that?

    Thanks!
     
  21. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,009
    I believe that's because the tip of a trail is where bending cancels out. This is to avoid sudden jumps, since the tip of a trail is always cut off. You can see this being applied to the gradient of the trail, which happens automatically:
    upload_2022-1-7_15-18-40.png

    That does mean the longer a trail gets, the longer this small black gradient becomes, which may look like delay. I'll make a note to expose an option to disabled this behaviour.

    Next update for the asset is a little backed up, since I'm reworking the grass bending rendering to be more efficient by not making use of a hidden camera. It need to make sure there are no regressions so nothing breaks :p
     
  22. HighKeys

    HighKeys

    Joined:
    Jan 6, 2016
    Posts:
    24
    Oh perfect! Thank you for your fast response.

    I will wait for the update at the moment i can go forward with that :)
     
  23. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,009
    v.1.2.1 was submitted! I decided to push back reworking the grass bending to next update, so I can get these minor changes out first.

    Added:
    - Emission color parameter (HDR)
    - Vegetation Studio Pro LOD debug now also shows on grass

    Fixed:
    - Wind direction not matching up between ambient wind and gusting
     
    Noogy likes this.
  24. Vaupell

    Vaupell

    Joined:
    Dec 2, 2013
    Posts:
    300
    Hi, was just TESTING the asset on Unity 2022.1.0b3.2528 It runs flawlessly, no errors, however also no grass bending ;)

    Just to let you know..
     
    StaggartCreations likes this.
  25. Acrodyn

    Acrodyn

    Joined:
    Oct 5, 2018
    Posts:
    2
    Hello!

    After Curved World activation all foliage becomes transparent. Is this a known issue?


    upload_2022-1-22_22-0-31.png
     
  26. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,009
    This could possibly be because the scene doesn't have a Curved World controller in it. In the Curved World demo scenes everything appears to work correctly. If all fails, right-clicking on the grass shader file and choosing "Re-import" might kick things back into place.
     
    Acrodyn likes this.
  27. Acrodyn

    Acrodyn

    Joined:
    Oct 5, 2018
    Posts:
    2
    Thank you for the response!

    In the end the problem was actually in the Curved World plugin which blocked proper grass shader compiling. Everything works perfectly now. Cheers! :)
     
  28. unity_68E2DE7C7CD47333A564

    unity_68E2DE7C7CD47333A564

    Joined:
    Jul 1, 2021
    Posts:
    5
    Guys any help on how to make my grasses make look more like the ones in the asset store page from this one, like
    any help with some preset settings like colors or translucency, as for the background scenes, i ll import them later from blender but meanwhile how to make this more like fluffy grass feeling


    upload_2022-2-5_0-13-55.png upload_2022-2-5_0-12-56.png
     
  29. unity_68E2DE7C7CD47333A564

    unity_68E2DE7C7CD47333A564

    Joined:
    Jul 1, 2021
    Posts:
    5
    Hey one more thing, about large open world scenes, how do i place those grasses? like should i place them from the unity's terrain as detail objects.. or place them as gameobjects like patches over multiple terrains? which would be more performant? i m using GPU instancer too
     
  30. Noogy

    Noogy

    Joined:
    May 18, 2014
    Posts:
    128
    Definitely avoid placing them as gameobjects. This might be fine for a group of instances here or there, but not for a large field. Graphics.DrawMeshInstanced is your friend here.

    Edit: Sorry, saw you're using an instancer. Not sure how each one works, but I guess you could manually scatter gameobjects in the editor and have the instancer optimize at runtime. However, again, even in the editor you don't want that many gameobjects at once, would be a nightmare (and likely impossible) to manage.
     
  31. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,009
    I'd suggest to carry on and build the rest of the environment, which will bring everything together. The absence of post-processing, AA and terrain materials make up for the biggest difference between the two images.

    What @Noogy outlines is essentially spot on. Pretty much every third-party vegetation renderer is a frontend for Unity's instanced rendering API, this does include GPU Instancer. GameObjects could be possible, but would likely require an aggressive streaming system. If you haven't already, I recommend checking this page in the documentation.
     
  32. XiongmaoHZH

    XiongmaoHZH

    Joined:
    Dec 21, 2021
    Posts:
    7
    Is it possible to use the world position to add a gradient color parameter to the shader, the current color is a bit monotonous, adding a gradient color can make more stylized grass, ambient occlusion can also allow users to customize the color, now only black can be added . I might also need a snow parameter, maybe make some changes to the Color tint.
     
  33. unity_68E2DE7C7CD47333A564

    unity_68E2DE7C7CD47333A564

    Joined:
    Jul 1, 2021
    Posts:
    5
    I want to hand paint the grasses and use the instancer to leverage the performance..
    So should i spawn in the grasses using unity's terrain system and the instanced renderer .. like bloating the hierarchy field with that many gameobject would be a nightmare.. but if i place them as a tree object would that affect the AI or pathfinding in any ways .. i read the documentation but i'm not sure about it like it says the github version wouldn't be affected .. so does that also applies for the A* pathfinding algorithm..(ik this is kinda off topic but i just wan't to be sure like otherwise it would be a hell to again design things from start)
     
  34. unity_68E2DE7C7CD47333A564

    unity_68E2DE7C7CD47333A564

    Joined:
    Jul 1, 2021
    Posts:
    5

    Thanks for the info ... but what should i do about it then.. like those grasses looks so beautiful and i want to hand paint them into the terrain and also render it with a instancer without filling up my editor hierarchy.. any solution for this other than procedural spawning...
     
  35. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,009
    Not presently, but I have been toying with the idea of adding texture-based color variation functionality, which should provide more variation. But as for an individual grass mesh, you can always use a colored texture, instead of a white one. This would allow any and all kinds of colors, as specific as need be.

    I can't say I personally have a lot of experience with the GPU Instancer asset, but I do know it allows taking all the terrain grass/details/trees and replacing their rendering. That would be what you're after. But their documentation likely has more details about this workflow.
     
  36. Shiiv

    Shiiv

    Joined:
    Jul 29, 2020
    Posts:
    9
    Hello,

    I recently tried to replace the "BendSphere" by a "BendTrail", and to my surprise, after some tweeks it really does look amazing ! (I thought it would be too much)

    But I noticed, when the character jumps, there is still a dark trail appearing on the grass (but no movement).
    It is very noticable when playing in fullscreen and its sad...
    I tried to put the trail way higher (like 10 units above, litteraly in the sky), but it still affect the grass color.

    I guess it would be complicated to fix this right away, but is there a possible solution to disable this coloring effect of the trail ? And leave only the movement ?
    I tried to check the shader, hopping to find something obvious, but even if there is, i have like 10 hours of experience in "shader coding", and it seems not to be enough :p

    And by the way, thanks a lot for this asset, i can just focus on coding and still have those incredible visuals, that was so not expected when i started my project :,D
     
  37. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,009
    The color you're seeing comes from the "Bending tint" color parameter on the grass material. If you were to set it to white, it'll be completely hidden. By default it's set to a very faint gray.

    For the height issue, on the Grass Bender component, you can try to disable Alpha Blending:
    upload_2022-2-25_13-40-23.png

    This ensures that multiple bending objects blend nicely together, but it has the downside of interfering with the ability to measure the height distance to the grass. Meaning if it's enabled, a bending object hovering above the grass may still affect it.

    That's not really an issue for things that walk on the terrain, but for a jumping character it's best to disable it.

    I see now the tooltip doesn't mention this, I'll be sure to add more details.
     
  38. Noogy

    Noogy

    Joined:
    May 18, 2014
    Posts:
    128
    Hello @StaggartCreations, I just updated to the latest version and am noticing some odd behavior with the shader. On the edges of geometry I'm seeing white pixels. I've attached an image, on the left you can sort of make out the pixels on the edges of the small leafy plants. On the right is the same image rendered at a much lower res, and the pixels really stand out. Any thoughts? Thanks.
     

    Attached Files:

  39. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,009
    That definitely seems unintentional. Do you happen to know from which version you updated? What you're seeing seems to be specular aliasing. There's a couple of things you could check on the grass material to pinpoint the source:

    - Toggling Environment & Specular reflections under the "Shading" tab
    - Temporarily removing the normal map, if present
    - Bringing the smoothness slider down to 0
    - Toggling "Alpha to coverage" under the "Rendering" tab
     
  40. Noogy

    Noogy

    Joined:
    May 18, 2014
    Posts:
    128
    I believe I was using 1.19 based on the folder's changelog. I tried your suggestions and I don't think that's it. I can definitely make it 'appear' worse if I max out specular, but it's actually more of an outline around all the edges of geometry. I've attached another screen, the arrow is pointing to the same leaf from different angles. You can see the white outline go all around the edges. Tried disabling AA and other settings, no go. I wouldn't mind sticking with the older version of the shader but I really need the wind fixes you've added.
     

    Attached Files:

  41. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,009
    Curious, I can't seem to reproduce the same artifacts when trying different settings and meshes. If could send me the mesh and material used, I can try it on my end and see if I can pinpoint the exact cause.
     
  42. makaolachsiungca

    makaolachsiungca

    Joined:
    Sep 27, 2019
    Posts:
    28
    Hi,
    I'm using third part plugin "VegetationStudioPro".
    What should I do to preview the demo asset?

    Unity 2022.1.0b7.2715
    URP 13.1.5
     

    Attached Files:

  43. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,009
    It looks like the shader hasn't entirely compiled, this can happen if it was imported before URP was installed. In which case, you can right-click on the Stylized Grass Shader folder and choose "re-import".

    But there's no guarantee either asset will work in a beta or alpha version of Unity.
     
  44. makaolachsiungca

    makaolachsiungca

    Joined:
    Sep 27, 2019
    Posts:
    28
    Thanks for your reply,
    Assets works fine now.

    -Tribute to your high-quality assets!
     
    StaggartCreations likes this.
  45. bsy50642

    bsy50642

    Joined:
    Aug 9, 2021
    Posts:
    9
    May I know what happens if you use Edge Detection of S.C Post Effect for this Asset?
     
  46. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,009
    The outcome depends largely on the settings used, you can see the difference between available techniques here.

    Here's an example with the Cross Depth Normals method, with the depth sensitivity set 1 and normals sensitivity set to 0.12:
    upload_2022-4-12_12-46-55.png

    But you can generally expect edges to be drawn based on the alpha of the grass texture, not around the actual geometry.
     
    bsy50642 likes this.
  47. rh4unity

    rh4unity

    Joined:
    Feb 22, 2020
    Posts:
    12
    Sorry if this has been asked before... I just skimmed the forum. Anyway, could anyone help me with a tutorial for this:

    I'm attempting to use this stylized grass shader with: Unity 2021; URP; Gaia 2021; The Vegetation Engine; Nature Renderer 2020.

    I'm not sure how to get this grass working with Gaia's biomes. I mean, making your own custom biome... to use the Gaia tool to add grass to the entire terrain. I know that after the grass would be added, that I would need to create a colormap of my terrain to use that part of the Stylized Grass Shader's effect...
     
  48. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,009
    I can't say I know the intricacies of using Gaia, but in the end it uses the terrain's vegetation system. I assume biomes are set up with specific prefabs and spawning rules, so you could simply use any of the prefabs from the Stylized Grass Shader\Prefabs folder.

    Side note, if you using Nature Renderer, you'd have to activate the integration to properly use this shader with its rendering system.
     
    rh4unity likes this.
  49. rh4unity

    rh4unity

    Joined:
    Feb 22, 2020
    Posts:
    12
    Thanks for your reply! Could you make a video of your process? (Or do you have any tutorial videos for this Stylized Grass asset?)

    I don't have to use Gaia, I'm experimenting with MapMagic 2 also... I'm new to both. But they both seem to use the "paint details" tool for grass. Not sure...

    Anyway, I'm basically trying to figure out how to add your Stylized Grass to my scene, in a way that would get decent performance. Instead of just dragging the grass prefabs into the scene. Any advice?
     
  50. Devsagi

    Devsagi

    Joined:
    Sep 28, 2019
    Posts:
    33
    Hello again and thank you for the previous update!

    I updated to Unity 2021.3 LTS recently and found this in your documentation:
    Can you give a pointer on where to actually set this up? It would be nice to use the material from this asset for the default terrain grass. I couldn't find it on the terrain settings, but maybe it's somewhere hidden within the URP settings.