Hello everyone, I tried to make a modified toon shader for glow-in-the-dark items. It shows emissions according to _Illum texture in the darkness, but with lights on it’s supposed to show only basic texture without any emission.
Here is the shader. In surf function it saves emission to Custom field, and in lighting function this Custom field is used for calculating emission for unlit object. Then lerp function chooses which one to use: lit with lights without emission (c.rgb), or unlit with emission (d.rgb). For weak lights it lerps somewhere in between.
Everything works fine as described above with directional light (images #1 & #2). But I can’t understand why it doesn’t work with point lights (image #3). No matter what I do, emission never disappears with point lights, even if they are at 2X intensity and placed on very item. The texture becomes almost pure white, but emission still doesn’t disappear…
I hope somebody can help me with this.
Shader "Custom/Illuminated" {
Properties {
_Color ("Main Color", Color) = (0.5,0.5,0.5,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_Illum ("Illumin (A)", 2D) = "white" {}
_IllumPower ("Illum Power", Float) = 1
}
SubShader {
Tags {"RenderType"="Opaque"}
LOD 200
Lighting On
//Cull off
CGPROGRAM
#pragma surface surf ToonRamp fullforwardshadows
#pragma lighting ToonRamp exclude_path:prepass
sampler2D _MainTex;
sampler2D _Illum;
float4 _Color;
half _IllumPower;
half4 Custom;
struct EditorSurfaceOutput {
half3 Albedo;
half3 Normal;
half3 Emission;
half3 Gloss;
half Specular;
half Alpha;
half3 Custom;
};
inline half4 LightingToonRamp (EditorSurfaceOutput s, half3 lightDir, half atten)
{
#ifndef USING_DIRECTIONAL_LIGHT
lightDir = normalize(lightDir);
#endif
half4 d;
d.rgb = s.Custom*s.Albedo * _IllumPower;
half4 c;
c.rgb = s.Albedo * _LightColor0.rgb * (atten*2);
float intens = saturate(_LightColor0*5);
c.rgb = lerp(d.rgb, c.rgb, intens);
return c;
}
struct Input {
float2 uv_MainTex : TEXCOORD0;
float2 uv_Illum;
};
void surf (Input IN, inout EditorSurfaceOutput o) {
half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Custom = tex2D(_Illum, IN.uv_Illum).a;
o.Emission = 0.0;;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
Fallback "Diffuse"
}