--- ray/src/rt/glass.c 1990/05/30 19:57:01 1.4 +++ ray/src/rt/glass.c 1991/05/08 08:27:46 1.7 @@ -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,8 +49,8 @@ register RAY *r; FVECT pnorm; double cos2; COLOR trans, refl; - double transbright; double d, r1; + double transtest, transdist; RAY p; register int i; @@ -61,6 +61,8 @@ register RAY *r; if (r->rod < 0.0) /* reorient if necessary */ flipsurface(r); + r->rt = r->rot; /* default ray length */ + transtest = 0; /* get modifiers */ raytexture(r, m->omod); pdot = raynormal(pnorm, r); @@ -80,16 +82,20 @@ register RAY *r; d = colval(mcolor, i); colval(trans,i) = (1.0-r1)*(1.0-r1)*d / (1.0 - r1*r1*d*d); } - transbright = -FTINY; /* transmitted ray */ if (rayorigin(&p, r, TRANS, bright(trans)) == 0) { - VCOPY(p.rdir, r->rdir); + 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 + transtest = 2; rayvalue(&p); multcolor(p.rcol, r->pcol); /* modify */ multcolor(p.rcol, trans); addcolor(r->rcol, p.rcol); - transbright = bright(p.rcol); - r->rt = r->rot + p.rt; + transtest *= bright(p.rcol); + transdist = r->rot + p.rt; } if (r->crtype & SHADOW) /* skip reflected ray */ @@ -107,7 +113,7 @@ register RAY *r; rayvalue(&p); multcolor(p.rcol, refl); addcolor(r->rcol, p.rcol); - if (bright(p.rcol) > transbright) - r->rt = r->rot + p.rt; } + if (transtest > bright(r->rcol)) + r->rt = transdist; }