Stylized Grass Shader ☘️ Unity 6 support now available!

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.

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.

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.

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.

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 :stuck_out_tongue:

1 Like

8947143--1227765--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?

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".

8948166--1228281--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.

1 Like

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

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.

1 Like

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.

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.

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

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

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.

2 Likes

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

“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.

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

2qcms6

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?

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:
9057406--1252123--upload_2023-6-5_11-11-7.png
(That is, grass/detail items. Tree items do not have this option)

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 :slight_smile:

[EDIT]

Figured it out! Thanks again.