Abnormal Light Direction

I was following along with the Unite 08 shader video tutorial (or doing my best to) and tried to take the Cg based basic diffused shader and apply a point light rather than a directional light. It works fine with a directional light, but when I apply a point it begins acting strange as I move the light around the object.

Shader "Experimental/Cel" {

	Properties {
		_Color ("Main Color", Color) = (1,1,1,1)
		_MainTex ("Base (RGB)", 2D) = "white" {}
	}
	
	SubShader {
		Pass {
			
			CGPROGRAM
			#pragma vertex vert
			#include "UnityCG.cginc"
			
			float4 _Color;

			struct v2f {
				float4 position : POSITION;
				float4 color : COLOR;
			};

			v2f vert (appdata_base i){
				v2f o;
				o.position = mul( glstate.matrix.mvp, i.vertex );
				float3 n = mul( glstate.matrix.invtrans.modelview[0], float4( i.normal, 1) );
				float LdotN = saturate( dot( normalize( glstate.light[0].position ), n ) );
				o.color = glstate.lightmodel.ambient * _Color;	// ambient light
				o.color += LdotN * _Color;						// diffused light
				return o;
			}
			
			ENDCG
			
		}
	} 
}

In the image below I have two spheres: the one on the left using my shader and the one on the right using Default-Diffuse.

Ok, I am trying this from scratch, this time comparing my previous code which creates this crazy angle of diffusion to the code in the NVIDIA Cg tutorial:
http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter05.html

Shader "Experimental/BasicTest" {

	Properties {
		_Color ("Main Color", Color) = (1,1,1,1)
		_MainTex ("Base (RGB)", 2D) = "white" {}
	}
	
	SubShader {
		Pass {
			
			CGPROGRAM
			#pragma vertex vert
			#include "UnityCG.cginc"
			
			float4 _Color;

			struct v2f {
				float4 position : POSITION;
				float4 color : COLOR;
			};

			v2f vert (appdata_base i){
				v2f o;
				
				// set position
				o.position = mul( glstate.matrix.mvp, i.vertex );
				
				float3 P = i.vertex.xyz;
				float3 N = i.normal;
				
				// compute emissive value
				// compute ambient value
				
				// compute diffuse value
				float3 L = normalize(glstate.light[0].position.xyz - P);
				float diffuseLight = max(dot(N,L),0);
				float4 diffuse = glstate.light[0].color * diffuseLight;
				o.color = diffuse;
				
				return o;
			}
			
			ENDCG
			
		}
	} 
}

The problem I’m running into now is that I’m getting a REALLY weird error that says:

"Cg in program 'vert': error C1010: expression left of ."color" is not a struct or array at line 38".

Though clearly, o is an instance of v2f, which OBVIOUSLY is a struct as I am defining it RIGHT before the vertex function! I have been pulling my hair out over this for days now. Please somebody shed some light.[/code]

instead of going through the nvidia cg stuff I would have recommended to first go through the builtin shaders which you can download from the resources page. will give you an idea of how they work and where your initial one might go wrong (potentially just a matter of coordinate systems local - global)

I have, but the issue is digging through the include files to actually find the calculations that do the magic I need to learn about. The DiffuseLight call I’ve been looking for is in UnityCG.cginc, so I’ll have to look at this closer tomorrow to see if it can resolve my issues.