ndeboar
08-25-2010, 01:20 AM
Hey,
I'm just working on a shader that uses Cook Torrence for it's specular component, and I have a question.
Here's the shader I'm basing my implementation on (from odforce):
color LocIllumCookTorrance(normal N; vector V;
float Ks, Kd, eta, roughness;
color Cdiff, Cspec;)
{
extern point P;
color Ct = 0;
float m2= roughness*roughness;
//First normalize every vector
vector Vn = normalize(V);
vector Nn = faceforward(normalize(N), -V);
illuminance ( P, Nn, PI/2 ) {
extern vector L;
vector Ln = normalize (L);
vector Hn = normalize (Vn + Ln);
//Cook-Torrance parmeters
float t = Hn.Nn;
float t2 = t*t; //t squared
float v = Vn.Nn;
float vp= Ln.Nn;
float u = Hn.Vn;
//2
//Now BRDF
float D = 0.5/(m2*t2*t2) * exp( (t2-1)/(m2*t2) );
float G = min(1 , 2*min(t*v/u, t*vp/u) );
float Kr, Kt;
fresnel(Ln, Nn, eta, Kr, Kt);
Ct += Cl * ( Cdiff*Kd + Cspec*Ks*Kr*D*G/(vp*v) ) * Nn.Ln;
}
return Ct;
}
Now, what I don't understand is why Fresnel takes L and not I. Surly Fresnel is always based on the viewer, not the light angle?
Also, is cook-tor still considered the "best" specular model?
Cheers!
Nick D
I'm just working on a shader that uses Cook Torrence for it's specular component, and I have a question.
Here's the shader I'm basing my implementation on (from odforce):
color LocIllumCookTorrance(normal N; vector V;
float Ks, Kd, eta, roughness;
color Cdiff, Cspec;)
{
extern point P;
color Ct = 0;
float m2= roughness*roughness;
//First normalize every vector
vector Vn = normalize(V);
vector Nn = faceforward(normalize(N), -V);
illuminance ( P, Nn, PI/2 ) {
extern vector L;
vector Ln = normalize (L);
vector Hn = normalize (Vn + Ln);
//Cook-Torrance parmeters
float t = Hn.Nn;
float t2 = t*t; //t squared
float v = Vn.Nn;
float vp= Ln.Nn;
float u = Hn.Vn;
//2
//Now BRDF
float D = 0.5/(m2*t2*t2) * exp( (t2-1)/(m2*t2) );
float G = min(1 , 2*min(t*v/u, t*vp/u) );
float Kr, Kt;
fresnel(Ln, Nn, eta, Kr, Kt);
Ct += Cl * ( Cdiff*Kd + Cspec*Ks*Kr*D*G/(vp*v) ) * Nn.Ln;
}
return Ct;
}
Now, what I don't understand is why Fresnel takes L and not I. Surly Fresnel is always based on the viewer, not the light angle?
Also, is cook-tor still considered the "best" specular model?
Cheers!
Nick D
