--- ray/src/rt/m_mist.c 1995/12/17 11:51:47 2.4 +++ ray/src/rt/m_mist.c 2003/02/22 02:07:28 2.10 @@ -1,13 +1,67 @@ -/* Copyright (c) 1995 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: m_mist.c,v 2.10 2003/02/22 02:07:28 greg Exp $"; #endif - /* * Mist volumetric material. */ +/* ==================================================================== + * 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 "ray.h" #include "source.h" @@ -33,23 +87,24 @@ static char SCCSid[] = "$SunId$ LBL"; * * Up to five real arguments may be given for MAT_MIST: * - * [ext_r ext_g ext_b [albedo [gecc]]] + * [ext_r ext_g ext_b [albedo_r albedo_g albedo_b [gecc]]] * * The primaries indicate medium extinction per unit length (absorption - * plus scattering). The albedo is the ratio of scattering to extinction, + * plus scattering), which is added to the global extinction coefficient, set + * by the -me option. The albedo is the ratio of scattering to extinction, * and is set globally by the -ma option (salbedo) and overridden here. * The Heyney-Greenstein eccentricity parameter (-mg seccg) indicates how much * scattering favors the forward direction. A value of 0 means isotropic * scattering. A value approaching 1 indicates strong forward scattering. */ +#ifndef MAXSLIST +#define MAXSLIST 32 /* maximum sources to check */ +#endif + #define RELAYDELIM '>' /* relay delimiter character */ -extern COLOR cextinction; /* global coefficient of extinction */ -extern double salbedo; /* global scattering albedo */ -extern double seccg; /* global scattering eccentricity */ - static int inslist(sl, n) /* return index of source n if it's in list sl */ register int *sl; @@ -86,7 +141,7 @@ register char *id; } -static +static void add2slist(r, sl) /* add source list to ray's */ register RAY *r; register int *sl; @@ -101,12 +156,14 @@ register int *sl; for (i = sl[0]; i > 0; i--) if (!inslist(r->slights, sl[i])) { if (r->slights[0] >= MAXSLIST) - error(USER, "scattering source list overflow"); + error(INTERNAL, + "scattering source list overflow"); r->slights[++r->slights[0]] = sl[i]; } } +int m_mist(m, r) /* process a ray entering or leaving some mist */ OBJREC *m; register RAY *r; @@ -118,12 +175,12 @@ register RAY *r; double re, ge, be; register int i, j; /* check arguments */ - if (m->oargs.nfargs > 5) + if (m->oargs.nfargs > 7) objerror(m, USER, "bad arguments"); /* get source indices */ if (m->oargs.nsargs > 0 && (myslist = (int *)m->os) == NULL) { if (m->oargs.nsargs > MAXSLIST) - objerror(m, USER, "too many sources in list"); + objerror(m, INTERNAL, "too many sources in list"); myslist = (int *)malloc((m->oargs.nsargs+1)*sizeof(int)); if (myslist == NULL) goto memerr; @@ -165,10 +222,11 @@ register RAY *r; p.slights[0] = 0; if (r->rod > 0.) { /* entering ray */ addcolor(p.cext, mext); - if (m->oargs.nfargs > 3) - p.albedo = m->oargs.farg[3]; - if (m->oargs.nfargs > 4) - p.gecc = m->oargs.farg[4]; + if (m->oargs.nfargs > 5) + setcolor(p.albedo, m->oargs.farg[3], + m->oargs.farg[4], m->oargs.farg[5]); + if (m->oargs.nfargs > 6) + p.gecc = m->oargs.farg[6]; add2slist(&p, myslist); /* add to list */ } else { /* leaving ray */ if (myslist != NULL) { /* delete from list */ @@ -180,23 +238,28 @@ register RAY *r; p.slights[++i] = p.slights[j]; if (p.slights[0] - i < myslist[0]) { /* fix old */ addcolor(r->cext, mext); - if (m->oargs.nfargs > 3) - r->albedo = m->oargs.farg[3]; - if (m->oargs.nfargs > 4) - r->gecc = m->oargs.farg[4]; + if (m->oargs.nfargs > 5) + setcolor(r->albedo, m->oargs.farg[3], + m->oargs.farg[4], m->oargs.farg[5]); + if (m->oargs.nfargs > 6) + r->gecc = m->oargs.farg[6]; add2slist(r, myslist); } p.slights[0] = i; } - re = colval(r->cext,RED) - colval(mext,RED); - ge = colval(r->cext,GRN) - colval(mext,GRN); - be = colval(r->cext,BLU) - colval(mext,BLU); - setcolor(p.cext, re<0. ? 0. : re, - ge<0. ? 0. : ge, - be<0. ? 0. : be); - if (m->oargs.nfargs > 3) - p.albedo = salbedo; - if (m->oargs.nfargs > 4) + if ((re = colval(r->cext,RED) - colval(mext,RED)) < + colval(cextinction,RED)) + re = colval(cextinction,RED); + if ((ge = colval(r->cext,GRN) - colval(mext,GRN)) < + colval(cextinction,GRN)) + ge = colval(cextinction,GRN); + if ((be = colval(r->cext,BLU) - colval(mext,BLU)) < + colval(cextinction,BLU)) + be = colval(cextinction,BLU); + setcolor(p.cext, re, ge, be); + if (m->oargs.nfargs > 5) + copycolor(p.albedo, salbedo); + if (m->oargs.nfargs > 6) p.gecc = seccg; } rayvalue(&p); /* calls rayparticipate() */