Joe alter had a post on the Renderman forum regarding calculating lights with his wonderful hair product. Shave and a Haircut. For those of you who want to know how to do an illuminance loop over each strand here is my modified code:
by the way it's not tested but from looking at it should work.
/*
Shave and a Haircut emulation shader (c) 2007 Joe Alter, Inc
by Joe Alter
Global Illumination loop modification by Bernard Edlington
*/
surface be_shave (float Ka = 0, SHAVEambdiff = .6, SHAVEspec = .35, SHAVEgloss = .07,SHAVEopacity = 1.0,SHAVEselfshad=1;
color SHAVEspec_color=1,rootcolor=1,tipcolor=1;)
{
normal pxslUtilShadingNormal(normal n;){
normal Ns = normalize(n);
extern vector I;
uniform float sides = 2;
uniform float raydepth;
attribute("Sides", sides);
rayinfo("depth", raydepth);
if (sides == 2 || raydepth > 0)Ns = faceforward(Ns, I, Ns);
return Ns;
}
normal Ns = pxslUtilShadingNormal(N);
float occl = 0;
color indiff = 0;
vector T = normalize (dPdv); /* tangent along length of hair */
vector V = -normalize(I); /* V is the view vector */
float df2 = 0,diffterm=0;
color Cspec = 0, Cdiff = 0; /* collect specular & diffuse light */
color mixed=1;
float rawspec;
color Cl2;
float vt;
float tl;
float nondiff = 0;
lightsource("__nondiffuse", nondiff);
illuminance ("environment", P, Ns, 1.57,
"lightcache", "refresh",
"send:light:__surfacearea", -10,
"send:light:__coneangle", 1.57,
"send:light:__coneaxis", Ns,
"light:__nondiffuse", nondiff,
"light:_indirectdiffuse", indiff,
"light:_occlusion", occl){
float sq2;
df2=(T.normalize(L));
df2*=df2;
df2=1.0-df2;
if (df2<0) df2="0;">0)
df2=sqrt(df2);
diffterm=df2; /* diffuse */
if (diffterm<0) diffterm="0;" vt =" V.T" sq2="1.0-vt*vt;" sq2="0;">0)
sq2=sqrt(sq2);
rawspec = df2* sqrt( 1.0- vt * vt ) - (normalize(L). T ) * vt; /* raw specular */
if (rawspec<0) rawspec=0;
diffterm=(1.0-SHAVEambdiff)+diffterm*SHAVEambdiff; /* limits gamut of diffuse term */
Cl2=Cl*SHAVEselfshad+(1-SHAVEselfshad); /* limits the gamut of shadowing */
Cspec += Cl2*pow( rawspec, 1.0 / ( 3.0 * ( .101 - SHAVEgloss ) ) )*.5; /* specular exponent x illumination */
Cdiff += Cl2*diffterm; /* diffuse x illumination */
}
mixed = mix( rootcolor, tipcolor, v );
Oi = Os*SHAVEopacity;
Ci = Oi * Cs * mixed* (Ka*ambient() + Cdiff) + ( Cspec * SHAVEspec_color *SHAVEspec); /*sum terms and premult color x opac */
}
Post a Comment