I'm trying to get the background of an image to be transparent, but I'm encountering some issues, and I can't figure out what's wrong with my shader code. Here's the shader code in action:
The effect looks fine to me on the playground, but in the simulator, the shader looks a bit different:
The original image simply has alpha around the outside of the bottle, but my shader is not letting the background be completely transparent. I know it's something to do with my code, because if I add a cutoff conditional, like this (note that there are three new lines, 27-29):
Then it will work in the simulator and on device and show pure alpha around the edges. But this is obviously a hack because it won't work when alpha is anything between .01 and 1, and I'd like to know what I'm doing wrong. It seems like, in the first version of the shader I've shown, the alpha variable should set the transparency properly on line 25, and even that should not be necessary, since all the other colors use this alpha value, and the mixing should not affect it.
What am I doing wrong? Why doesn't setting the alpha just work, without the added, hacky cutoff conditional?