Better way to get shadows on grass particle system

I have a grass particle system that currently uses a render texture from a camera facing down towards the ground to color the particles (i.e. blades of grass). I also have a simple cloud shadow texture that rolls across the ground. While this works for the time being I am wondering if there is a better solution to get shadows like sampling the color of the vertex underneath and getting the color of the material and the shadow. If it involves HLSL I may need some assistance as I am not too well versed in shaders.

Grass with Blades that use a Flipbook sprite

Spawning of the grass particles

Sampling the Mesh and Particle ID and setting the color according to the Render Texture UVs

Flipbook Sprite output

Hi!

To be able to properly receive shadows and lighting, ideally you should convert your output to a lit version.

In your case, since it seems you don’t want lighting, just the shadows, maybe you could expose a texture (like you have now) and, instead of the render target pass the main light shadow map.

With that and the inverse light matrix, you should be able to sample the actual shadow at any position.
I’ll try a quick test and get back to you if it works.

Thanks for your help. Hopefully to narrow your focus I plan to use this to get banding shadows that move across the grass. I hope I am moving in the right direction.

How are these shadows generated at the moment?

At the moment I have a cookie on my main light with a shadow texture. But the reason I want to capture shadows is to do a toon shader style shadow effect where the shadow bands. I hope I haven’t been too confusing on this post.

I think I understand what you mean with the bands, but this is going to be very difficult to do with shadow maps.

If you look at most 3d toon games, they usually have hard shadows with no bands. This is because the shadow map only gives you depth information, which allows you to know whether a pixel is in shadow or not, but no grayscale values. Of course, PCF and other techniques allow you to get some soft shadows as well, but it is usually a short gradient that may not look great with bands.

That being said, I think hard shadows should be more than enough for your toon shading.

Now, back to your question, unfortunately I could not find a good way to obtain the shadow map (or a copy) for a specific light. Shadow maps live only during rendering, they behave differently depending on the SRP and some settings, and they are meant to be used only during the lighting passes.

I think your best option is to convert the output to URP or HDRP lit, and use a shader graph if necessary to get your custom look. This will help, not only with shadows, but also to get a more consistent look with the rest of lit objects under different lighting settings.