Error when trying to add shadowcaster pass to terrain shader in Unity5

I’m in the middle of upgrading a project from Unity4 to 5.
I had made a custom terrain shader which is just the default terrain shader in Unity4, with an extra shadowcaster pass to fix a shadow-flickering problem we had.
Now when I add the same pass to the new terrain shader in Unity5, I get the following error:

with line 45 being the CGPROGRAM -line in the shadowcaster pass.

I have no idea what it means, and I can’t find any relevant info.

Anyone have a clue?

Here’s the shadowcaster pass incase you’re curious:
shadowcaster pass

SubShader
{
    // Pass to render object as a shadow caster
    Pass
    {
        Name "ShadowCaster"
        Tags { "LightMode" = "ShadowCaster" }
       
        Fog {Mode Off}
        ZWrite On ZTest LEqual Cull Off
        Offset 1, 1

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

        float _Offset;

        struct v2f
        {
            V2F_SHADOW_CASTER;
        };

        v2f vert( appdata_base v )
        {
            v.vertex.y += _Offset;
            v2f o;
            TRANSFER_SHADOW_CASTER(o)
            return o;
        }

        float4 frag( v2f i ) : COLOR
        {
            SHADOW_CASTER_FRAGMENT(i)
        }
        ENDCG
    }
}

I do believe that the line numbers it details are confusingly the line numbers of the COMPILED shader program. Review the contents of the compiled shader on that line to get a better idea of what is causing the issue.

Hi, thanks for the reply.

It doesn’t seem that way, regardless of where I place the shadow pass, the error points to that CGPROGRAM -line. When I look at the compiled shader, the same line number is a blank line or some random other line (depending on where I place the shadow pass),
so it really is pointing to the CGPROGRAM -line.

The error seems to say that surface shaders don’t allow CGPROGRAM stuff, but that just isn’t true, so I just don’t know what the problem is.

You know what? Try moving all of your ZWrite Ztest stuff on its own line:

ZWrite On
ZTest LEqual
Cull Off

I don;t think it is valid to specify them on one line.

I tried it, didn’t work. :s
I actually use the same shadowcaster pass in other shaders and those work, so the pass itself is fine.

I should have probably also noted that I get a warning as well:

So what does that mean exactly? I can’t have more than 1 vertex shader in 1 file (each in seperate subshaders)? That can’t be right.

I’m looking back into this but I can’t find what’s wrong. And it doesn’t help that I don’t actually understand much of Unity shader stuff. :s

Any help?

Or can anyone just explain me what this means:
#pragma surface does not allow specifying other programs

what programs? what’s it talking about?

OK, got it working. (Typical that that happens right after me asking)

I moved some of the code around and now it works:

The terrainshader contained a CGINCLUDE part, and then a Category thing with 2 subshaders in it (for shader model 2 and 3+) and then my custom subshader with only a shadowcaster pass,
I moved the 2 subshaders out of the Category thingy, and placed the CGINCLUDE part in those 2 subshader’s CGPROGRAM part.

And somehow that causes the shadowcaster pass to work.


Sigh

Still no idea what #pragma surface does not allow specifying other programs” means though.