Unity 3D Shaders for Two Transparent Textures

I like programming. C++ and C# make sense to me. Graphics and shaders, less so. I understand them, I just don’t have much experience with the syntax used in Unity 3D’s shader system.

And so, I was annoyed when I wanted to have a shader that faded between two transparent textures. I assumed that this might be a good way to smooth out 2d animations. But while I could find shaders that would fade between two normal textures, I couldn’t find ANYTHING that supported alpha transparency in those textures.

Anyway, after much experimentation, I made up the shaders myself. They work quite well, too. Sadly, they don’t work well for what I need: the first shader is based on Unity’s transparency shaders, which work great by allowing semi-transparent colors, but this causes errors with rendering order and isn’t good for more complex scenes with a lot of transparent textures. I typically stay away from that and use cutout transparency shaders, which don’t allow semi-transparency, but don’t have the errors I mention. From an animation perspective, the first (transparent) shader looks better, but the second (transparent cutout) is necessary for actual use but doesn’t look as good. I provide both here, hoping it helps some of you out. Maybe I can use it elsewhere…

Continue reading