Cutout + Surface Shader

Hi, I’m pretty new to shaders and I only really have experience with surface shaders in Unity.

Basically, I want to have a cutout-like effect dictated by a secondary texture’s alpha but instead of not drawing a pixel I’d like to instead draw another texture. Right now I can the first part but the second part eludes me.

Whenever I tried that I could only seem to figure out how to draw the third texture when the secondary texture, used to sample alpha value, had alpha. I couldn’t achieve the cutout-like effect no matter what I tried.

This is the desired look:

But that is currently achieved by duplicating the mesh and having two different materials on each. I cannot figure out how to achieve filling out cutout-like alpha effect with the lava-like texture.

P.S. I know it looks terrible but it is true to its source material: http://www.pso-world.com/images/items/BB-YAMATO-ACTION-1.jpg

Well, I kind of got it but I’d prefer not to use an if. Those are supposedly poor for performance right?

if(cutoffTexAlpha - _CutOff < 0)
{
     o.Albedo = tex2D(_EmissionTex, IN.uv_EmissionTex);
     o.Emission = _Emission * o.Albedo;
}

That’s about all I could come up with. It works but I’m not sure it’s a good way to do it.

You could replace your if statement by a lerp

half4 mc = tex2D (_MainTex, IN.uv_MainTex);
half4 sc = tex2D (_SecondTex, IN.uv_SecondTex);
half4 bc = tex2D (_BlendTex, IN.uv_BlendTex);
o.Albedo = mc.rgb * (1f - bc.rgb) + sc.rgb * bc.rgb;

There I use a black and white blending texture. If the pixel is white th second texture is used and if the pixel is black the the main texture is used. This may not be the solution but I think it’s better than the if statement.

I hope that’ll help.

Hmmmm, well I don’t necessarily want to use the emission texture based on a white or black pixel or alpha directly. I need an alpha cutoff-like effect so that I can finely control the amount of cracks in my lava cracked rocks seen here: https://i.gyazo.com/b5dc1b889c923d08e116df8099a4d730.mp4.

The question I face now is if I were to find a way to remove the if/branch would it be more efficient? I’d have to do a texture lookup all the time for the emission texture.