Shader works in editor but not on Android

Hello!

This is the shader I am trying to use. I did not write it. I got it on the web.

Shader "Custom/Scanlines" {
	Properties{
		_Color("Color", Color) = (0,0,0,1)
		_LinesSize("LinesSize", Range(1,10)) = 1
	}
		SubShader{
			Tags {"IgnoreProjector" = "True" "Queue" = "Overlay"}
			Fog { Mode Off }
			Pass {
				ZTest Always
				ZWrite Off
				Blend SrcAlpha OneMinusSrcAlpha

		CGPROGRAM

		#pragma vertex vert 
		#pragma fragment frag
		#include "UnityCG.cginc"

				fixed4 _Color; half _LinesSize;

				struct v2f {
					half4 pos:POSITION;
					fixed4 sPos : TEXCOORD;
				};

				v2f vert(appdata_base v) {
					v2f o; o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
					o.sPos = ComputeScreenPos(o.pos);
					return o;
				}

				fixed4 frag(v2f i) : COLOR {
					fixed p = i.sPos.y / i.sPos.w;

					if ((int)(p*_ScreenParams.y / floor(_LinesSize)) % 2 == 0) discard;

					   return _Color;
				 }

		ENDCG
			   }

	}

}

And this is the script I am using to load it. It is attached to the camera.

using UnityEngine;

[ExecuteInEditMode]
public class CRTShader : MonoBehaviour {

    private Material material;

    void Start() {
        material = new Material(Shader.Find("Custom/Scanlines"));
    }

    public void OnRenderImage(RenderTexture source, RenderTexture destination) {
        material.SetTexture("_MainTex", source);
        Graphics.Blit(source, destination, material);
    }

}

It runs fine on the editor but it does not work on the Android build.

The shader is in the Resources folder.

What I am doing wrong? Any ideas?

Thank you.

I’m not sure why you’re creating a new material in Start() ?

material = new Material(Shader.Find("Custom/Scanlines"));

Add the [SerializeField] attribute to the material variable (or make it public, not private) to expose it in the inspector and assign a material that uses the Scanlines shader directly, which will ensure it gets included in the build.