This article starting address: HTTP://98JY.NET/ARTICLE/24
For more articles, please enter the portal
----------------------------------------------
The half Lambert illumination model was invented by valve in the production of "half-life" games to show objects in darker areas. In general, the light model improves the diffuse light on the surface of the object. Is Valve's example, the left hand side is the Lambert model, the right hand side is the half Lambert model.
Using our original base of shader, we changed the Lightingbasicdiffuse () method to the following:
Inline Float4 Lightingbasicdiffuse (surfaceoutput s, fixed3lightdir, fixed atten) {float diflight = dot (s.normal, Lightdir ) Float Hlambert = diflight * 0.5 + 0.5;float4 Col;col.rgb = S.albedo * _lightcolor0.rgb * (Hlambert * atten * 2); COL.A = S.alpha;return Col;}
After saving shader, we go back to unity.
If you do not make any changes to the objects in the scene, you can see that the overall performance of the object is now brighter than the original. The reason for this is that the code
float Hlambert = diflight * 0.5 + 0.5;
Diflight in the range because of the dot () method's relationship, in [0, 1] range, so that the range of Hlambert is in [0.5, 1]. This algorithm maps the range 0~1 to the range 0.5~1, and the whole increases the final value.
98 Education Original, reproduced please specify the source (98jy.net), otherwise considered infringement.
Unity Shader Tutorial-lesson Fifth: Customizing the half Lambert model of the lighting model