--- ray/src/rt/dielectric.c 1998/06/17 12:53:07 2.13 +++ ray/src/rt/dielectric.c 2003/02/22 02:07:28 2.15 @@ -1,13 +1,65 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: dielectric.c,v 2.15 2003/02/22 02:07:28 greg Exp $"; #endif - /* * dielectric.c - shading function for transparent materials. + */ + +/* ==================================================================== + * The Radiance Software License, Version 1.0 * - * 9/6/85 + * 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 "ray.h" @@ -50,10 +102,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,6 +122,7 @@ register RAY *r; double cos1, cos2, nratio; COLOR ctrans; COLOR talb; + int hastexture; double refl, trans; FVECT dnorm; double d1, d2; @@ -84,7 +134,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; @@ -92,6 +147,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]; @@ -150,13 +206,23 @@ register RAY *r; refl *= 0.5; trans = 1.0 - refl; + 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 @@ -184,6 +250,10 @@ register RAY *r; /* 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 */