--- ray/src/rt/glass.c 2010/09/26 15:51:15 2.18 +++ ray/src/rt/glass.c 2014/01/25 18:27:39 2.21 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: glass.c,v 2.18 2010/09/26 15:51:15 greg Exp $"; +static const char RCSid[] = "$Id: glass.c,v 2.21 2014/01/25 18:27:39 greg Exp $"; #endif /* * glass.c - simpler shading function for thin glass surfaces. @@ -50,7 +50,7 @@ m_glass( /* color a ray which hit a thin glass surfac COLOR mcolor; double pdot; FVECT pnorm; - double rindex, cos2; + double rindex=0, cos2; COLOR trans, refl; int hastexture, hastrans; double d, r1e, r1m; @@ -65,6 +65,11 @@ m_glass( /* color a ray which hit a thin glass surfac rindex = m->oargs.farg[3]; /* use their value */ else objerror(m, USER, "bad arguments"); + /* check back face visibility */ + if (!backvis && r->rod <= 0.0) { + raytrans(r); + return(1); + } /* check transmission */ setcolor(mcolor, m->oargs.farg[0], m->oargs.farg[1], m->oargs.farg[2]); if ((hastrans = (intens(mcolor) > 1e-15))) { @@ -112,9 +117,7 @@ m_glass( /* color a ray which hit a thin glass surfac /* transmitted ray */ if (rayorigin(&p, TRANS, r, trans) == 0) { if (!(r->crtype & SHADOW) && hastexture) { - for (i = 0; i < 3; i++) /* perturb direction */ - p.rdir[i] = r->rdir[i] + - 2.*(1.-rindex)*r->pert[i]; + VSUM(p.rdir, r->rdir, r->pert, 2.*(1.-rindex)); if (normalize(p.rdir) == 0.0) { objerror(m, WARNING, "bad perturbation"); VCOPY(p.rdir, r->rdir); @@ -143,8 +146,7 @@ m_glass( /* color a ray which hit a thin glass surfac } /* reflected ray */ if (rayorigin(&p, REFLECTED, r, refl) == 0) { - for (i = 0; i < 3; i++) - p.rdir[i] = r->rdir[i] + 2.0*pdot*pnorm[i]; + VSUM(p.rdir, r->rdir, pnorm, 2.*pdot); checknorm(p.rdir); rayvalue(&p); multcolor(p.rcol, p.rcoef);