--- ray/src/rt/virtuals.c 1994/12/20 20:18:43 2.3 +++ ray/src/rt/virtuals.c 2003/02/22 02:07:29 2.7 @@ -1,18 +1,72 @@ -/* Copyright (c) 1994 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: virtuals.c,v 2.7 2003/02/22 02:07:29 greg Exp $"; #endif - /* * Routines for simulating virtual light sources * Thus far, we only support planar mirrors. + * + * External symbols declared in source.h */ +/* ==================================================================== + * 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 "octree.h" - #include "otypes.h" #include "source.h" @@ -23,12 +77,11 @@ static char SCCSid[] = "$SunId$ LBL"; #define STESTMAX 32 /* maximum seeks per sample */ -double getdisk(); - static OBJECT *vobject; /* virtual source objects */ static int nvobjects = 0; /* number of virtual source objects */ +void markvirtuals() /* find and mark virtual sources */ { register OBJREC *o; @@ -66,11 +119,12 @@ markvirtuals() /* find and mark virtual sources */ for (i = nsources; i-- > 0; ) addvirtuals(i, directrelay); /* done with our object list */ - free((char *)vobject); + free((void *)vobject); nvobjects = 0; } +void addvirtuals(sn, nr) /* add virtuals associated with source */ int sn; int nr; @@ -88,6 +142,7 @@ int nr; } +void vproject(o, sn, n) /* create projected source(s) if they exist */ OBJREC *o; int sn; @@ -126,7 +181,7 @@ OBJREC *o; m = objptr(i); if (m->otype != MAT_ILLUM || m->oargs.nsargs < 1 || !strcmp(m->oargs.sarg[0], VOIDID) || - (i = modifier(m->oargs.sarg[0])) == OVOID) + (i = lastmod(objndx(m), m->oargs.sarg[0])) == OVOID) return(m); /* direct modifier */ return(objptr(i)); /* illum alternate */ } @@ -157,7 +212,7 @@ MAT4 pm; normalize(nsloc); VCOPY(ourspot.aim, ocent); ourspot.siz = PI*maxrad2; - ourspot.flen = 0.; + ourspot.flen = -1.; if (source[sn].sflags & SSPOT) { multp3(theirspot.aim, source[sn].sl.s->aim, pm); /* adjust for source size */ @@ -301,7 +356,6 @@ register int sn; /* target source number */ FVECT offsdir; SRCINDEX si; double or, d; - int infront; int stestlim, ssn; int nhit, nok; register int i, n; @@ -314,7 +368,6 @@ register int sn; /* target source number */ if (source[sn].sflags & SDISTANT) { /* 32. == heuristic constant */ n = 32.*or2/(thescene.cusize*thescene.cusize)*vspretest + .5; - infront = DOT(onorm, source[sn].sloc) > 0.; } else { for (i = 0; i < 3; i++) offsdir[i] = source[sn].sloc[i] - oc[i]; @@ -323,7 +376,6 @@ register int sn; /* target source number */ n = 2.*PI * vspretest + .5; else n = 2.*PI * (1.-sqrt(1./(1.+or2/d)))*vspretest + .5; - infront = DOT(onorm, offsdir) > 0.; } if (n < MINSAMPLES) n = MINSAMPLES; #ifdef DEBUG @@ -335,6 +387,7 @@ register int sn; /* target source number */ stestlim = n*STESTMAX; ssn = 0; nhit = nok = 0; + initsrcindex(&si); while (n-- > 0) { /* get sample point */ do { @@ -348,35 +401,29 @@ register int sn; /* target source number */ for (i = 0; i < 3; i++) offsdir[i] = or*(1. - 2.*offsdir[i]); ssn++; - for (i = 0; i < 3; i++) - sr.rorg[i] = oc[i] + offsdir[i]; - d = DOT(offsdir,onorm); + d = 1. - DOT(offsdir, onorm); + for (i = 0; i < 3; i++) { + sr.rorg[i] = oc[i] + offsdir[i] + d*onorm[i]; + sr.rdir[i] = -onorm[i]; + } sr.rmax = 0.0; - if (infront) - for (i = 0; i < 3; i++) { - sr.rorg[i] -= (d-.0001)*onorm[i]; - sr.rdir[i] = -onorm[i]; - } - else - for (i = 0; i < 3; i++) { - sr.rorg[i] -= (d+.0001)*onorm[i]; - sr.rdir[i] = onorm[i]; - } rayorigin(&sr, NULL, PRIMARY, 1.0); } while (!(*ofun[o->otype].funp)(o, &sr)); /* check against source */ - initsrcindex(&si); - si.sn = sn; - nopart(&si, &sr); + VCOPY(sr.rorg, sr.rop); /* starting from intersection */ samplendx++; - if (!srcray(&sr, NULL, &si) || sr.rsrc != sn) - continue; + if (si.sp >= si.np-1 || + !srcray(&sr, NULL, &si) || sr.rsrc != sn) { + si.sn = sn-1; /* reset index to our source */ + si.np = 0; + if (!srcray(&sr, NULL, &si) || sr.rsrc != sn) + continue; /* can't get there from here */ + } sr.revf = srcvalue; - rayvalue(&sr); + rayvalue(&sr); /* check sample validity */ if (bright(sr.rcol) <= FTINY) continue; - nok++; - /* check against obstructions */ + nok++; /* got sample; check obstructions */ rayclear(&sr); sr.revf = raytrace; rayvalue(&sr); @@ -403,6 +450,7 @@ register int sn; /* target source number */ #ifdef DEBUG +void virtverb(sn, fp) /* print verbose description of virtual source */ register int sn; FILE *fp;