Unity Shader Tutorial-lesson Fifth: Customizing the half Lambert model of the lighting model

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.