PDA

View Full Version : RSL: Cook Torrence question


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

Creepfree
08-25-2010, 06:22 AM
Hey.
Looks like a weird shader to me...(shader declaration-"color",there is no such type in RMS,variables' "externs"-it's not neccessary,etc.)Anyway,getting back to your question, fresnel function does take I and N.From the RMS docs:

"void fresnel( vector I, N; float eta, output float Kr, Kt [; output vector R, T] )"
As far as i know,C-T shading model is the most accurate BRDF "representative"
,while staying the most computationally intensive.Here is a paper regarding different
BRDF implementations:

http://portal.acm.org/citation.cfm?id=1186336&coll=ACM&dl=ACM&CFID=32988670&CFTOKEN=46757267

ndeboar
08-25-2010, 06:27 AM
Thanks CreepFree

It's just a function, not a shader, hence it's called as a color That's also why it makes calls using extern, you need to use them in functions.

You could in theory pass anything to fresnel, but what I want to know is why they are passing L, it makes no sense to me. I just want to see if they have made a mistake, or they know something I don't.

I also dont have access to the acm library.

Per-Anders
08-25-2010, 06:44 AM
Without looking too closely, yes the cook torrence fresnel parameter is indeed meant to be eye/normal.

As for "best", that depends best at what? It's a simulation of a microfaceted surface, so it's a reasonable approximation of the reflectance on a very specific set of surfaces. It's not the most physically correct, like all specular models it's a cheat for speed, it's good enough if you're not looking for photorealism.

ndeboar
08-25-2010, 07:18 AM
Cheers Per-Anders!

re "best shader": Thanks pretty well the answer i was expecting (i use the term "best" in a "good all round" sense).

Right, back to coding.

Nick

CGTalk Moderation
08-25-2010, 07:18 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.