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"
}