_WorldSpaceLightPos0 Giving Inconsistent Results in Different Rendering Paths

I am developing a low poly shader to explore geometry shaders. Since geometry shaders are not currently supported in Surface Shaders I have had to write my own lighting. I began with diffuse lighting using _WorldSpaceLightPos0 to retrieve the current direction of my light (I’m using a directional light). I am getting inconsistent results. In forward and deferred rendering the result is similar (and incorrect). The _WorldSpaceLightPos0 variable switches between two different values depending on the position of my Main Camera. However, if I switch to the Legacy Vertex Lit render path my shader renders correctly.

How do I get consistent behavior using the _WorldSpaceLightPos0 variable? According to the Unity documentation this will contain the direction of the light (there is only a single, directional light in my scene). Why does this work perfectly in the Legacy Rendering path but fails in the up to date Forward and Deferred renderers?

When I modify my shader to draw the _WorldSpaceLightPos0 this is the result I get. Note how it switches between two colors as the camera moves in and out, this is the world space direction of the light changing. It only ever switches between these two values. Green is the correct light position, in legacy vertex lit rendering I only get that result:

Incorrect Light Direction in Shader

All of my lighting calculations are being done in world space inside the geometry shader using the following snippet from the shader.

float3 lightPosition = _WorldSpaceLightPos0;

float3 v0 = IN[0].pos.xyz;
float3 v1 = IN[1].pos.xyz;
float3 v2 = IN[2].pos.xyz;

float3 normal = normalize(cross(v0 - v1, v1 - v2));
float4 worldNormal = normalize(mul(unity_ObjectToWorld, normal));

float lightStrength = max(dot(normalize(lightPosition), worldNormal), 0);

Below is the complete shader for reference and reproduction of the issue. I’ve replaced the texture rendering with drawing the value of the lightPosition instead for debugging. This is the same code as I used to generate the attached gif. I am using Unity 5.5.1f1.

// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'

// Low Poly Shader developed as part of World of Zero, uses geometry shaders to build unique triangles.
// Based upon the example at: http://www.battlemaze.com/?p=153

Shader "World of Zero/Low Poly" {
	Properties{
		_Color("Color", Color) = (1,1,1,1)
		_MainTex("Albedo (RGB)", 2D) = "white" {}
		_Glossiness("Smoothness", Range(0,1)) = 0.5
		_Metallic("Metallic", Range(0,1)) = 0.0
	}
		SubShader{
			Tags { "RenderType" = "Opaque" }
			LOD 200

			Pass
		{

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

			// Use shader model 4.0 target, we need geometry shader support
			#pragma target 4.0

			sampler2D _MainTex;

			struct v2g
			{
				float4 pos : SV_POSITION;
				float3 norm : NORMAL;
				float2 uv : TEXCOORD0;
				float3 color : TEXCOORD1;
			};

			struct g2f
			{
				float4 pos : SV_POSITION;
				float3 norm : NORMAL;
				//float2 uv : TEXCOORD0;
				float3 diffuseColor : TEXCOORD1;
				//float3 specularColor : TEXCOORD2;
			};

			half _Glossiness;
			half _Metallic;
			fixed4 _Color;

			v2g vert(appdata_full v)
			{
				float3 v0 = v.vertex.xyz;

				v2g OUT;
				OUT.pos = v.vertex;
				OUT.norm = v.normal;
				OUT.uv = v.texcoord;
				OUT.color = tex2Dlod(_MainTex, v.texcoord).rgb;
				return OUT;
			}

			[maxvertexcount(3)]
			void geom(triangle v2g IN[3], inout TriangleStream<g2f> triStream)
			{
				float3 lightPosition = _WorldSpaceLightPos0;

				float3 v0 = IN[0].pos.xyz;
				float3 v1 = IN[1].pos.xyz;
				float3 v2 = IN[2].pos.xyz;

				float3 normal = normalize(cross(v0 - v1, v1 - v2));
				float4 worldNormal = normalize(mul(unity_ObjectToWorld, normal));

				float3 color = (IN[0].color + IN[1].color + IN[2].color) / 3;
				float lightStrength = max(dot(normalize(lightPosition), worldNormal), 0);

				g2f OUT;
				OUT.pos = mul(UNITY_MATRIX_MVP, IN[0].pos);
				OUT.norm = normal;
				OUT.diffuseColor = _WorldSpaceLightPos0;// color * lightStrength;
				triStream.Append(OUT);

				OUT.pos = mul(UNITY_MATRIX_MVP, IN[1].pos);
				OUT.norm = normal;
				OUT.diffuseColor = _WorldSpaceLightPos0;//color * lightStrength;
				triStream.Append(OUT);

				OUT.pos = mul(UNITY_MATRIX_MVP, IN[2].pos);
				OUT.norm = normal;
				OUT.diffuseColor = _WorldSpaceLightPos0;//color * lightStrength;
				triStream.Append(OUT);
			}

			half4 frag(g2f IN) : COLOR
			{
				return float4(IN.diffuseColor.rgb, 1.0);
			}
			ENDCG

		}
		}
}

A bit too late for you but i had the same issue and some other person might find this useful:

You need this tag in your pass: Tags{ “LightMode” = “ForwardBase” }

It’s important that it is placed in the Pass and not the SubShader.
I placed it in the SubShader section and spent like an hour debugging because i thought it wouldn’t make a difference. It does.