Hello everyone, I have a problem. I tried to search but I can’t find what I want.
I have a texture. This texture have a blue, green and black colors. They are masks, this is a face texture actually.
I want to replace them like blue color will replace with my eyes texture in unity, green color will replace with face texture…
How can I write this shader? I searched but only I find color changing shaders
Thanks…
You would sample each of the different textures, then simply lerp from the base color to each sampled texture color, in the order you’d want them layered (though ideally it shouldn’t matter since your mask should only have a given color in the area it needs it without >1 value overlaps).
Here is a simple example:
float4 col = tex2D(_MainTex, i.uv); //I'm guessing this is your body texture?
float4 mask = tex2D(_BlendMap, i.uv);
float4 faceTex = tex2D(_FaceTex, i.uv);
float4 eyesTex = tex2D(_EyesTex, i.uv);
col = lerp(col, faceTex, mask.g); //blends into face texture based on mask green value
col = lerp(col, eyesTex, mask.b); //blends previous result into eye texture based on mask green value
return col;
Usually it would be better to have your eyes be using a separate material meant just for eye textures though instead of using blending like this. Or is this some cartoon-like character or 2D where it’s a solid face?