Hi Guys,
I am trying to make simple cap geometry with strips Texture on it. and i want to make 8 color variations of the same Cap, which are later randomly placed on floor . In this case is there any way where we can make one Texture (greyscale map) with alpha channel (alpha channel contains strip information) where we should be able to change the color in shader where the changes should reflect only on the defined alpha region i.e. on strips ?
for example if we change the color to red in shader than only defined alpha region should change to red color, rest should remain same.
The exact method will depend on the shader, but in general pretty simple and a common trick. For reference, the “red goes here” alpha channel would be called a “control” channel (or texture.) It turns out that you can use any channel – for example paint red where the red should be. It the original texture is opaque, can even use its alpha. The terrain shader (FirstPass, AddPass) is very short and uses the same trick, but 4 times in a row. Code you want is something like:
// in fragment shader
half4 col = ... // this line is already there, looking up usual texture.
// grab your "alpha is red" texture, whichever channel you painted:
float redAmt = Tex2D(_redTexture, IN.uv_MainTex).a;
// NOTE: assuming uses same unwrap, can substitute IN.uv_Tex2... if not
half4 red = float4(1,0,0,1);
// ...or you could add "mixColor" to the material and not need this line
// This is the 2nd key line, that does all the work:
col = lerp(col, red, redAmt);
// Standard lerp. redAmt goes from 0 to 1. gradient alpha gives gradient red
// Can flip col<->red to make "no alpha" turn red
// if you want sharp, pixellated red borders, use instead:
if(alphaRed>0.5) col=red;
There’s a little more set-up. You’d want to name and add redTexture in two places (right where _MainTexture is.) Plus if your starting shader is just ShaderLab w/o a fragment shader, this won’t work at all. There may be ShaderLab commands to do the same thing.