--- ray/src/rt/glass.c 1989/02/02 10:41:24 1.1 +++ ray/src/rt/glass.c 1991/10/29 16:30:46 1.11 @@ -1,4 +1,4 @@ -/* Copyright (c) 1986 Regents of the University of California */ +/* Copyright (c) 1991 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -49,7 +49,8 @@ register RAY *r; FVECT pnorm; double cos2; COLOR trans, refl; - double d, r1; + double d, r1e, r1m; + double transtest, transdist; RAY p; register int i; @@ -60,6 +61,7 @@ register RAY *r; if (r->rod < 0.0) /* reorient if necessary */ flipsurface(r); + transtest = 0; /* get modifiers */ raytexture(r, m->omod); pdot = raynormal(pnorm, r); @@ -71,36 +73,52 @@ register RAY *r; pow(colval(mcolor,BLU), 1.0/cos2)); /* compute reflection */ - r1 = (pdot - RINDEX*cos2) / (pdot + RINDEX*cos2); - d = (1.0/pdot - RINDEX/cos2) / (1.0/pdot + RINDEX/cos2); - r1 = (r1*r1 + d*d) / 2.0; + r1e = (pdot - RINDEX*cos2) / (pdot + RINDEX*cos2); + r1e *= r1e; + r1m = (1.0/pdot - RINDEX/cos2) / (1.0/pdot + RINDEX/cos2); + r1m *= r1m; /* compute transmittance */ for (i = 0; i < 3; i++) { d = colval(mcolor, i); - colval(trans,i) = (1.0-r1)*(1.0-r1)*d / (1.0 - r1*r1*d*d); + colval(trans,i) = .5*(1.0-r1e)*(1.0-r1e)*d/(1.0-r1e*r1e*d*d); + colval(trans,i) += .5*(1.0-r1m)*(1.0-r1m)*d/(1.0-r1m*r1m*d*d); } /* transmitted ray */ - if (rayorigin(&p, r, TRANS, intens(trans)) == 0) { - VCOPY(p.rdir, r->rdir); + if (rayorigin(&p, r, TRANS, bright(trans)) == 0) { + if (!(r->crtype & SHADOW) && + DOT(r->pert,r->pert) > FTINY*FTINY) { + for (i = 0; i < 3; i++) /* perturb direction */ + p.rdir[i] = r->rdir[i] - r->pert[i]/RINDEX; + normalize(p.rdir); + } else { + VCOPY(p.rdir, r->rdir); + transtest = 2; + } rayvalue(&p); multcolor(p.rcol, r->pcol); /* modify */ multcolor(p.rcol, trans); addcolor(r->rcol, p.rcol); + transtest *= bright(p.rcol); + transdist = r->rot + p.rt; } + if (r->crtype & SHADOW) /* skip reflected ray */ return; /* compute reflectance */ for (i = 0; i < 3; i++) { d = colval(mcolor, i); d *= d; - colval(refl,i) = r1 * (1.0 + (1.0-2.0*r1)*d) / (1.0 - r1*r1*d); + colval(refl,i) = .5*r1e*(1.0+(1.0-2.0*r1e)*d)/(1.0-r1e*r1e*d); + colval(refl,i) += .5*r1m*(1.0+(1.0-2.0*r1m)*d)/(1.0-r1m*r1m*d); } /* reflected ray */ - if (rayorigin(&p, r, REFLECTED, intens(refl)) == 0) { + if (rayorigin(&p, r, REFLECTED, bright(refl)) == 0) { for (i = 0; i < 3; i++) p.rdir[i] = r->rdir[i] + 2.0*pdot*pnorm[i]; rayvalue(&p); multcolor(p.rcol, refl); addcolor(r->rcol, p.rcol); } + if (transtest > bright(r->rcol)) + r->rt = transdist; }