Textures used for shadow casting being switched across all materials using the same shader ?

I came across an odd behaviour I have a hard time understanding :

I made a foliage shader that needs to cast shadow from a cutout texture.
It works well until I have a second material with the same shader that use another texture.

The shadows now flick from one texture to another.

6797585--788144--shadowsSwitch.gif

I believe this is based on the cascaded shadow distance because it seems to change accordingly :

6797585--788147--cascadedShadow.gif

All I could think of was that the SRP batcher sets one texture to use for all material, even if I don’t actually use the _BaseMap from the CBuffer and also that my shader isn’t compatible with SRP batcher…

The shadowcaster pass I use is the one from Unity , I only added this little piece of code to cutout.
(input.uv2 is just the texcoord )

Anyone have any clues? Thanks in advance !

Up ? :frowning:

I have few ideas that you can try:

  1. You can try to use RenderDoc to gather and analyze draw calls. It is super helpful in situations like this.
  2. I see that you used discard but Alpha method use clip instead. So you can try that. They actually do the same but who knows:)
  3. You can disable cascade shadowing and check what will happen.

Thanks for your reply,

-I don’t see how drawcalls debug would help here, a part from knowing that it actually does increase and decrease from the shadowpass calls ?
-Clipping didn’t change anything,
-Disabling cascaded shadow actually disables one of the textures, so basically all materials cast the shadow of a specific texture that they don’t have a ref to.

The “texture switch” seems to only be there when using 4 cascades, at the most detailed one.

So the expected behaviour is only there when using 4 cascades, but if I increase the distance, then it switch back .

By the way, duplicating the shader per materials that has a different texture does work. so yeah that’s the quick fix for now but duplicating my shader per texture is not the best workflow nor the most optimized so …

sorry for late answer but this issue reminds me a very recent bug. We’re working on a fix to be published soon, but meanwhile you can try a work around: disabling “static batching” may fix this issue. Of course it’s just a work around and you may lose some CPU perf by disabling static batching (depends of your scene )