Surface Shader not blending two samples correctly

When sampling the same texture twice in a surface shader, I have the following:

At the end of my surf() method, when I get my main sample from the following code:

float3 mainTextureSample = tex2D(_TextureMap, textureUV);
o.Albedo = mainTextureSample.rgb;

I get the following output:

If I use the following code:

float3 detailTextureSample = tex2D(_TextureMap, detailUV);
o.Albedo = detailTextureSample.rgb;

I get the following output:

If I use this code to try to combine the two:

float3 mainTextureSample = tex2D(_TextureMap, textureUV);
float3 detailTextureSample = tex2D(_TextureMap, detailUV);
o.Albedo = mainTextureSample.rgb - detailTextureSample.rgb;

I get the following:

Since the detail sample is returning black, I’d expect to see something like:

Am I doing something wrong? My shader was working in 5.3, but in 5.4 it seems that it isn’t calculating things the same way?

You might want to look at the generated shader code, there have been some bugs with the surface shader generation code in Unity 5.

Mainly it’s quite possible the surface shader is using the same UV for both the main and detail UVs when trying to use them both which is clearly wrong.

As far as I can tell, the shader seems to be packing the texture uvs correctly.

If i move all of my surface shader code to a finalcolor shader, I get the expected output. Unfortunately, that also strips the lighting information off of the final color which I need.

I am running the code on my Mac, so it is running OpenGL 4. When I get back to my Windows machine, I’m going to see if the DirectX shader also produces the same result.