ToonBlinnRamp.shader
1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
Shader "I_Jemin/ToonBlinnRamp" {
Properties {
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_NormalMap("Normal Map",2D) = "black" {}
_RampTex ("RampTexture",2D) = "black" {}
_OutlineThreshold("Outline Threshold",Range(0,1)) = 0.2
_SpecularPower("Specular Power",Range(0,10)) = 3
}
SubShader {
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf ToonBlinn noambient
sampler2D _MainTex;
sampler2D _NormalMap;
sampler2D _RampTex;
float _OutlineThreshold;
float _SpecularPower;
struct Input {
float2 uv_MainTex;
float2 uv_NormalMap;
};
void surf (Input IN, inout SurfaceOutput o) {
o.Normal = UnpackNormal(tex2D(_NormalMap, IN.uv_NormalMap));
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
fixed4 LightingToonBlinn(SurfaceOutput s, float3 lightDir,float3 viewDir, float atten)
{
//Lambert
float diffuseBrightness = dot(s.Normal,lightDir);
diffuseBrightness = saturate(diffuseBrightness);
//Half-Lambert
diffuseBrightness = diffuseBrightness * 0.5 + 0.5;
fixed3 rampColor = tex2D(_RampTex, float2(diffuseBrightness, 0.5));
fixed3 diffuseLight = rampColor * s.Albedo;
//Blinn-Phong Specular
float3 halfVec = normalize(viewDir + lightDir);
float specBrightness = dot(halfVec,s.Normal);
specBrightness = saturate(specBrightness);
specBrightness = pow(specBrightness,10 - _SpecularPower);
fixed3 specLight = tex2D(_RampTex,float2(0,specBrightness));
// Draw outlint by rim
float rimBrightness = dot(s.Normal,viewDir);
rimBrightness = abs(rimBrightness);
if(rimBrightness < _OutlineThreshold)
{
rimBrightness = 0;
}
else
{
rimBrightness = 1;
}
// final output
fixed4 c;
// don't draw atten for toony effect
c.rgb = (diffuseLight + specLight) * _LightColor0 * rimBrightness;
c.a = s.Alpha;
return c;
}
ENDCG
}
FallBack "Diffuse"
}