--- ray/src/rt/dielectric.c 1996/04/17 14:01:52 2.11 +++ ray/src/rt/dielectric.c 2003/07/27 22:12:03 2.17 @@ -1,15 +1,12 @@ -/* Copyright (c) 1986 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: dielectric.c,v 2.17 2003/07/27 22:12:03 schorsch Exp $"; #endif - /* * dielectric.c - shading function for transparent materials. - * - * 9/6/85 */ +#include "copyright.h" + #include "ray.h" #include "otypes.h" @@ -50,10 +47,7 @@ static int lambda(); #define MINCOS 0.997 /* minimum dot product for dispersion */ -extern COLOR cextinction; /* global coefficient of extinction */ -extern COLOR salbedo; /* global scattering albedo */ - static double mylog(x) /* special log for extinction coefficients */ double x; @@ -73,7 +67,7 @@ register RAY *r; double cos1, cos2, nratio; COLOR ctrans; COLOR talb; - double mabsorp; + int hastexture; double refl, trans; FVECT dnorm; double d1, d2; @@ -85,7 +79,12 @@ register RAY *r; raytexture(r, m->omod); /* get modifiers */ - cos1 = raynormal(dnorm, r); /* cosine of theta1 */ + if ( (hastexture = DOT(r->pert,r->pert) > FTINY*FTINY) ) + cos1 = raynormal(dnorm, r); /* perturb normal */ + else { + VCOPY(dnorm, r->ron); + cos1 = r->rod; + } /* index of refraction */ if (m->otype == MAT_DIELECTRIC) nratio = m->oargs.farg[3] + m->oargs.farg[4]/MLAMBDA; @@ -93,6 +92,7 @@ register RAY *r; nratio = m->oargs.farg[3] / m->oargs.farg[7]; if (cos1 < 0.0) { /* inside */ + hastexture = -hastexture; cos1 = -cos1; dnorm[0] = -dnorm[0]; dnorm[1] = -dnorm[1]; @@ -128,7 +128,6 @@ register RAY *r; r->gecc = 0.; } } - mabsorp = exp(-bright(r->cext)*r->rot); /* approximate */ d2 = 1.0 - nratio*nratio*(1.0 - cos1*cos1); /* compute cos theta2 */ @@ -152,20 +151,31 @@ register RAY *r; refl *= 0.5; trans = 1.0 - refl; - if (rayorigin(&p, r, REFRACTED, mabsorp*trans) == 0) { + trans *= nratio*nratio; /* solid angle ratio */ + if (rayorigin(&p, r, REFRACTED, trans) == 0) { + /* compute refracted ray */ d1 = nratio*cos1 - cos2; for (i = 0; i < 3; i++) p.rdir[i] = nratio*r->rdir[i] + d1*dnorm[i]; - + /* accidental reflection? */ + if (hastexture && + DOT(p.rdir,r->ron)*hastexture >= -FTINY) { + d1 *= (double)hastexture; + for (i = 0; i < 3; i++) /* ignore texture */ + p.rdir[i] = nratio*r->rdir[i] + + d1*r->ron[i]; + normalize(p.rdir); /* not exact */ + } #ifdef DISPERSE if (m->otype != MAT_DIELECTRIC || r->rod > 0.0 || r->crtype & SHADOW || !directvis || m->oargs.farg[4] == 0.0 - || !disperse(m, r, p.rdir, trans)) + || !disperse(m, r, p.rdir, + trans, ctrans, talb)) #endif { copycolor(p.cext, ctrans); @@ -180,11 +190,15 @@ register RAY *r; } if (!(r->crtype & SHADOW) && - rayorigin(&p, r, REFLECTED, mabsorp*refl) == 0) { + rayorigin(&p, r, REFLECTED, refl) == 0) { /* compute reflected ray */ for (i = 0; i < 3; i++) p.rdir[i] = r->rdir[i] + 2.0*cos1*dnorm[i]; + /* accidental penetration? */ + if (hastexture && DOT(p.rdir,r->ron)*hastexture <= FTINY) + for (i = 0; i < 3; i++) /* ignore texture */ + p.rdir[i] = r->rdir[i] + 2.0*r->rod*r->ron[i]; rayvalue(&p); /* reflected ray value */ @@ -199,11 +213,12 @@ register RAY *r; #ifdef DISPERSE static -disperse(m, r, vt, tr) /* check light sources for dispersion */ +disperse(m, r, vt, tr, cet, abt) /* check light sources for dispersion */ OBJREC *m; RAY *r; FVECT vt; double tr; +COLOR cet, abt; { RAY sray, *entray; FVECT v1, v2, n1, n2; @@ -289,6 +304,8 @@ double tr; if (l1 > MAXLAMBDA || l1 < MINLAMBDA) /* not visible */ continue; /* trace source ray */ + copycolor(sray.cext, cet); + copycolor(sray.albedo, abt); normalize(sray.rdir); rayvalue(&sray); if (bright(sray.rcol) <= FTINY) /* missed it */