Hi everyone,
Long time reading, first time posting, blablabla…
I try to make a shader that is invisible when not lit directly by any light source. I almost have something but now I have reach my limit of understanding.
Shader "Custom/RevealAlpha" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
_MainTex("MainTex", 2D) = "white" {}
_lerper ("lerper", range (0,1)) = 0
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
_Ramp("Shading Ramp", 2d) = "white"{}
}
SubShader {
Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
LOD 300
CGPROGRAM
#pragma surface surf CustomDiffuse alphatest:_Cutoff
#include "UnityCG.cginc"
#include "Autolight.cginc"
sampler2D _MainTex;
fixed4 _Color;
half _lerper;
sampler2D _Ramp;
half4 LightingCustomDiffuse(SurfaceOutput s, half3 lightDir,half atten){
half NdotL =dot(s.Normal, lightDir);
half diff = NdotL * 0.5 + 0.5;
half3 ramp = tex2D(_Ramp, float2(diff)).rgb;
half4 c;
c.rgb = s.Albedo * _LightColor0.rgb * (step(_lerper,ramp) * atten * 2);
c.a = s.Alpha;
return c;
}
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
fixed4 lum = (_LightColor0 * _lerper);
lum = step (0.2, lum);
o.Albedo =tex.rgb * _Color.rgb * lum.rgb * 2 ;
o.Alpha = lum.r * 10;
}
ENDCG
}
Fallback "Transparent/Cutout/VertexLit"
}
And this is the result:
I use a ramp and a custom lighting model because it was the only way to make the transition sharper.Witch is driving me insane because I specifically use Alpha Test.
I also multiply the Albedo by 2 to make it more visible. Yes the Albedo and not the Alpha were the “*10” has no effect.
The problem for me come from “_LightColor0”, but it’s also my key element here.(The documentation is quite light on the subject.)
So, since now I don’t know what i’m doing anymore. I will be grateful if someone can tell me what I’m doing wrong.
Thank in advance. ![]()
