Blending between two textures using alpha from the third (Path Mask) texture.

I created a terrain in blender, exported it in unity and I need to apply two textures with tiling, one for grass and another for roads, I also have third texture with a mask.

I have found a shader that seems to solve my problem. http://wiki.unity3d.com/index.php/LayerShader

It blends between two textures using alpha from the third (Path Mask) texture.

It works fine in editor and on my nexus 4 smartphone, but on other smartphones (asus zenfone 2, moto g) the polygones start to jump randomly, like uv coordinates are constantly moving and then returning to the right place.

So may be this task can be done using standard unity 5 shaders?
I tried using detail mask and secondary map, But I only managed to put one texture where it should be but another part remains without texture.

May be we can somehow fix the old shader? I don’t know what is outdated here:

Shader "MyShaders/TerrainTwoLayer" {


Properties
{
	_Color ("Main Color", Color) = (1,1,1)
	_MainTex ("Main Texture (RGB)", 2D) = ""
	_PathTex ("Path Texture (RGB)", 2D) = ""
	_PathMask ("Path Mask (A)", 2D) = ""
}

SubShader 
{
	Lighting On
	
	Material 
	{
		Ambient [_Color]
		Diffuse [_Color]
	}

	Pass
	{		
		SetTexture [_MainTex]
		
		SetTexture [_PathMask]
		{
			combine previous, texture
		}
				
		SetTexture [_PathTex]
		{
			combine texture lerp(previous) previous
		}
		
		SetTexture [_MainTex]
		{
			combine previous * primary	
		}
	}
}

SubShader 
{
	Lighting On
	
	Material 
	{
		Ambient [_Color]
		Diffuse [_Color]
	}

	Pass
	{	
		SetTexture [_MainTex]
		{
			combine texture * primary
		}		
	}
	
	Pass
	{
		Blend SrcAlpha OneMinusSrcAlpha
				
		SetTexture [_PathTex]
		{
			combine texture * primary
		}
		
		SetTexture [_PathMask]
		{
			combine previous, texture
		}
	}
}

Fallback "Diffuse"

 
}

Try this one :

Tell me if it works :slight_smile: