Unity Shader:bank BRDF

Source: Internet
Author: User

Back BRDF is an empirical model for simulating anisotropic gloss on metal surfaces, with formulas referring to GPU programming and CG language Spring Snow lowbrow 120-page formula (10-14)

1Shader"CUSTOM/BANK-BRDF" {2 Properties {3_ambicolor ("Main Color", Color) = (1,1,1,1)4_ak ("Ambient Coef",float) =15_diffcolor ("Diff Color", Color) = (1,1,1,1)6_DK ("Diff Coef",float) =17_speccolor ("Spec Color", Color) = (1,1,1,1)8_sk ("Sk",float) =19_SP ("Sp", Range (0,5)) =1Ten     } One  A Subshader { - Pass { - Cgprogram the#include"Unitycg.cginc" -             #pragmaVertex vert -             #pragmaFragment Frag -  + float4 _ambicolor; -             float_ak; + float4 _diffcolor; A             float_DK; at float4 _speccolor; -             float_sk; -             float_sp; -  -             structv2f { - float4 pos:position; in FLOAT3 normal:texcoord0; - FLOAT3 Light:texcoord1; to FLOAT3 View:texcoord2; + FLOAT3 Targent:texcoord3; -             }; the  * v2f Vert (Appdata_base v) { $ v2f o;Panax NotoginsengO.pos =Mul (UNITY_MATRIX_MVP, V.vertex); -O.normal =V.normal; theO.light =Objspacelightdir (V.vertex); +O.view =Objspaceviewdir (V.vertex); AO.targent =Cross (V.normal, o.view); the  +                 returno; -             } $  $ float4 Frag (v2f i): COLOR { -Float3 L =normalize (i.light); -FLOAT3 T =normalize (i.targent); theFLOAT3 v =normalize (I.view); -FLOAT3 n =normalize (i.normal);Wuyi  the                 floatlt =dot (l, t); -                 floatVT =dot (v, t); Wu                 floatNL =dot (n, l); -                 floatNV =dot (n, v); About  $FLOAT4 Ambi = _ambicolor *_ak; -FLOAT4 diff = _dk * _diffcolor *saturate (NL); -  -                 if(NL <=0|| NV <=0) A                     returnAmbi +diff; +  the                 floatp = sqrt (1-LT * lt) * sqrt (1-VT * VT)-LT *VT; -                 floatf = _sk *Pow (P, _sp); $                 floatSpec = f * _speccolor *Saturate (dot (l, N)); the  the                 returnAmbi + diff +spec; the             } the ENDCG -         } in     }  theFallBack"Diffuse" the}

The effect is as follows:

Unity Shader:bank BRDF

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.