## Anisotropic shader (for brushed metals and others)

Compiling, libraries, modules, coding guidelines and porting

Moderators: jesterKing, stiv

lordloki
Posts: 2
Joined: Thu Oct 17, 2002 12:36 am

### Anisotropic shader (for brushed metals and others)

Hi all

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;
}
``````
The problem is that I don't know how calculate the dPdu vector, being dPdu the derivate of the point to shading in the direction U (U is a texture coordinate).

Can somebody help me?

This shader is based in this paper:
http://www.cs.utah.edu/~michael/brdfs/simple.pdf

Regards
Jorge

Marty_D
Posts: 0
Joined: Mon Jun 09, 2003 11:16 pm
Try subscribing to Bf-committers and posting. http://projects.blender.org/pipermail/bf-committers/ The hardcore coders seem to hang there. Keep tying. Anistropic shader would be awesome.

joeri
Posts: 96
Joined: Fri Jan 10, 2003 6:41 pm
Contact:
I was hoping you would get an answer here, since I'm telling everybody this is a developers forum.

Marty_D
Posts: 0
Joined: Mon Jun 09, 2003 11:16 pm
At least I didn't get spanked.

Hello? Anyone?

There's another shader project getting discussed over at Elysiun with diffuse surface. I don't remember anyone mentioning anistropic quality though so keep it up.

lukep
Posts: 0
Joined: Sun Apr 04, 2004 1:39 pm

BTW in less than one month we has an istotropic plastic one, a velvet style, and then anisotropic, funny

matt_e
Posts: 410
Joined: Mon Oct 14, 2002 4:32 am
Location: Sydney, Australia
Contact:
Well if I'm not mistaken, all three shaders are being developed by jorge (lordloki) himself, so it's not that much of a coincidence

I can't help with the original question, but I really hope someone see this, who can. An anisotropic shader would be awesome!

halibut
Posts: 0
Joined: Fri Apr 25, 2003 2:02 pm
Contact:
This is really brilliant work, I can't help you with your original question, but I can't wait till this thing is released

Where can I find the plastic one?