BasicBlinnPhong.shader
1.29 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
Shader "I_Jemin/BasicBlinnPhong" {
Properties {
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_NormalMap("Noraml Map",2D) = "black" {}
_SpecularColor("Specular Color",Color) = (1,1,1,1)
}
SubShader {
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf BasicBlinn fullforwardshadows
sampler2D _MainTex;
sampler2D _NormalMap;
fixed4 _SpecularColor;
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 LightingBasicBlinn(SurfaceOutput s, float3 lightDir, float3 viewDir, float atten)
{
// Lambert
float diffuseBrightness = saturate(dot(s.Normal, lightDir));
fixed3 lambertColor = diffuseBrightness * s.Albedo;
// Blinn Phong Specular
float3 halfVec = normalize(lightDir + viewDir);
float specularBrightness = saturate(dot(s.Normal, halfVec));
specularBrightness = pow(specularBrightness, 48);
fixed4 specularColor = specularBrightness * _SpecularColor;
// final output
fixed4 c;
c.rgb = (lambertColor + specularColor) * _LightColor0.rgb * atten;
c.a = s.Alpha;
return c;
}
ENDCG
}
FallBack "Diffuse"
}