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