- Home /
Shadows with Alpha, fade out shadow.
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!
Did you find a solution to this? Its been asked a few times but I haven't seen an answer anywhere. Thanks.
Answer by FortisVenaliter · Aug 20, 2015 at 10:00 PM
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.
@FortisVenaliter thats a great technical explanation and also a good idea for how to avoid popping.. But now for the obvious next question..Do you know of any reference examples of this? Thanks
The shadow fade actually work perfect using unity 5 standard shader with Fade and Transparent mode.
Um, not it doesn't its all or nothing, I was working in this less than 12 hours ago
No, I haven't had to try that since C++ and DirectX, and I don't even know where that code is. But I do know I've seen both speckle fade and shadow-only shaders out there for Unity, so it shouldn't be too hard to combine them.
Answer by AaronC · Aug 21, 2015 at 10:07 PM
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.