Diffuse (Lambert)
- Lum = C * max(0, cos(L, N))
- Lum: diffuse reflective brightness.
- C: diffuse reflective intensity (diffuse reflective color).
- L: direction of incident light.
- N: normal direction.
Transmitting mirror (Phong)
- Lum = C * pow(max(0, cos(R, V)), gloss)
- Lum: high brightness.
- C: high light intensity (highlight color).
- R: the direction of the reflected light.
- V: viewing direction.
- gloss: mirror smoothness.
Half-size vector (BlinnPhong)
- Lum = C * pow(max(0, cos(H, N)), gloss)
- Lum: high brightness.
- C: high light intensity (highlight color).
- H: half-size vector.
- N: normal direction.
- gloss: mirror smoothness.
Function illumination inside Unity
- Forward under diffuse lighting function:
inline fixed4 LightingLambert(SurfaceOutput s, fixed3 lightDir, fixed atten){
fixed diff = max(0, dot(s.Normal, lightDir));
fixed4 c;
c.rgb = s.Albedo * _LightColor0.rgb * (diff * atten * 2);
c.a = s.Alpha;
return c;
}
- Forward functions at high light:
inline fixed4 LightingBlinnPhong(SurfaceOutput s, fixed3 lightDir, half3 viewDir, fixed atten){
half3 h = normalize(lightDir + viewDir);
fixed diff = max(0, dot(s.Normal, lightDir));
float nh = max(0, dot(s.Normal, h));
float spec = pow(nh, s.Specular * 128.0) * s.Gloss;
fixed4 c;
c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * _SpecColor.rgb * spec) * (atten * 2);
c.a = s.Alpha + _LightColor0.a * _SpecColor.a * spec * atten;
return c;
}