--- ray/src/rt/dielectric.c 2004/03/30 16:13:01 2.18 +++ ray/src/rt/dielectric.c 2005/04/19 01:15:06 2.20 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: dielectric.c,v 2.18 2004/03/30 16:13:01 schorsch Exp $"; +static const char RCSid[] = "$Id: dielectric.c,v 2.20 2005/04/19 01:15:06 greg Exp $"; #endif /* * dielectric.c - shading function for transparent materials. @@ -74,6 +74,9 @@ m_dielectric( /* color a ray which hit a dielectric in COLOR ctrans; COLOR talb; int hastexture; + double transdist, transtest=0; + double mirdist, mirtest=0; + int flatsurface; double refl, trans; FVECT dnorm; double d1, d2; @@ -91,6 +94,8 @@ m_dielectric( /* color a ray which hit a dielectric in VCOPY(dnorm, r->ron); cos1 = r->rod; } + flatsurface = !hastexture && r->ro != NULL && isflat(r->ro->otype); + /* index of refraction */ if (m->otype == MAT_DIELECTRIC) nratio = m->oargs.farg[3] + m->oargs.farg[4]/MLAMBDA; @@ -159,8 +164,10 @@ m_dielectric( /* color a ray which hit a dielectric in trans *= nratio*nratio; /* solid angle ratio */ - if (rayorigin(&p, r, REFRACTED, trans) == 0) { + setcolor(p.rcoef, trans, trans, trans); + if (rayorigin(&p, REFRACTED, r, p.rcoef) == 0) { + /* compute refracted ray */ d1 = nratio*cos1 - cos2; for (i = 0; i < 3; i++) @@ -187,16 +194,22 @@ m_dielectric( /* color a ray which hit a dielectric in copycolor(p.cext, ctrans); copycolor(p.albedo, talb); rayvalue(&p); - scalecolor(p.rcol, trans); + multcolor(p.rcol, p.rcoef); addcolor(r->rcol, p.rcol); - if (nratio >= 1.0-FTINY && nratio <= 1.0+FTINY) - r->rt = r->rot + p.rt; + /* virtual distance */ + if (flatsurface || + (1.-FTINY <= nratio && + nratio <= 1.+FTINY)) { + transtest = 2*bright(p.rcol); + transdist = r->rot + p.rt; + } } } } - + setcolor(p.rcoef, refl, refl, refl); + if (!(r->crtype & SHADOW) && - rayorigin(&p, r, REFLECTED, refl) == 0) { + rayorigin(&p, REFLECTED, r, p.rcoef) == 0) { /* compute reflected ray */ for (i = 0; i < 3; i++) @@ -208,9 +221,20 @@ m_dielectric( /* color a ray which hit a dielectric in rayvalue(&p); /* reflected ray value */ - scalecolor(p.rcol, refl); /* color contribution */ + multcolor(p.rcol, p.rcoef); /* color contribution */ addcolor(r->rcol, p.rcol); + /* virtual distance */ + if (flatsurface) { + mirtest = 2*bright(p.rcol); + mirdist = r->rot + p.rt; + } } + /* check distance to return */ + d1 = bright(r->rcol); + if (transtest > d1) + r->rt = transdist; + else if (mirtest > d1) + r->rt = mirdist; /* rayvalue() computes absorption */ return(1); } @@ -228,7 +252,8 @@ disperse( /* check light sources for dispersion */ COLOR abt ) { - RAY sray, *entray; + RAY sray; + const RAY *entray; FVECT v1, v2, n1, n2; FVECT dv, v2Xdv; double v2Xdvv2Xdv;