00001 #ifndef blinn_h
00002 #define blinn_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 void
00018 blinnSpecularAOV( color specularColor; normal Nf;
00019 float eccentricity, specularRollOff, reflectivity;
00020 output color o_SpecularDirect;
00021 output color o_SpecularDirectShadow;
00022 )
00023 {
00024 float E;
00025 vector H, Ln, V, Nn;
00026 float NH, NH2, NHSQ, Dd, Gg, VN, VH, LN, Ff, tmp;
00027 float nondiff, nonspec;
00028 color ks;
00029 color inshadow, Cl_noshd, Cl_diff;
00030 extern point P;
00031 extern vector L, I;
00032 extern color Cl;
00033
00034 if(eccentricity != 1)
00035 E = 1 / (eccentricity * eccentricity - 1);
00036 else
00037 E = -1e5;
00038 V = normalize(-I);
00039 VN = V.Nf;
00040 illuminance("-environment", P, Nf, 1.57079632679)
00041 {
00042 if( 0 == lightsource("__nonspecular", nonspec) )
00043 nonspec = 0;
00044 if( nonspec < 1 )
00045 {
00046 Ln = normalize(L);
00047 H = normalize(Ln+V);
00048 NH = Nf.H;
00049 NHSQ = NH*NH;
00050 NH2 = NH * 2;
00051 Dd = (E+1) / (NHSQ + E);
00052 Dd *= Dd;
00053 VH = V.H;
00054 LN = Ln.Nf;
00055 if( VN < LN )
00056 {
00057 if( VN * NH2 < VH )
00058 Gg = NH2 / VH;
00059 else
00060 Gg = 1 / VN;
00061 }
00062 else
00063 {
00064 if( LN * NH2 < VH )
00065 Gg = (LN * NH2) / (VH * VN);
00066 else
00067 Gg = 1 / VN;
00068 }
00069
00070 tmp = pow((1 - VH), 3);
00071 Ff = tmp + (1 - tmp) * specularRollOff;
00072 ks = Dd * Gg * Ff * specularColor;
00073
00074 if( 0 == lightsource("_cl_noshadow", Cl_noshd) )
00075 Cl_noshd = Cl;
00076 Cl_diff = Cl_noshd - Cl;
00077 o_SpecularDirect += ks * Cl_noshd;
00078 o_SpecularDirectShadow += ks * Cl_diff;
00079 }
00080 }
00081 }
00082
00083 #endif