Shader with two textures separated by an alpha channel?

I have a bunch of wall assets which look like this (quick screenshot, the full texture tiles):


I am trying to make the red parts animate and move horizontally, whereas the gray foreground parts stay static. Currently this is my solution:

  1. Use two planes with separate textures, one 0.001 units behind the other.
  2. For the foreground, use a cutout alpha shader to mask out the parts that should be red/animated.
  3. For the background, use a separate texture with a script that changes the X offset and time it so that it tiles.

While this works, it’s clumsy to use two planes for each wall section, it makes it harder to snap to a grid since it often snaps to the element with an offset, and it uses more draw calls through separate materials.

Is there a way to make a shader which has these properties?

  1. Use a diffuse map which is masked by its alpha channel.
  2. Use a second diffuse map which uses no alpha and always renders below the first one.
  3. Have the second diffuse map be targetable with a script so its offset can be animated separately.

This way I could do it all in a single plane with no (or minimal) extra draw calls and it’d all work much more elegantly. I’m not very knowledgeable on shaders and any material on this kind of approach I found online was either incomplete or obsolete at this point. This is a mobile-targeted game so optimally there’d only be a diffuse map and it’d be lit with a lightmap.

is this what you need ?

Shader "2 layers transparent" {
	Properties {
	   // _Color ("Overall Color", Color) = (1,0.5,0.5,1)
		_t1 ("texture in white", 2D) = "white" {}
		_tint1 ("Tint1", Color) = (1.0, 0.6, 0.6, 1.0)
		_t2 ("texture in red", 2D) = "white" {}
		_tint2 ("Tint2", Color) = (1.0, 0.6, 0.6, 1.0)
	    _t3 ("use for alpha channel", 2D) = "white" {}

		_rc ("low cutoff", Range(1,80)) = 1.0 
	SubShader {
		//Tags { "RenderType"="Opaque" }
		LOD 200
		#pragma surface surf Lambert
        float _rc;

		sampler2D _t1;
		sampler2D _t2;
		sampler2D _t3;

        fixed4 _tint1;
        fixed4 _tint2;

		struct Input {
			float2 uv_t1;
			float2 uv_t2;
			float2 uv_t3;


		void surf (Input IN, inout SurfaceOutput o) {
		    float f;
			half4 pix = tex2D (_t1, IN.uv_t1)*_tint1;
            half4 pix2 = tex2D (_t2, IN.uv_t2)*_tint2;
			f=tex2D (_t3, IN.uv_t3).a;
			o.Albedo = pix.rgb;
	FallBack "Diffuse"