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.
  2. Dismiss Notice

Stylized Grass Shader [URP] ☘️

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

  1. deshowiz

    deshowiz

    Joined:
    Mar 28, 2015
    Posts:
    20
    If you're going to use just a plane object then you should be using a terrain component, since using grass terrain details that are painted onto the terrain is much more performant. So you need to decide what grass prefab you're painting onto the terrain, and then add that prefab to a GPUI detail manager not a GPUI prefab manager. The lack of performance gains you're experiencing is mostly because of the fact that you now have so many objects in the scene. You'll see that as you scale your solution with/without the detail manager enabled that the gains are heavily significant (but you need to watch the video on the detail manager n YouTube like I recommended before).

    This forum is mostly for the grass asset so if you have any other questions about GPUI then I'd look at the demo scenes and documentation more, or DM me instead of posting about it here.
     
    Last edited: May 14, 2023
  2. Balours

    Balours

    Joined:
    Nov 27, 2013
    Posts:
    59
    Hi! I'm rendering a decal on my terrain and I want to avoid the decal to render on other objects likes rocks, bushs ... and the grass. For that I'm using the Rendering Layers setting, so my decal is on a rendering layer call "Receive Decal" and if the an object has this rendering layer activated it will render also the decal. But for the grass it doesn't work, the decal is always rendered even without the Rendering Layer selected. Is there any way to fix that?

    One more random questions, how did you manage to do the backdrop Mountains in the StylizedGrassDemo scene? Mostly the texturing part it works well and it's lightweight.

    Thanks a lot.

    Edit: 2022.2.19 and v1.3.4
     
    Last edited: May 15, 2023
  3. The11thAlchemist

    The11thAlchemist

    Joined:
    Aug 10, 2020
    Posts:
    14
    Hello. VR developer here. I've wasted a bunch of money trying other grass assets and none of them worked well in VR, but your water asset is great and your grass was on sale so I decided to give grass one last try. In general, with a little tweaking it is better than all the other assets that I've tried but I have a couple slight problems: 1) When perspective correction is on, all the grass rotates and yaws with the VR head movements...very similar problem that the shuriken particle system has with texture sheets. Is there a way to lock the grass angle to the camera position? Also would it be possible to have the perspective correction on a slope so that grass that is closer gets corrected but grass farther away doesn't? I really just need the grass underneath the player to be flattened. 2) I'm assuming you are using some sort of dithering for the distance/angle fading, but it extremely obvious and distracting. Any way to make it smoother? Turning off ambient occlusion helped a little, but wondering how to make it less "speckled". Thanks for your time
     
  4. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,102
    Apologies, notifications for this thread seemed to have expired, so I wasn't aware of any messages.

    It's very possible URP's built-in shaders were outfitted with new functionality, it would have to be identified and incorporated into the grass shader as well. I've made a backlog item to investigate this and see if its possible.

    The mountains in the demo scene were modeled and textured in World Creator 2, using the same terrain materials as on the actual (smaller) terrain. The mesh and albedo/normal map are exported from there and set up in Unity.

    I had linked the project file in an earlier post, which is this: https://1drv.ms/u/s!AlkpXXlKu-02xd83dnXOGgrfqZ_9TA?e=gjdtd0 (would have to reassign all textures, since the file paths point to my local harddrive).

    When the grass bending render feature is active, the "Perspective correction" functionality actually uses the camera's forward direction. Otherwise, the direction is based on the camera position.

    In an upcoming update (1.4.0), there's now an option exposed to use either direction. One may look better over the other, depending on the context. I think the position-based direction would be more suited for VR, since it doesn't change when rotating the HMD.

    The dithering looking noisy in inherent to the technique I'm afraid. It is typically used in combination with TAA to achieve the appearance of true transparency, because it smooths out any perceived noise. But TAA is likely not viable for VR (performance-wise).

    In the upcoming v1.4.0 version you can assign a dithering/noise texture to be used for the effect (defaults to a blue noise texture). This already looks better out of the box.
     
    Balours and The11thAlchemist like this.
  5. Introfernal

    Introfernal

    Joined:
    Dec 5, 2017
    Posts:
    9
    NullReferenceException: Object reference not set to an instance of an object
    UnityEngine.Rendering.Universal.DebugHandler..ctor (UnityEngine.Rendering.Universal.ScriptableRendererData scriptableRendererData)

    im getting this error when trying to render the colormap on latest lts

    the scalemap is completely blackl
     
    Last edited: Jun 1, 2023
  6. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,102
    "DebugHandler" hints at URP's debug updater, which is only present in play-mode/runtime. Rendering a colormap at runtime is not supported, in part because the debughandler interferes.
     
  7. TreyH

    TreyH

    Joined:
    Feb 6, 2014
    Posts:
    13
    Is there any additional setup required for the Masking Sphere to work? I'm not able to see any difference with or without it atm sadly -- bending and everything else seems fine though.

    Using Version 1.3.4 with 2021.3.26 LTS, if that helps.

    edit: Also using Nature Renderer 2021

     
    Last edited: Jun 3, 2023
  8. Flxko

    Flxko

    Joined:
    May 24, 2023
    Posts:
    3
    Hi . Love this asset. the grass looks beautiful.

    I'm having one issue however, and was hoping to fix it: when using a terrain 3D object with uneven terrain (hills etc) and placing via paint trees the bottom of the grass won't align with the geometry of the ground? any way I can fix this?
     
  9. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,102
    Ah, yes! This particular feature fades the grass out wherever the sphere is positioned. Though this piggybacks on the "Distance/angle fading" feature, which needs to be enabled under the "Rendering" tab.

    A bit of an oversight that this component is not documented. I've made a note to address this.

    Glad to hear it is to your liking!

    Unity's vegetation system merely supports rotation on the Y-axis for trees, so they'll always end up being oriented towards the sky.

    As of Unity 2022.2, grass can align to the terrain normal through this parameter:
    upload_2023-6-5_11-11-7.png
    (That is, grass/detail items. Tree items do not have this option)
     
    Last edited: Jun 5, 2023
  10. Flxko

    Flxko

    Joined:
    May 24, 2023
    Posts:
    3
    Thanks for the quic

    Thanks for the quick reply! Much appreciated.

    How do I go about accessing the edit mesh window? Is it the mesh of the grass asset or the ground mesh itself? I'm just adding a terrain object, and then using the paint trees function to add the grass. Apologies for the noob question! Still learning the ropes here :)

    [EDIT]

    Figured it out! Thanks again.
     
    Last edited: Jun 5, 2023
  11. KarolisO

    KarolisO

    Joined:
    Feb 2, 2014
    Posts:
    29
    Hello! I'm getting the following errors when trying to bake a color map in the demo scene with Unity 2023:

    Shader error in 'Hidden/TerrainAlbedo': redefinition of 'sampler_LinearClamp' at Shader/Editor/TerrainSplatmaskPass.hlsl(5) (on d3d11)
    Shader error in 'Hidden/TerrainSplatmask': redefinition of 'sampler_LinearClamp' at Shader/Editor/TerrainSplatmaskPass.hlsl(5) (on d3d11)

    Any thoughts on how I could resolve this?
     
  12. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,102
    Unity 2023 is a beta/alpha version, which are not supported. The error about sampler redefinitions is one the breaking URP changes in this version, but it will be addressed once support for 2023 is verified.

    Edit: Seems to have been backported to 2022.3, so that is now not completely supported either. A workaround is to check the "Using third-party terrain shader" checkbox.
     
    Last edited: Jun 9, 2023
  13. kjorrt

    kjorrt

    Joined:
    Nov 26, 2014
    Posts:
    34
    Hi,

    I have read through the posts and at least two people have had similar problems to mine but their solutions didn't help me.

    I followed the guide for blending the grass with the terrain but all I get is red. I have double-checked the blue box and the grass and the terrain falls within the bounds.

    I have altered the bounds. The terrain is not using a custom shader. I have also tried placing the grass with both Unity's terrain system and as plain GameObjects but the result is the same. This result can be seen below.

    From what I've read it seems like the grass is not inside the blue box but the whole terrain is inside the blue box. Any ideas?

    Is there a terrain blending demo?


     
  14. Kerrjgan

    Kerrjgan

    Joined:
    May 30, 2016
    Posts:
    10
    Hey!
    I'm getting a few errors with some of the Terrain shaders. Unity 2022.3.2f1 // URP 14.0.8

    Code (CSharp):
    1. Shader error in 'Hidden/TerrainAlbedo': redefinition of 'sampler_LinearClamp' at Shader/Editor/TerrainSplatmaskPass.hlsl(5) (on d3d11)
    2. Shader error in 'Hidden/TerrainAlbedoAdd': redefinition of 'sampler_LinearClamp' at Shader/Editor/TerrainSplatmaskPass.hlsl(5) (on d3d11)
    3. Shader error in 'Hidden/TerrainSplatmask': redefinition of 'sampler_LinearClamp' at Shader/Editor/TerrainSplatmaskPass.hlsl(5) (on d3d11)
     
  15. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,102
    A red color specifies areas in the render where no geometry is visible, typically the skybox.

    The main demo scene has a color map set up, if re-rendering it there works as expected, then you can be assured the issue is not project-specific.

    @kjorrt This is actually related to the same issue as well.

    Verified support for Unity 2023.1 is pending next update. One thing that breaks is this error being thrown, which in turn breaks the color map rendering, resulting in a completely red render.

    I'm aiming to round off and submit the update this month :)
     
  16. AustinDrozin

    AustinDrozin

    Joined:
    Jun 8, 2016
    Posts:
    29
    How do you get the billboards to work with multiple cameras in the scene? I am switching between cameras a lot and it seems like that is breaking the billboard effect. I'm using it for grass and distant trees actually. First image is what it looks like in Editor, and second is when I hit play and the cameras are being used.
    upload_2023-6-19_18-48-30.png upload_2023-6-19_18-48-20.png
     
  17. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,102
    There's no set up needed for that to work. The billboarding is performed in the same process that positions the vertices in the world, based on the camera that's rendering it. Therefor it always rotates the mesh towards the camera looking at it, that could be any number of camera's simultaneously.

    What's odd is that edit or play mode makes no difference to a shader whatsoever, any differences you may see have to come from scripts so how.

    What I can imagine is if you use a third-party renderer, like Nature Renderer or GPU Instancer, it may not support split-screen functionality.
     
  18. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,102
    Version 1.4.0 is now available on the asset store! This is a large update to focused on tackling several backlog items, such as runtime colormap baking, and a generalized render feature.

    Changelog:
    Verified support for Unity 2023.1.f1

    Added:
    - New general Grass Render Feature, this now handles Bending, Perspective Correction and Dithering in one render feature.
    - Support for runtime Color Map rendering (GrassColorMapRenderer.Render()).
    - Hue Variation Height parameter, allows limiting the hue shift to the tip of grass geometry.
    - Option to use the camera's forward direction for Perspective Correction (on the render feature).
    - Additional wind gust texture variant (omni-directional).
    - Support for Rendering Layer Mask (lights and decals).

    Changed:
    - Improved UI for the Colormap Renderer inspector to provide more concise instructions and notifications.
    - When saving a Colormap asset to a file, the texture is now saved as a separate .PNG file. This will allow Unity to properly compress it.
    - Grass bending can now be disabled on the render feature.
    - Angle/Distance fading now uses a dithering texture (assigned on the render feature).
    - (Unity 2022.2+) LOD crossfading now uses the same shader function now native to URP.
    - Hue variation is now applied on a per-pixel basis.

    Fixed:
    - Colormap not taking effect when entering Play mode, if it was saved to an asset.
    - Non-terrain objects always rendering on top of terrains in a Colormap render output.
    - Colormap Renderer, non-terrain objects not being restored to their original Y-position after rendering.
    - Colormap Renderer, fresnel reflections potentially still being visible when using a third-party lighting system.
    - Ensured the flower prefabs have a centered position by default.
    - Grass benders not rendering using the SRP Batcher, if enabled.
    - Shader error 'redefinition of sampler_linearClamp' in URP 14.0.7+
    - Material UI, not respecting individual texture assignments when selecting multiple materials.

    Removed:
    (Deletions aren't tracked by Unity packages, these must be performed manually on your end)

    - GrassBendingFeature class.

    Update guide!
    When now rendering a color map, you may get the error "Graphics.CopyTexture called with mismatching texture data sizes, perhaps formats are incompatible?" If so, just hit the "New" button and it won't ever come up again:
    upload_2023-6-20_14-19-53.png


    Development overview
    This is the last update to support Unity 2020.3! 2021.3 LTS will be the new minimum moving forward.

    I now consider this the definitive version of the asset! Which means any major new features, or reworks are considered for the development of a new grass (shader) asset. I can't say there are any plans for that at the moment. But the past 3 years have proven that hand-writing an opaque shader is discouraged, due to Unity relying on people using Shader Graph, which allows them to change whatever they want in their shader libraries and don't have to be accountable for it.

    So the "next" iteration of the asset would be in Shader Graph. This yields easy support for other render pipelines and (semi)automatic implementation of new Unity features. On the flipside, third-party renderers wouldn't be integratable anymore, so the focus would lie on using DOTS.

    If you're familiar with the asset, or have been using it for quite a while, please consider leaving a review on the store page. This really does help with the continuity of the asset
     
    Last edited: Jun 20, 2023
    floky and TreyH like this.
  19. AustinDrozin

    AustinDrozin

    Joined:
    Jun 8, 2016
    Posts:
    29
    So I actually took everything out of my scene beside the meshes with the billboard shader on them and it still changes on play mode... I don't even have a camera in my scene now.



    Not using any different renderer.
     
  20. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,102
    Possibly what's happening is that the grass/tree geometry is being combined by Static Batching. I get that impression since clusters are rotating around a shared pivot. If your prefabs are marked for static batching, that should in any case be disabled as it prevents GPU Instancing from working.

    Could also be due to Dynamic Batching, but I'd recommend to check the Frame Debugger to see what's happening exactly.
     
  21. AustinDrozin

    AustinDrozin

    Joined:
    Jun 8, 2016
    Posts:
    29
    ah yep. That makes a lot of sense lol. I feel dumb for that one. So grass quads just shouldn't be marked as static ever then?
     
  22. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,102
    That's correct! Dynamic/static batching will prevent each instance from having unique properties, in this case an individual pivot point for the billboarding to rotate around.

    You can still mark prefabs as static for Occlusion Culling or GI though, just not Batching.
     
  23. Introfernal

    Introfernal

    Joined:
    Dec 5, 2017
    Posts:
    9
    Im trying the package with 2022.3.3 and bending is broken (also bend material is pink) is this expected? (SOLVED: Needed to change path to common.hsls to an absolute path)
     
    Last edited: Jun 25, 2023
  24. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,102
    Reimporting the shader in the Stylized Grass Shader\Shaders\Bending folder would have likely worked as well. If you got an error about an include file missing, it's a definite false-positive. Unity's shader compiler is growing more and more flakey.
     
    Introfernal likes this.
  25. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,102
    Check out the crowdfunded game Solarpunk, using Stylized Grass Shader

     
  26. ratking

    ratking

    Joined:
    Feb 24, 2010
    Posts:
    344
    What can I do to change the ambient occlusion color/strength at the bottom of the grass?
     
  27. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,102
    Under the Color tab, on the material, there is an Ambient Occlusion parameter. It controls the darkness of the base/root of the mesh.

    Or do you mean 'real' AO from a post-processing effect?
     
  28. ratking

    ratking

    Joined:
    Feb 24, 2010
    Posts:
    344
    Ah, strange that I missed that. By the way, I wonder if it's a good idea that the Color Map color is applied after the AO, so you can't really combine those two
     
  29. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,102
    The color map is currently applied last, in terms of color application, so will be laid over everything else. Though if the Colormap Height parameter isn't maxed out, you will be able to see the Ambient Occlusion parameter have a bit of an effect still (particularly around the vertical center). Perhaps that's what you're seeing.
     
  30. ratking

    ratking

    Joined:
    Feb 24, 2010
    Posts:
    344
    I just noticed that I'm mostly seeing the (somewhat) darker Equator Color of the Environment Lighting; I wonder if I can reduce that somehow for the grass

    [EDIT] Ah, it's because of the spherized normals. I'll just turn that off then.
     
  31. weiboyuan

    weiboyuan

    Joined:
    Sep 17, 2021
    Posts:
    2
    Is it necessary to use Nature Renderer or GPU Instancer as they do not support webgl? Will they bring even a slight performance improvement to the "Stylized Grass Shader" on webgl?
     
  32. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,102
    WebGL doesn't support Compute Shaders, which in turn makes various GPU-accelerated processing techniques incompatible. Something both NR and GPUI depend on, by also benefit from. Performance isn't so black and white, but their whole design is around superior performance (over Unity's terrain/GameObject setups), so its reasonable to assume they'd provide just that.
     
  33. weiboyuan

    weiboyuan

    Joined:
    Sep 17, 2021
    Posts:
    2
    I have tested the performance of GPUI in webgl and it does not seem to have any help in improving performance, so I think using them on webgl may not be very helpful for the performance of stylized grass shader.
    Can't stylized grass shader reduce batches without using them?
    I see a plugin called Infini GRASS GPU Vegetation that can render a lot of grass with very low batches on webgl. I am not sure if it can be combined with stylized grass shader.
     
  34. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,102
    On WebGL these assets will fallback to the slower non-GPU accelerated rendering, because WebGL in turn does not support compute shaders. This asset (Stylized grass shader) is not a rendering system, but rather a shader (+ related content), so it doesn't relate to batches.
     
  35. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,102
    Submitted version 1.4.1, a relative minor update with a few fixes. It is now also time to retire support for Unity 2020 LTS moving forward.

    Added:
    - LOD Crossfading support for cast shadows in Unity 2022.2+

    Fixed:
    - Script compile error in Unity 2022.2 (only)
    - Shader error in Unity 2023.1.7+ (URP v15.0.8) due to now backported code from Unity 2023.2
    - Grass turning black when Entity Graphics was in use without MaterialProperty components to define a color
     
    Lars-Steenhoff likes this.
  36. StanK_

    StanK_

    Joined:
    Dec 5, 2017
    Posts:
    10
    Hi @StaggartCreations
    Is colormap possible to use with the same effect of transparency on Simple Lit / Simple config as with unlit?
    Here are the results on the empty scene, unlit shader:
    upload_2023-8-17_16-34-56.png

    Here are the simple lit for plane and grass on simple mode:
    upload_2023-8-17_16-35-53.png

    Is it possible to get the same result for Lit as the first one? I noticed playing with flatting normals gives some transparency for a few faces, but others are becoming darker
     

    Attached Files:

    Last edited: Aug 17, 2023
  37. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,102
    When the material is lit normals indeed start to play a role. You'd want the normals of the bottom vertices to point straight up, since the normals of the terrain at that point do as well.

    You'd want to keep the "Flatten normals" parameter set to 1
    upload_2023-8-18_12-29-47.png
    As well as the "Tip mask" parameter, so that normals on the bottom stay pointed upward.

    Also consider that right now there is one patch of grass, and you're looking at it intently. In the context of a complete environment and gameplay, a minor discrepancy in color will hardly be noticeable.
     
  38. StanK_

    StanK_

    Joined:
    Dec 5, 2017
    Posts:
    10
    @StaggartCreations yeah it' better now, played also with some external AO to get more darkenings and terrain shader by itself.

    Have another issue to ask suggestion, I have each terrain's chunk as an individual mesh procedurally generated, for colormap feature I'm currently making colormap renderer everytime player moves over different chunks. It takes performance to re-render all chunks again and draw the colormap, redrawing already placed grass.
    Is it possible to have many colormaps working simultaneously, so I'd have a colormap for each individual chunk or some solution that could solve rerendering colormap after every chunk changed (as the whole colormap becomes very big with all chunks around)?
     
  39. Sir_patrickl

    Sir_patrickl

    Joined:
    Jun 24, 2013
    Posts:
    51
    Hi, I'm using version 1.41 and I did a test upgrade to Unity 2022.2.1f1 and I'm getting a compile error in the StylizedGrassShader.shader

    line 120:

    Code (CSharp):
    1.         #if UNITY_VERSION >= 202220
    2.         #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl"
    3.         #endif
    I enabled Rendering Layers in URP assets but that didn't help.

    Is there something else I'm missing? It was all working fine in 2021 LTS prior to updating.

    Thanks
     
  40. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,102
    I'd recommend skipping 2022.2 and using 2022.3 instead, as this is the LTS version.

    When using Unity 2022, you'd actually have to use 2022.2.15f1 or newer. This version uses URP v14.0.7, in which the "RenderingLayers.hlsl" shader library is in fact present.

    It is a relatively recent trend that minor patch releases of Unity start to introduce such breaking changes. As you can see, the shader code accounts for "Unity 2022.2 or newer", but there is no syntax available to check for minor versions. Hence I'm always going to assume the latest release version when updating assets.
     
  41. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,102
    Given the process behind the baking, it would be too slow to perform in situations where performance needs to remain consistent.

    The limitation of 1 active color map at a time would remain. It's technically possible to overcome this, but it quickly spins out of control in terms of scope.

    Procedurally generated and streamed terrains is a particular use case that rubs against these limitations unfortunately.
     
  42. Sir_patrickl

    Sir_patrickl

    Joined:
    Jun 24, 2013
    Posts:
    51
    Not sure how I missed that version, I thought I changed to latest version but obviously didn't. Updated to 2022.3 and works fine now. Thanks!