Custom Shader not working on Mac or iOS

Hey folks,

I have a scene in which I needed to cast shadows onto a transparent surface. Obviously the build in stuff wont do this, So I turned to the ProjectedShadows Script on the Unify wiki, which sort of gave me what I wanted, but the actual projection of the shadow wasn’t giving the desired results.

So in the end, I stripped out the projector part of it, pumped the render texture through as the main texture of new transparent material, and worked a shader together to draw the shadow area and nothing else as I needed it.

On PC this works a treat, and does exactly what I wanted (minus a soft edge / blur which I’ll look at adding later). However when I open the project on a mac, or build it to iOS…nothing, no shadow. In the mac editor I can swap the shader on the shadow planes material to be a regular diffuse or transparent shader and I can see that the texture is rendering ok. but I need this shader to work to get the correct coordinate mapping and fragment opperations.

Here is the shader.

Shader "Custom/GroundPlaneShader"
{
	Properties
	{
		_Color("_Color", Color) = (1,1,1,1)
		_MainTex ("Base (RGB)", 2D) = "white" { TexGen ObjectLinear }
	}

	SubShader 
	{
		Tags { "Queue" = "Transparent" }

		LOD 200
		Blend SrcAlpha OneMinusSrcAlpha
		
		Pass 
		{
			CGPROGRAM

				#pragma vertex vert
				#pragma fragment frag
				#include "UnityCG.cginc"
				
				sampler2D _MainTex;
				float4 _MainTex_ST;
				half4 _Color;
				float4x4 _Projector;
			
				struct v2f 
				{
					float4 pos : SV_POSITION;
					half2 uv : TEXCOORD0;
				};

				struct appdata 
				{
					float4 vertex : SV_POSITION;
				};
			
				v2f vert(appdata v) 
				{
					v2f o;
					o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
					o.uv = mul(_Projector, v.vertex).xy;
					return o;
				}
						
				fixed4 frag(v2f IN) : COLOR 
				{
					half4 diffuse = tex2D(_MainTex, IN.uv);
					diffuse.a = 1- diffuse.a;
					return diffuse * _Color;
				}

			ENDCG
		}
	}
}

Can anyone see a reason why this shader will work on PC but not on Mac or iOS ? or is there an even greater mistake that means the working on PC is nothing short of an unfortunate random coincidence.

any help and suggestion is greatly appreciated. thanks folks.

At a glance, it looks fine to me.

_MainTex (“Base (RGB)”, 2D) = “white” { TexGen ObjectLinear }

The TexGen ObjectLinear might be confusing it, I think that’s for fixed function shaders. Try replacing it with
_MainTex (“Base (RGB)”, 2D) = “white” {}

Do you get any errors in the console?

That doesnt change it unfortunately.

No console errors but i think i’ve found the issue.

Im using _Projector to generate the uv coords, but there is no longer a projector in the scene at all (it also doenst work on PC anymore after some changes) So my best guess is that when it was working on PC it was simply the luck of having the _Projector value set at the right value at that given time. but it has since changed.

Im trying to see if having the projector left in the scene but just with no shadow texture will work (hoping it will still set the _Projector matrix for the other material to use). However failing that, is there any way to get the correct projection matrix over to the shader given that the shadow texture is generated from one ortho camera in the scene, and then the scene (and the plane with the shadow on it) are then rendered from a perspective camera elsewhere in the scene?

Edit: Seems not, even if I leave the projector set up exactly as it is from the ProjectedShadows script the custom shader still doesn’t map the coordinates correctly when it gets rendered.
SOLVED: Issue is now solved, for any interested my current solution is just to leave the projector in the scene, and simply never give it the shadow texture, that way it still seems to set the necessary projection matrix but doesn’t influence the scene in any other way. It isn’t an ideal solution, but its working for now.