Possibility to check all lights in one pass of a shader?

Hi everyone,

tl;dr: is there a way to check several lights during 1 pass of a shader? I would like to modify the effect of some specific lights depending on whether the pixel is lit by other lights or not.

The long explanation:
I am trying to create a surface shader for my 2D game. My shader already works very nicely with my sprites and normal maps. Additionally the game is in the night and I wanted the moonlight to lit the sprites without displaying their color (so everything is grey under the moonlight). I have put a 0 alpha on the moonlight and 255 on the other lights to be able differentiate them in the shader and it works very well. The colors appears only if a light which is not the moon is close to a sprite, otherwise it is lit only with grey/white.

Now my problem is the following: when a light (say a flame) is close to my sprite, I would like to hide the lighting coming from the moon. Right now if my sprite is between a flame and the moonlight, I have 1 side of the sprite with the colors visible and the other side lit by the moonlight so grayish. In real life the luminosity of the flame would prevent our eyes to see the moonlight reflection and this side would be black. This is the effect I want to recreate.

I could implement this effect easily if I could check whether the sprite is near a light which is not the moon in the shader. Then depending on how bright this light is I would attenuate the moonlight reflection. Unfortunately I can’t find a way to check the other lights while I am handling the moonlight.

Any ideas?

See my code below. The key part is around line 65.

Shader "Sprites/Sprite normal map"
{
	Properties
	{
		[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
		_BumpMap ("Normalmap", 2D) = "bump" {}
		[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
		_Cutoff ("Alpha Cutoff", Range (0,1)) = 0.5

	}

	SubShader
	{
		Tags
		{ 
			"Queue"="Transparent" 
			"IgnoreProjector"="True" 
			"RenderType"="TransparentCutOut" 
			"PreviewType"="Plane"
			"CanUseSpriteAtlas"="True"
		}
		LOD 300

		// Render front faces only
		Cull Back
		Lighting On
		ZWrite Off
		Fog { Mode Off }
		
		CGPROGRAM
		#pragma surface surf Lambert alpha vertex:vert addshadow alphatest:_Cutoff 
		#pragma multi_compile DUMMY PIXELSNAP_ON 

		sampler2D _MainTex;
		sampler2D _BumpMap;
		fixed4 _Color;
		float _ScaleX;

		struct Input
		{
			float2 uv_MainTex;
			float2 uv_BumpMap;
			fixed4 color : COLOR;
		};
		
		void vert (inout appdata_full v, out Input o)
		{
			#if defined(PIXELSNAP_ON) && !defined(SHADER_API_FLASH)
			v.vertex = UnityPixelSnap (v.vertex);
			#endif
			float3 normal = v.normal;
			
			v.normal = float3(0,0,1);
			v.tangent =  float4(1, 0, 0, 1);
			
			UNITY_INITIALIZE_OUTPUT(Input, o);
		}

		void surf (Input IN, inout SurfaceOutput o)
		{
			fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * IN.color;
			if (_LightColor0.a < 0.1f)
			{
				// Here I would like to test the other lights to know if I should attenuate _LightColor0
				o.Albedo = _LightColor0;	
			}
			else
			{
				o.Albedo = c.rgb;
			}
			
			o.Alpha = c.a;
			o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
			o.Normal.z *= -1;
		}
		ENDCG
	}

Fallback "Transparent/Cutout/Diffuse"
}

Using forward rendering, this can be done through blending.

http://docs.unity3d.com/Manual/SL-Blend.html