Unity shader Learning by pixel diffuse light model

Source: Internet
Author: User

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

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.