--- ray/src/rt/glass.c 1989/02/02 10:41:24 1.1 +++ ray/src/rt/glass.c 1991/06/13 13:58:20 1.9 @@ -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"; @@ -50,6 +50,7 @@ register RAY *r; double cos2; COLOR trans, refl; double d, r1; + 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); @@ -80,13 +82,23 @@ register RAY *r; colval(trans,i) = (1.0-r1)*(1.0-r1)*d / (1.0 - r1*r1*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 (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 */ @@ -96,11 +108,13 @@ register RAY *r; colval(refl,i) = r1 * (1.0 + (1.0-2.0*r1)*d) / (1.0 - r1*r1*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; }