How to interact with shadows in shaders that move vertices

Hi everyone!

I’m hoping to get general guidance on how to interact with shadows with my node material shader. I have a very complex main shader I use in my game. There is a part that moves the vertices a bit according to uv2 texture, so I can make trees and foliage wobble a bit, so I can simulate them being affected by “wind”.

Currently, the wobbly effect does not effect the shadows at all. Take a look at the picture below:

shadowsss2

So the shadows stay stationary the whole time. Is there any way to include the vertex movement to the shadows themselves? Will that be costly performance wise? I use the cascaded shadow generator in my case.

Thanks in advance for all the help :nerd_face:

The reason is shadow use his own shader to render depth. You can use ShadowDepthWrapper using another node material with the same vertex part and a simple fragment part, this should not cost much but depends on your vertex code.

3 Likes

Woah thank you, that was easier than I thought! Hooked it up and seems to work well :star_struck: Thanks for pointing me to the solution!

shadowsss4

Here is a relevant part of the docs for future readers: Babylon.js docs

1 Like