I have very little experience with shader programming and I could use some help with getting the following shader to work.
What I’m trying to get is the following:
Unlit transparent shader using 2 textures, each for one UV set.
The second UV set is has a texture which determines the transparency (like an alpha texture).
The reason I’m not using the alpha channel of the first texture is that the alpha texture should use the 2nd UV set instead of the first.
I managed to get the 2 textures loaded, each using a different UV set. The problem, however, is that I cannot figure out how to combine them so that the black color of the second texture becomes transparent.
Texture input:
First texture (UVset 1)
Second texture (UVset 2)
First texture + second texture (everything in BLACK should be transparent)…
That’s only part of what’s needed to make a shader render as transparent, in some ways that’s actually the least important part. You also need to set the Blend, ZWrite, and the Queue. Also your textures are both RGB textures with no alpha, and by default textures have 100% full alpha (opaque), and you never assign an alpha value. You in fact throw away the alpha channel of your alpha texture if it had alpha by using col.rgb = combined;
Around where you have Tags you’ll want this:
Tags { “Queue”=“Transparent” “RenderType”=“Transparent” }
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
And then in the shader code itself you want this:
fixed4 col = tex2D(_MainTex, i.uv);
fixed4 alpha = tex2D(_AlphaTex, i.uv2);
col.a *= alpha.g;
return col;
That uses the green channel of your “alpha” texture as the alpha or transparency output by the shader.
However once you do all of this you’ll find your cat looks kind of funny if this shader is used on the entire body of the cat, and that’s because of ZWrite Off. If you remove that line or set it to ZWrite On you’ll also get a different funny result. I’ve written about this a few times here on the forum if you want to know why.