Invisible object that reveals its texture in light

Hello,

I need help with creating a surface shader that reveals only the part of the _MainTex that is in the light of a certain colour. The rest of the surfaces will then be transparent, showing any objects behind it.

Due to the dynamic shadows that I will be using(shadows on the object will hide the texture as well), I tried to detect the light colour values in a custom lighting model (_PrePass) and then set the alpha accordingly. But I realised that for a surface to be rendered transparent, the surface output Alpha cant be set to 0 in the lighting model.

I’m not very good at shaders, this might not be possible at all. Is it possible to render a surface visibility based on light values? TIA.

And this is what I have so far…

Shader "Custom/Invisible Texture" 
{

	Properties 
	{
		_Color ("Main Color", Color) = (1,1,1,1)
		_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
		_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
		_LightCutoff ("Light cutoff", Range(0,1)) = 0.5
	}

	SubShader 
	{
		Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
		LOD 200
		
		CGPROGRAM
		#pragma surface surf CustomLight alphatest:_Cutoff
		
		sampler2D _MainTex;
		fixed4 _Color;
		half _LightCutoff;
		
		struct Input 
		{
			float2 uv_MainTex;
		};
		
		fixed4 LightingCustomLight_PrePass (SurfaceOutput s, half4 light)
		{
			fixed4 c;

			if (light.g > _LightCutoff)
			{
				// render pixel
				c.rgb = s.Albedo;
				c.a = 1;
			}
			else
			{
				// transparent
				c.rgb = s.Albedo;
				c.a = 0;
			}
						
			return c;
		}
		
		void surf(Input IN, inout SurfaceOutput o) 
		{
			fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
			o.Albedo = c.rgb;
			o.Alpha = c.a;
		}
		
		ENDCG
	}

//Fallback "Transparent/Cutout/VertexLit"
}

I posted something like this somewhere long ago, try to search for lights and camera match and shadows or somethin.

Cant seem to find that thread…

Help anyone?

Have you tried this?
http://forum.unity3d.com/threads/26639-Reveal-texture-only-when-light-falls-on-it

Yes, I did. Doesnt work for me, probably because its a vertex shader, not surface.

Did you try to make it a forward rendered shader and do alpha cutoff in the LightingCustomLight block instead of prepass one?