Shader as Follows:
Shader"Custom/diffuse Fragment-level"{Properties {_diffuse ("Diffuse", Color) = (1,1,1,1)} subshader {Tags {"Rendertype"="Opaque"} LOD -Pass {Tags {"Lightmode"="Forwardbase"}//only the correct lightmode is set to access some of the built-in variables that unity provides, such as: _lightcolor0Cgprogram#pragmaVertex vert#pragmaFragment Frag#include"Unitycg.cginc"#include"Lighting.cginc" structAppData {float4 vertex:position; FLOAT3 normal:normal; }; structv2f {float4 vertex:sv_position; FLOAT3 worldnormal:normal; }; FLOAT4 _diffuse; v2f vert (appdata v) {v2f o; O.vertex=Unityobjecttoclippos (v.vertex); FLOAT3 WN=mul (v.normal, (float3x3) _world2object); O.worldnormal=Normalize (wn); returno; } fixed4 frag (v2f i): sv_target {float3 lightdir=Normalize (_worldspacelightpos0); FLOAT4 Diffusecolor= _diffuse * _LIGHTCOLOR0 * MAX (0, Dot (lightdir, i.worldnormal)); returnUnity_lightmodel_ambient +diffusecolor; } endcg}} Fallback"Diffuse"}
The effect is as Follows:
Reprint Please specify source: http://www.cnblogs.com/jietian331/p/7079005.html
Per-pixel illumination can be updated to smooth the lighting effect, but there is a disadvantage, in the area where the illumination cannot reach, the appearance of the model is usually all black, without any light and shade changes, like a plane, without any model details, such AS.
To this end, there is an improved technique: the Semi-lambert (half Lambert) illumination model .
Unity shader Learning by pixel diffuse light model