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