(SHADER) How to make black-white mask from texture without if branching?

A texture uses black background for unused space, which should be filled with another color, defined in shader parameters, but other colors, that are painted on the texture, should not be altered.

So i need to make a black-white mask from this texture to simply multiply a color with it, but i fail to do it. Painted colors appear lighter or even inverted with different approaches that i used, seems like i’m missing something.

I do not want to use branching, because this shader will be the main shader in the game and it will break performance.

HI, @curly-brace

  1. You can make a mask from texture by multiplying it by great value an then clamp it to 0-1 (black part of texture will not be affected, other colors turn to white).
  2. Then you can use lerp(a,b,t) function to combine final texture: lerp (_Color, _Texture, _Mask);

_Color - your shader parameter;

_Texture - initial texture;

_Mask - result of step #1

NVidia Lerp reference:

http://http.developer.nvidia.com/Cg/lerp.html

Hope this helps