- Home /
cut a hole in a sprite with alpha
I'm trying to cut a hole in a sprite using shaders. So far it works with the stencil shader, and some freely accessible code all over the web, however I've realised I can't have transparent gradient edges on the hole. Here is what I can do currently:
but what I would like is to have transparent edges like this:
I've been trying for hours, but no luck so far. I'm sure there must be a way to do it. If someone could at least point me in the right direction I'd greatly appreciate it.
If you want to invest some cash, you could try Alpha $$anonymous$$ask on the asset store It may not have a a soft masking option but you could also take a look at the new(Unity 2017.1) Sprite $$anonymous$$ask
Answer by DrZarqawi · Aug 08, 2017 at 11:33 AM
I'm not sure how you are trying to accomplish this, but; The way i would go about it would be to create a new temp sprite and copy over the RGB data from the sprite you want cut from.
I would then define the area i wanted to cut, maybe based on the size of my cut-mask. then go through each pixel of the defined area on the temp sprite and compare the alpha value to the corresponding pixel in the mask.
If the temp sprites pixels alpha value is higher than that of the corresponding pixel in the mask, then set it to the masks alpha value. repeat until all pixels are accounted for.
Then overwrite or replace the old sprite with the temp sprite.
Answer by niorg2606 · Aug 08, 2017 at 02:06 PM
You're using shaders for transparency? I would just use unity's built in Alpha From Grayscale option and Alpha Is Transparent option, both found when clicking on a Sprite in the project tab.
Your answer
![](https://koobas.hobune.stream/wayback/20220612132227im_/https://answers.unity.com/themes/thub/images/avi.jpg)