Unity Shader Getting Started Tutorial (iv) Realization of reflective spot

Source: Internet
Author: User
Tags pow

This section describes Phongmodel(that is, the calculated model of the reflected light above), the method of calculation is blinphong(that is , the direction of the v+ light source with the direction of Vision L and, with N doing dot product, then power to get specular reflectance coefficient) adopted csdn blog http://blog.csdn.net An illustration in the/u010133610/article/details/52206654.

Step 1.1 : Create new shader and material, as I said in the previous tutorial.

Step 1.2 : The code is as follows:

Code start Shader"custom/learn2"{Properties {_color ("Color", Color) = (1,1,1,1) _maintex ("Albedo (RGB)", 2D) =" White"{}} subshader {Tags {"Rendertype"="Opaque"} LOD $Cgprogram#pragmaSurface Surf Phongmodelsampler2d _maintex; structInput {float2 Uv_maintex;        };        Fixed4 _color; voidSurf (Input in, InOut surfaceoutput o) {fixed4 c= tex2d (_maintex, In.uv_maintex) *_color; O.albedo=C.rgb; O.alpha=C.A;            } inline Float4 Lightingphongmodel (surfaceoutput s, float3 Lightdir, Half3 viewdir, half atten) {                        Float4 Col; //The first is the diffuse reflectance coefficient, and the approximate degree (cosine) of the incident light as the coefficient            floatDiffusef = Max (0, Dot (s.normal, lightdir)); //h indicates the direction of the study point pointing to the light source (lightdir) + The direction of the research point pointing to the glasses (Viewdir), with the power of the approximate degree of H and the method as the specular reflectance coefficientFLOAT3 H = normalize (Lightdir +Viewdir); floatSpecbase = Max (0, Dot (s.normal, H)); floatSpecf= Pow (specbase, the); //Diffuse reflectance + specular highlight modelCol.rgb = S.albedo * _lightcolor0 * Diffusef * atten +_lightcolor0*SPECF; COL.A=S.alpha; returnCol; } ENDCG} FallBack"Diffuse"}

▲ End of code

Step 1.3 : Apply a texture and see the effect:

Some experiments are documented below:

the effect that corresponds to the following values when the preceding is modified:

Float specf= Pow (specbase, 1);

Float specf= Pow (specbase, 10);

Float specf= Pow (specbase, 100);

Float specf= Pow (specbase, 1000);

Float specf= Pow (specbase, 10000);

--Xiao Jiang cun son of Wen Jie [email protected] 7 months on the day 21:54:01

Unity Shader Getting Started Tutorial (iv) Realization of reflective spot

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.