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.