Hi, I am fading out my character when they die, and this all works great. The problem I am having is the shadow doesnt fade out with them.
Is it possible to make the shadow fade out at the same time? What bit of shader code do I need to mess with to achieve this?
Sorry new to shaders but keen to learn!
Not really… So, the way shadowing works is that the light is either blocked for a pixel, or it’s not. You can blur that and add effects to make it softer, but it’s all based on the hard shadow basics.
That’s why, for example, any game you see on the market with windows, those windows either block out light entirely or not at all. It’s an occlusion issue, not a blending issue.
I don’t know of any way (or for that matter any engine) which can do what you’re looking for properly, but here’s the best way I know to simulate it:
Have two models of the fading object. One visible on the screen that does not cast shadows, and one invisible that does cast shadows.
On the invisible one, instead of doing an alpha crossfade, do a speckling fade. E.g. if alpha is 50%, then just turn off a random 50% of the pixels in the shadow model. The shadow will flicker a bit as it fades, but it should dissipate instead of popping.
I found the dissolve shader on the wiki worked, and under the renderer shadows options you can have “only shadows” which gave me exactly the result I was looking for.