- Home /
Transparency from light shader
I am currently trying to write a shader which makes an object completely invisible unless it has light. Essentially imagine a plain diffuse shader, except instead of approaching black as there is less light, the result approaches invisible.
Could anyone assist me with this?
Answer by Klaus-Eiperle · Jun 04, 2014 at 01:11 PM
Hi,
You are looking for this:
Shader "Custom/CGM-LightShader" {
Properties {
_SpecColor ("Specular Color", Color) = (0.25,0.25,0.25,0)
_Color ("Main Color", Color) = (0.5,0.5,0.5,1)
_Shininess ("Shininess", Range (0.01, 1)) = 0.5
}
SubShader {
Tags {
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
}
LOD 300
CGPROGRAM
#pragma surface surf BlinnPhong decal:add nolightmap
half _Shininess;
float4 _Color;
struct Input {
float4 color : COLOR;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = _Color;
o.Albedo = c.rgb * _SpecColor.a;
o.Gloss = c.rgb;
o.Specular = c.rgb * _Shininess;
o.Alpha = 0;
}
ENDCG
}
FallBack "Transparent/VertexLit"
}
Wow. Was honestly expecting either no reply for such a question, or some links to random unity docs.
This is brilliant, thankyou so much.
Quick question though, is there any way you know to get this to work with black lights as well?
Your answer
Follow this Question
Related Questions
GrabPass and Transparent geometry 0 Answers
How to make my shader have a variable transparency 1 Answer
Receiving Shadows On a Tranparent Shader 1 Answer
ex2D shader fix 1 Answer
Toon Lighted Alpha 1 Answer