--- ray/src/rt/glass.c 2010/10/25 22:57:45 2.19 +++ ray/src/rt/glass.c 2014/05/10 17:43:01 2.22 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: glass.c,v 2.19 2010/10/25 22:57:45 greg Exp $"; +static const char RCSid[] = "$Id: glass.c,v 2.22 2014/05/10 17:43:01 greg Exp $"; #endif /* * glass.c - simpler shading function for thin glass surfaces. @@ -41,23 +41,23 @@ static const char RCSid[] = "$Id: glass.c,v 2.19 2010/ #define RINDEX 1.52 /* refractive index of glass */ -extern int +int m_glass( /* color a ray which hit a thin glass surface */ OBJREC *m, - register RAY *r + RAY *r ) { COLOR mcolor; double pdot; FVECT pnorm; - double rindex, cos2; + double rindex=0, cos2; COLOR trans, refl; int hastexture, hastrans; double d, r1e, r1m; double transtest, transdist; double mirtest, mirdist; RAY p; - register int i; + int i; /* check arguments */ if (m->oargs.nfargs == 3) rindex = RINDEX; /* default value of n */ @@ -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))) { @@ -111,7 +116,7 @@ m_glass( /* color a ray which hit a thin glass surfac multcolor(trans, r->pcol); /* modify by pattern */ /* transmitted ray */ if (rayorigin(&p, TRANS, r, trans) == 0) { - if (!(r->crtype & SHADOW) && hastexture) { + if (!(r->crtype & (SHADOW|AMBIENT)) && hastexture) { VSUM(p.rdir, r->rdir, r->pert, 2.*(1.-rindex)); if (normalize(p.rdir) == 0.0) { objerror(m, WARNING, "bad perturbation"); @@ -146,7 +151,8 @@ m_glass( /* color a ray which hit a thin glass surfac rayvalue(&p); multcolor(p.rcol, p.rcoef); addcolor(r->rcol, p.rcol); - if (!hastexture && r->ro != NULL && isflat(r->ro->otype)) { + if (r->ro != NULL && isflat(r->ro->otype) && + !hastexture | (r->crtype & AMBIENT)) { mirtest = 2.0*bright(p.rcol); mirdist = r->rot + p.rt; }