--- ray/src/rt/dielectric.c 2003/02/22 02:07:28 2.15 +++ ray/src/rt/dielectric.c 2010/09/26 15:51:15 2.21 @@ -1,77 +1,25 @@ #ifndef lint -static const char RCSid[] = "$Id: dielectric.c,v 2.15 2003/02/22 02:07:28 greg Exp $"; +static const char RCSid[] = "$Id: dielectric.c,v 2.21 2010/09/26 15:51:15 greg Exp $"; #endif /* * dielectric.c - shading function for transparent materials. */ -/* ==================================================================== - * The Radiance Software License, Version 1.0 - * - * Copyright (c) 1990 - 2002 The Regents of the University of California, - * through Lawrence Berkeley National Laboratory. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes Radiance software - * (http://radsite.lbl.gov/) - * developed by the Lawrence Berkeley National Laboratory - * (http://www.lbl.gov/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Radiance," "Lawrence Berkeley National Laboratory" - * and "The Regents of the University of California" must - * not be used to endorse or promote products derived from this - * software without prior written permission. For written - * permission, please contact radiance@radsite.lbl.gov. - * - * 5. Products derived from this software may not be called "Radiance", - * nor may "Radiance" appear in their name, without prior written - * permission of Lawrence Berkeley National Laboratory. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of Lawrence Berkeley National Laboratory. For more - * information on Lawrence Berkeley National Laboratory, please see - * . - */ +#include "copyright.h" #include "ray.h" - #include "otypes.h" +#include "rtotypes.h" #ifdef DISPERSE #include "source.h" -static disperse(); -static int lambda(); +static int disperse(OBJREC *m,RAY *r,FVECT vt,double tr,COLOR cet,COLOR abt); +static int lambda(OBJREC *m, FVECT v2, FVECT dv, FVECT lr); #endif +static double mylog(double x); + + /* * Explicit calculations for Fresnel's equation are performed, * but only one square root computation is necessary. @@ -104,8 +52,9 @@ static int lambda(); static double -mylog(x) /* special log for extinction coefficients */ -double x; +mylog( /* special log for extinction coefficients */ + double x +) { if (x < 1e-40) return(-100.); @@ -115,14 +64,19 @@ double x; } -m_dielectric(m, r) /* color a ray which hit a dielectric interface */ -OBJREC *m; -register RAY *r; +extern int +m_dielectric( /* color a ray which hit a dielectric interface */ + OBJREC *m, + register RAY *r +) { double cos1, cos2, nratio; COLOR ctrans; COLOR talb; int hastexture; + double transdist, transtest=0; + double mirdist, mirtest=0; + int flatsurface; double refl, trans; FVECT dnorm; double d1, d2; @@ -134,12 +88,14 @@ register RAY *r; raytexture(r, m->omod); /* get modifiers */ - if (hastexture = DOT(r->pert,r->pert) > FTINY*FTINY) + if ( (hastexture = DOT(r->pert,r->pert) > FTINY*FTINY) ) cos1 = raynormal(dnorm, r); /* perturb normal */ else { 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; @@ -208,8 +164,10 @@ register RAY *r; 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++) @@ -222,7 +180,8 @@ register RAY *r; p.rdir[i] = nratio*r->rdir[i] + d1*r->ron[i]; normalize(p.rdir); /* not exact */ - } + } else + checknorm(p.rdir); #ifdef DISPERSE if (m->otype != MAT_DIELECTRIC || r->rod > 0.0 @@ -236,16 +195,22 @@ register RAY *r; 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++) @@ -254,12 +219,23 @@ register RAY *r; 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]; - + checknorm(p.rdir); 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); } @@ -267,15 +243,18 @@ register RAY *r; #ifdef DISPERSE -static -disperse(m, r, vt, tr, cet, abt) /* check light sources for dispersion */ -OBJREC *m; -RAY *r; -FVECT vt; -double tr; -COLOR cet, abt; +static int +disperse( /* check light sources for dispersion */ + OBJREC *m, + RAY *r, + FVECT vt, + double tr, + COLOR cet, + COLOR abt +) { - RAY sray, *entray; + RAY sray; + const RAY *entray; FVECT v1, v2, n1, n2; FVECT dv, v2Xdv; double v2Xdvv2Xdv; @@ -404,9 +383,12 @@ COLOR cet, abt; static int -lambda(m, v2, dv, lr) /* compute lambda for material */ -register OBJREC *m; -FVECT v2, dv, lr; +lambda( /* compute lambda for material */ + register OBJREC *m, + FVECT v2, + FVECT dv, + FVECT lr +) { FVECT lrXdv, v2Xlr; double dtmp, denom;