Search code examples
unity-game-engineshadertextures

Unity shader to subtract texture from mask


I have 2 textures, one is a painting and another is a black and white image that must work as a mask.

In a nutshell, I want to be able to "subtract" those textures, so that the paiting becomes transparent where the mask is black and keep the same color where the mask is white.

The paiting and the mask don't have the same dimensions, but they are both square-like.

How can I do this efficiently?


Solution

  • I think you could simply multiply the painting by the mask. The black parts of your mask are equal to 0 so they will turn the painting transparent in those parts and the white parts are equal to 1. You could even have the painting fade out if you had grey values because greys are between 0 and 1.

    Also, make sure your texture and your shader have the appropriate boxes ticked to support transparency.