I am implementing a material anisotropic to blender and, of course, I have some problems.
This is the code that I have done until now :
Code: Select all
/* Phong anisotropic spec */
float AnisoPhong_Spec( float *n, float *l, float *v, float fresnel_mir, float epsilon, float Nu, float Nv)
{
float i, nh, nv, nl, hl, h[3],hproj[3], dPdu[3],ang, fresnel, exp;
/* half-way vector */
h[0] = l[0] + v[0];
h[1] = l[1] + v[1];
h[2] = l[2] + v[2];
Normalise(h);
nh = n[0]*h[0]+n[1]*h[1]+n[2]*h[2]; /* Dot product between surface normal and half-way vector */
if(nh<0.0) nh = 0.0;
nv = n[0]*v[0]+n[1]*v[1]+n[2]*v[2]; /* Dot product between surface normal and view vector */
if(nv<=0.0) nv = 0.001;
nl = n[0]*l[0]+n[1]*l[1]+n[2]*l[2]; /* Dot product between surface normal and light vector */
if(nl<=0.0) nl = 0.001;
hl = h[0]*l[0]+h[1]*l[1]+h[2]*l[2]; /* Dot product between half-way vector and light vector */
if(hl<=0.0) hl = 0.001;
/* half-way vector surface projection */
hproj[0] = h[0] - (nh * n[0]);
hproj[1] = h[1] - (nh * n[1]);
hproj[2] = h[2] - (nh * n[2]);
Normalise(hproj);
/* dPdu vector */
dPdu = 0;
dPdu = -1;
dPdu = 0;
Normalise(dPdu);
/* Calculate angle between dPdu vector and half-way vector surface projection */
epsilon = (hproj[0]*dPdu[0] + hproj[1]*dPdu[1] + hproj[2]*dPdu[2]) / (sqrt(pow(hproj[0],2)+pow(hproj[1],2)+pow(hproj[2],2)) * sqrt(pow(dPdu[0],2)+pow(dPdu[1],2)+pow(dPdu[2],2)));
exp = (Nu * (cos (epsilon)) * (cos (epsilon))) + (Nv * (sin (epsilon)) * (sin (epsilon))) / (1 - pow(nh,2));
fresnel = fresnel_mir + ((1 - fresnel_mir) * pow((1 - hl), 5));
i = (sqrt((Nu+1)*(Nv+1))/(8*PI)) * (pow(nh, exp)/(hl*MAX2(nl,nv))) * fresnel;
return i;
}
Can somebody help me?
This shader is based in this paper:
http://www.cs.utah.edu/~michael/brdfs/simple.pdf
Thanks in advance
Regards
Jorge