ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/virtuals.c
(Generate patch)

Comparing ray/src/rt/virtuals.c (file contents):
Revision 1.5 by greg, Thu Jun 20 17:08:39 1991 UTC vs.
Revision 2.25 by greg, Fri Feb 12 00:41:19 2021 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Routines for simulating virtual light sources
6   *      Thus far, we only support planar mirrors.
7 + *
8 + *  External symbols declared in source.h
9   */
10  
11 < #include  "ray.h"
11 > #include "copyright.h"
12  
13 + #include  "ray.h"
14   #include  "otypes.h"
15 <
15 > #include  "otspecial.h"
16   #include  "source.h"
17 + #include  "random.h"
18  
19 + #define  MINSAMPLES     16              /* minimum number of pretest samples */
20 + #define  STESTMAX       32              /* maximum seeks per sample */
21  
19 double  intercircle();
22  
23   static OBJECT  *vobject;                /* virtual source objects */
24   static int  nvobjects = 0;              /* number of virtual source objects */
25  
26  
27 < markvirtuals()                  /* find and mark virtual sources */
27 > static int
28 > isident4(MAT4 m)
29   {
30 <        register OBJREC  *o;
31 <        register int  i;
30 >        int     i, j;
31 >
32 >        for (i = 4; i--; )
33 >                for (j = 4; j--; )
34 >                        if (!FABSEQ(m[i][j], i==j))
35 >                                return(0);
36 >        return(1);
37 > }
38 >
39 >
40 > void
41 > markvirtuals(void)                      /* find and mark virtual sources */
42 > {
43 >        OBJREC  *o;
44 >        int  i;
45                                          /* check number of direct relays */
46          if (directrelay <= 0)
47                  return;
48                                          /* find virtual source objects */
49 <        for (i = 0; i < nobjects; i++) {
49 >        for (i = 0; i < nsceneobjs; i++) {
50                  o = objptr(i);
51                  if (!issurface(o->otype) || o->omod == OVOID)
52                          continue;
53 <                if (!isvlight(objptr(o->omod)->otype))
53 >                if (!isvlight(vsmaterial(o)->otype))
54                          continue;
55                  if (sfun[o->otype].of == NULL ||
56 <                                sfun[o->otype].of->getpleq == NULL)
57 <                        objerror(o, USER, "illegal material");
56 >                                sfun[o->otype].of->getpleq == NULL) {
57 >                        objerror(o,WARNING,"secondary sources not supported");
58 >                        continue;
59 >                }
60                  if (nvobjects == 0)
61                          vobject = (OBJECT *)malloc(sizeof(OBJECT));
62                  else
63 <                        vobject = (OBJECT *)realloc((char *)vobject,
63 >                        vobject = (OBJECT *)realloc((void *)vobject,
64                                  (unsigned)(nvobjects+1)*sizeof(OBJECT));
65                  if (vobject == NULL)
66                          error(SYSTEM, "out of memory in addvirtuals");
# Line 55 | Line 73 | markvirtuals()                 /* find and mark virtual sources */
73   #endif
74                                          /* append virtual sources */
75          for (i = nsources; i-- > 0; )
76 <                if (!(source[i].sflags & SSKIP))
59 <                        addvirtuals(i, directrelay);
76 >                addvirtuals(i, directrelay);
77                                          /* done with our object list */
78 <        free((char *)vobject);
78 >        free((void *)vobject);
79          nvobjects = 0;
80   }
81  
82  
83 < addvirtuals(sn, nr)             /* add virtuals associated with source */
84 < int  sn;
85 < int  nr;
83 > void
84 > addvirtuals(            /* add virtuals associated with source */
85 >        int  sn,
86 >        int  nr
87 > )
88   {
89 <        register int  i;
89 >        int  i;
90                                  /* check relay limit first */
91          if (nr <= 0)
92                  return;
93 +        if (source[sn].sflags & SSKIP)
94 +                return;
95                                  /* check each virtual object for projection */
96          for (i = 0; i < nvobjects; i++)
97                                          /* vproject() calls us recursively */
# Line 78 | Line 99 | int  nr;
99   }
100  
101  
102 < vproject(o, sn, n)              /* create projected source(s) if they exist */
103 < OBJREC  *o;
104 < int  sn;
105 < int  n;
102 > void
103 > vproject(               /* create projected source(s) if they exist */
104 >        OBJREC  *o,
105 >        int  sn,
106 >        int  n
107 > )
108   {
109 <        register int  i;
110 <        register VSMATERIAL  *vsmat;
109 >        int  i;
110 >        VSMATERIAL  *vsmat;
111          MAT4  proj;
112          int  ns;
113  
114          if (o == source[sn].so) /* objects cannot project themselves */
115                  return;
116                                  /* get virtual source material */
117 <        vsmat = sfun[objptr(o->omod)->otype].mf;
117 >        vsmat = sfun[vsmaterial(o)->otype].mf;
118                                  /* project virtual sources */
119          for (i = 0; i < vsmat->nproj; i++)
120                  if ((*vsmat->vproj)(proj, o, &source[sn], i))
121                          if ((ns = makevsrc(o, sn, proj)) >= 0) {
122 +                                source[ns].sa.sv.pn = i;
123   #ifdef DEBUG
124 <                                virtverb(&source[ns], stderr);
124 >                                virtverb(ns, stderr);
125   #endif
126                                  addvirtuals(ns, n);
127                          }
128   }
129  
130  
131 + OBJREC *
132 + vsmaterial(                     /* get virtual source material pointer */
133 +        OBJREC  *o
134 + )
135 + {
136 +        int  i;
137 +        OBJREC  *m;
138 +
139 +        i = o->omod;
140 +        m = findmaterial(o);
141 +        if (m == NULL)
142 +                return(objptr(i));
143 +        if (m->otype != MAT_ILLUM || m->oargs.nsargs < 1 ||
144 +                        !strcmp(m->oargs.sarg[0], VOIDID) ||
145 +                        (i = lastmod(objndx(m), m->oargs.sarg[0])) == OVOID)
146 +                return(m);              /* direct modifier */
147 +        return(objptr(i));              /* illum alternate */
148 + }
149 +
150 +
151   int
152 < makevsrc(op, sn, pm)            /* make virtual source if reasonable */
153 < OBJREC  *op;
154 < register int  sn;
155 < MAT4  pm;
152 > makevsrc(               /* make virtual source if reasonable */
153 >        OBJREC  *op,
154 >        int  sn,
155 >        MAT4  pm
156 > )
157   {
158 <        register int  nsn;
159 <        FVECT  nsloc, ocent, nsnorm;
158 >        FVECT  nsloc, nsnorm, ocent, v;
159 >        double  maxrad2, d;
160          int  nsflags;
116        double  maxrad2;
117        double  d1;
161          SPOT  theirspot, ourspot;
162 <        register int  i;
163 <
164 <        nsflags = (source[sn].sflags|(SVIRTUAL|SFOLLOW)) & ~SSPOT;
162 >        int  i;
163 >                                        /* check for no-op */
164 >        if (isident4(pm))
165 >                return(0);
166 >        nsflags = source[sn].sflags | (SVIRTUAL|SSPOT|SFOLLOW);
167                                          /* get object center and max. radius */
168 <        if (sfun[op->otype].of->getdisk != NULL) {
169 <                maxrad2 = (*sfun[op->otype].of->getdisk)(ocent, op);
170 <                if (maxrad2 <= FTINY)                   /* too small? */
126 <                        return(-1);
127 <                nsflags |= SSPOT;
128 <        }
168 >        maxrad2 = getdisk(ocent, op, sn);
169 >        if (maxrad2 <= FTINY)                   /* too small? */
170 >                return(-1);
171                                          /* get location and spot */
172          if (source[sn].sflags & SDISTANT) {             /* distant source */
173                  if (source[sn].sflags & SPROX)
174                          return(-1);             /* should never get here! */
175                  multv3(nsloc, source[sn].sloc, pm);
176 <                if (nsflags & SSPOT) {
177 <                        VCOPY(ourspot.aim, ocent);
178 <                        ourspot.siz = PI*maxrad2;
179 <                        ourspot.flen = 0.;
138 <                }
176 >                normalize(nsloc);
177 >                VCOPY(ourspot.aim, ocent);
178 >                ourspot.siz = PI*maxrad2;
179 >                ourspot.flen = -1.;
180                  if (source[sn].sflags & SSPOT) {
140                        copystruct(&theirspot, source[sn].sl.s);
181                          multp3(theirspot.aim, source[sn].sl.s->aim, pm);
182 <                        if (nsflags & SSPOT &&
183 <                                !commonbeam(&ourspot, &theirspot, nsloc))
184 <                                return(-1);             /* no overlap */
182 >                                                /* adjust for source size */
183 >                        d = sqrt(dist2(ourspot.aim, theirspot.aim));
184 >                        d = sqrt(source[sn].sl.s->siz/PI) + d*source[sn].srad;
185 >                        theirspot.siz = PI*d*d;
186 >                        ourspot.flen = theirspot.flen = source[sn].sl.s->flen;
187 >                        d = ourspot.siz;
188 >                        if (!commonbeam(&ourspot, &theirspot, nsloc))
189 >                                return(-1);     /* no overlap */
190 >                        if (ourspot.siz < d-FTINY) {    /* it shrunk */
191 >                                d = beamdisk(v, op, &ourspot, nsloc);
192 >                                if (d <= FTINY)
193 >                                        return(-1);
194 >                                if (d < maxrad2) {
195 >                                        maxrad2 = d;
196 >                                        VCOPY(ocent, v);
197 >                                }
198 >                        }
199                  }
200          } else {                                /* local source */
201                  multp3(nsloc, source[sn].sloc, pm);
202 <                if (nsflags & SSPOT) {
203 <                        for (i = 0; i < 3; i++)
204 <                                ourspot.aim[i] = ocent[i] - nsloc[i];
205 <                        if ((d1 = normalize(ourspot.aim)) == 0.)
206 <                                return(-1);             /* at source!! */
207 <                        if (source[sn].sflags & SPROX &&
208 <                                        d1 > source[sn].sl.prox)
209 <                                return(-1);             /* too far away */
210 <                        ourspot.siz = 2.*PI*(1. - d1/sqrt(d1*d1+maxrad2));
211 <                        ourspot.flen = 0.;
212 <                } else if (source[sn].sflags & SPROX) {
213 <                        FVECT  norm;
214 <                        double  offs;
161 <                                                /* use distance from plane */
162 <                        offs = (*sfun[op->otype].of->getpleq)(norm, op);
163 <                        d1 = DOT(norm, nsloc) - offs;
164 <                        if (d1 < 0.) d1 = -d1;
165 <                        if (d1 > source[sn].sl.prox)
166 <                                return(-1);             /* too far away */
167 <                }
202 >                for (i = 0; i < 3; i++)
203 >                        ourspot.aim[i] = ocent[i] - nsloc[i];
204 >                if ((d = normalize(ourspot.aim)) == 0.)
205 >                        return(-1);             /* at source!! */
206 >                if (source[sn].sflags & SPROX && d > source[sn].sl.prox)
207 >                        return(-1);             /* too far away */
208 >                ourspot.flen = 0.;
209 >                                                /* adjust for source size */
210 >                d = (sqrt(maxrad2) + source[sn].srad) / d;
211 >                if (d < 1.-FTINY)
212 >                        ourspot.siz = 2.*PI*(1. - sqrt(1.-d*d));
213 >                else
214 >                        nsflags &= ~SSPOT;
215                  if (source[sn].sflags & SSPOT) {
216 <                        copystruct(&theirspot, source[sn].sl.s);
216 >                        theirspot = *(source[sn].sl.s);
217                          multv3(theirspot.aim, source[sn].sl.s->aim, pm);
218 +                        normalize(theirspot.aim);
219                          if (nsflags & SSPOT) {
220 +                                ourspot.flen = theirspot.flen;
221 +                                d = ourspot.siz;
222                                  if (!commonspot(&ourspot, &theirspot, nsloc))
223                                          return(-1);     /* no overlap */
224 <                                ourspot.flen = theirspot.flen;
224 >                        } else {
225 >                                nsflags |= SSPOT;
226 >                                ourspot = theirspot;
227 >                                d = 2.*ourspot.siz;
228                          }
229 +                        if (ourspot.siz < d-FTINY) {    /* it shrunk */
230 +                                d = spotdisk(v, op, &ourspot, nsloc);
231 +                                if (d <= FTINY)
232 +                                        return(-1);
233 +                                if (d < maxrad2) {
234 +                                        maxrad2 = d;
235 +                                        VCOPY(ocent, v);
236 +                                }
237 +                        }
238                  }
239                  if (source[sn].sflags & SFLAT) {        /* behind source? */
240                          multv3(nsnorm, source[sn].snorm, pm);
241 <                        if (nsflags & SSPOT && checkspot(&ourspot, nsnorm) < 0)
241 >                        normalize(nsnorm);
242 >                        if (nsflags & SSPOT && !checkspot(&ourspot, nsnorm))
243                                  return(-1);
244                  }
245          }
246 <                                        /* everything is OK, make source */
247 <        if ((nsn = newsource()) < 0)
246 >                                        /* pretest visibility */
247 >        nsflags = vstestvis(nsflags, op, ocent, maxrad2, sn);
248 >        if (nsflags & SSKIP)
249 >                return(-1);     /* obstructed */
250 >                                        /* it all checks out, so make it */
251 >        if ((i = newsource()) < 0)
252                  goto memerr;
253 <        source[nsn].sflags = nsflags;
254 <        VCOPY(source[nsn].sloc, nsloc);
253 >        source[i].sflags = nsflags;
254 >        VCOPY(source[i].sloc, nsloc);
255 >        multv3(source[i].ss[SU], source[sn].ss[SU], pm);
256 >        multv3(source[i].ss[SV], source[sn].ss[SV], pm);
257          if (nsflags & SFLAT)
258 <                VCOPY(source[nsn].snorm, nsnorm);
259 <        source[nsn].ss = source[sn].ss; source[nsn].ss2 = source[sn].ss2;
260 <        if ((nsflags | source[sn].sflags) & SSPOT) {
261 <                if ((source[nsn].sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL)
258 >                VCOPY(source[i].snorm, nsnorm);
259 >        else
260 >                multv3(source[i].ss[SW], source[sn].ss[SW], pm);
261 >        source[i].srad = source[sn].srad;
262 >        source[i].ss2 = source[sn].ss2;
263 >        if (nsflags & SSPOT) {
264 >                if ((source[i].sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL)
265                          goto memerr;
266 <                if (nsflags & SSPOT)
195 <                        copystruct(source[nsn].sl.s, &ourspot);
196 <                else
197 <                        copystruct(source[nsn].sl.s, &theirspot);
198 <                source[nsn].sflags |= SSPOT;
266 >                *(source[i].sl.s) = ourspot;
267          }
268          if (nsflags & SPROX)
269 <                source[nsn].sl.prox = source[sn].sl.prox;
270 <        source[nsn].sa.svnext = sn;
271 <        source[nsn].so = op;
272 <        return(nsn);
269 >                source[i].sl.prox = source[sn].sl.prox;
270 >        source[i].sa.sv.sn = sn;
271 >        source[i].so = op;
272 >        return(i);
273   memerr:
274          error(SYSTEM, "out of memory in makevsrc");
275 +        return -1; /* pro forma return */
276   }
277  
278  
279 < commonspot(sp1, sp2, org)       /* set sp1 to intersection of sp1 and sp2 */
280 < register SPOT  *sp1, *sp2;
281 < FVECT  org;
279 > double
280 > getdisk(                /* get visible object disk */
281 >        FVECT  oc,
282 >        OBJREC  *op,
283 >        int  sn
284 > )
285   {
286 <        FVECT  cent;
287 <        double  rad2, cos1, cos2;
288 <
289 <        cos1 = 1. - sp1->siz/(2.*PI);
290 <        cos2 = 1. - sp2->siz/(2.*PI);
291 <        if (sp2->siz >= 2.*PI-FTINY)            /* BIG, just check overlap */
292 <                return(DOT(sp1->aim,sp2->aim) >= cos1*cos2 -
293 <                                        sqrt((1.-cos1*cos1)*(1.-cos2*cos2)));
294 <                                /* compute and check disks */
295 <        rad2 = intercircle(cent, sp1->aim, sp2->aim,
296 <                        1./(cos1*cos1) - 1.,  1./(cos2*cos2) - 1.);
297 <        if (rad2 <= FTINY || normalize(cent) == 0.)
298 <                return(0);
299 <        VCOPY(sp1->aim, cent);
300 <        sp1->siz = 2.*PI*(1. - 1./sqrt(1.+rad2));
301 <        return(1);
286 >        double  rad2, roffs, offs, d, rd, rdoto;
287 >        FVECT  rnrm, nrm;
288 >                                /* first, use object getdisk function */
289 >        rad2 = getmaxdisk(oc, op);
290 >        if (!(source[sn].sflags & SVIRTUAL))
291 >                return(rad2);           /* all done for normal source */
292 >                                /* check for correct side of relay surface */
293 >        roffs = getplaneq(rnrm, source[sn].so);
294 >        rd = DOT(rnrm, source[sn].sloc);        /* source projection */
295 >        if (!(source[sn].sflags & SDISTANT))
296 >                rd -= roffs;
297 >        d = DOT(rnrm, oc) - roffs;      /* disk distance to relay plane */
298 >        if ((d > 0.) ^ (rd > 0.))
299 >                return(rad2);           /* OK if opposite sides */
300 >        if (d*d >= rad2)
301 >                return(0.);             /* no relay is possible */
302 >                                /* we need a closer look */
303 >        offs = getplaneq(nrm, op);
304 >        rdoto = DOT(rnrm, nrm);
305 >        if (d*d >= rad2*(1.-rdoto*rdoto))
306 >                return(0.);             /* disk entirely on projection side */
307 >                                /* should shrink disk but I'm lazy */
308 >        return(rad2);
309   }
310  
311  
312 < commonbeam(sp1, sp2, dir)       /* set sp1 to intersection of sp1 and sp2 */
313 < register SPOT  *sp1, *sp2;
314 < FVECT  dir;
312 > int
313 > vstestvis(              /* pretest source visibility */
314 >        int  f,                 /* virtual source flags */
315 >        OBJREC  *o,             /* relay object */
316 >        FVECT  oc,              /* relay object center */
317 >        double  or2,            /* relay object radius squared */
318 >        int  sn /* target source number */
319 > )
320   {
321 <        FVECT  cent, c1, c2;
322 <        double  rad2, d;
323 <        register int  i;
324 <                                        /* move centers to common plane */
325 <        d = DOT(sp1->aim, dir);
326 <        for (i = 0; i < 3; i++)
327 <                c1[i] = sp1->aim[i] - d*dir[i];
328 <        d = DOT(sp2->aim, dir);
329 <        for (i = 0; i < 3; i++)
330 <                c2[i] = sp2->aim[i] - d*dir[i];
331 <                                        /* compute overlap */
332 <        rad2 = intercircle(cent, c1, c2, sp1->siz/PI, sp2->siz/PI);
333 <        if (rad2 <= FTINY)
334 <                return(0);
335 <        VCOPY(sp1->aim, cent);
336 <        sp1->siz = PI*rad2;
337 <        return(1);
254 < }
255 <
256 <
257 < checkspot(sp, nrm)              /* check spotlight for behind source */
258 < register SPOT  *sp;
259 < FVECT  nrm;
260 < {
261 <        double  d, d1;
262 <
263 <        d = DOT(sp->aim, nrm);
264 <        if (d > FTINY)                  /* center in front? */
265 <                return(0);
266 <                                        /* else check horizon */
267 <        d1 = 1. - sp->siz/(2.*PI);
268 <        return(1.-FTINY-d*d > d1*d1);
269 < }
270 <
271 <
272 < double
273 < intercircle(cc, c1, c2, r1s, r2s)       /* intersect two circles */
274 < FVECT  cc;                      /* midpoint (return value) */
275 < FVECT  c1, c2;                  /* circle centers */
276 < double  r1s, r2s;               /* radii squared */
277 < {
278 <        double  a2, d2, l;
279 <        FVECT  disp;
280 <        register int  i;
281 <
282 <        for (i = 0; i < 3; i++)
283 <                disp[i] = c2[i] - c1[i];
284 <        d2 = DOT(disp,disp);
285 <                                        /* circle within overlap? */
286 <        if (r1s < r2s) {
287 <                if (r2s >= r1s + d2) {
288 <                        VCOPY(cc, c1);
289 <                        return(r1s);
290 <                }
321 >        RAY  sr;
322 >        FVECT  onorm;
323 >        double  offsdir[3];
324 >        SRCINDEX  si;
325 >        double  or, d, d1;
326 >        int  stestlim, ssn;
327 >        int  nhit, nok;
328 >        int  i, n;
329 >                                /* return if pretesting disabled */
330 >        if (vspretest <= 0)
331 >                return(f);
332 >                                /* get surface normal */
333 >        getplaneq(onorm, o);
334 >                                /* set number of rays to sample */
335 >        if (source[sn].sflags & SDISTANT) {
336 >                                        /* 32. == heuristic constant */
337 >                n = 32.*or2/(thescene.cusize*thescene.cusize)*vspretest + .5;
338          } else {
339 <                if (r1s >= r2s + d2) {
340 <                        VCOPY(cc, c2);
341 <                        return(r2s);
339 >                VSUB(offsdir, source[sn].sloc, oc);
340 >                d = DOT(offsdir,offsdir);
341 >                if (d <= FTINY)
342 >                        n = 2.*PI * vspretest + .5;
343 >                else
344 >                        n = 2.*PI * (1.-sqrt(1./(1.+or2/d)))*vspretest + .5;
345 >        }
346 >        if (n < MINSAMPLES) n = MINSAMPLES;
347 > #ifdef DEBUG
348 >        fprintf(stderr, "pretesting source %d in object %s with %d rays\n",
349 >                        sn, o->oname, n);
350 > #endif
351 >                                /* sample */
352 >        or = sqrt(or2);
353 >        stestlim = n*STESTMAX;
354 >        ssn = 0;
355 >        nhit = nok = 0;
356 >        initsrcindex(&si);
357 >        while (n-- > 0) {
358 >                                        /* get sample point */
359 >                do {
360 >                        if (ssn >= stestlim) {
361 > #ifdef DEBUG
362 >                                fprintf(stderr, "\ttoo hard to hit\n");
363 > #endif
364 >                                return(f);      /* too small a target! */
365 >                        }
366 >                        multisamp(offsdir, 3, urand(sn*931+5827+ssn));
367 >                        for (i = 0; i < 3; i++)
368 >                                offsdir[i] = or*(1. - 2.*offsdir[i]);
369 >                        ssn++;
370 >                        d = 1. - DOT(offsdir, onorm);
371 >                        for (i = 0; i < 3; i++) {
372 >                                sr.rorg[i] = oc[i] + offsdir[i] + d*onorm[i];
373 >                                sr.rdir[i] = -onorm[i];
374 >                        }
375 >                        sr.rmax = 0.0;
376 >                        rayorigin(&sr, PRIMARY, NULL, NULL);
377 >                } while (!(*ofun[o->otype].funp)(o, &sr));
378 >                                        /* check against source */
379 >                VCOPY(sr.rorg, sr.rop); /* starting from intersection */
380 >                samplendx++;
381 >                if (si.sp >= si.np-1 ||
382 >                                !srcray(&sr, NULL, &si) || sr.rsrc != sn) {
383 >                        si.sn = sn-1;           /* reset index to our source */
384 >                        si.np = 0;
385 >                        if (!srcray(&sr, NULL, &si) || sr.rsrc != sn)
386 >                                continue;       /* can't get there from here */
387                  }
388 +                sr.revf = srcvalue;
389 +                rayvalue(&sr);                  /* check sample validity */
390 +                if ((d = bright(sr.rcol)) <= FTINY)
391 +                        continue;
392 +                nok++;                  /* got sample; check obstructions */
393 +                rayclear(&sr);
394 +                sr.revf = raytrace;
395 +                rayvalue(&sr);
396 +                if ((d1 = bright(sr.rcol)) > FTINY) {
397 +                        if (d - d1 > FTINY) {
398 + #ifdef DEBUG
399 +                                fprintf(stderr, "\tpartially shadowed\n");
400 + #endif
401 +                                return(f);      /* intervening transmitter */
402 +                        }
403 +                        nhit++;
404 +                }
405 +                if (nhit > 0 && nhit < nok) {
406 + #ifdef DEBUG
407 +                        fprintf(stderr, "\tpartially occluded\n");
408 + #endif
409 +                        return(f);              /* need to shadow test */
410 +                }
411          }
412 <        a2 = .25*(2.*(r1s+r2s) - d2 - (r2s-r1s)*(r2s-r1s)/d2);
413 <                                        /* no overlap? */
414 <        if (a2 <= 0.)
415 <                return(0.);
416 <                                        /* overlap, compute center */
417 <        l = sqrt((r1s - a2)/d2);
418 <        for (i = 0; i < 3; i++)
419 <                cc[i] = c1[i] + l*disp[i];
420 <        return(a2);
412 >        if (nhit == 0) {
413 > #ifdef DEBUG
414 >                fprintf(stderr, "\t0%% hit rate\n");
415 > #endif
416 >                return(f | SSKIP);      /* 0% hit rate:  totally occluded */
417 >        }
418 > #ifdef DEBUG
419 >        fprintf(stderr, "\t100%% hit rate\n");
420 > #endif
421 >        return(f & ~SFOLLOW);           /* 100% hit rate:  no occlusion */
422   }
423 +        
424  
308
425   #ifdef DEBUG
426 < virtverb(vs, fp)        /* print verbose description of virtual source */
427 < register SRCREC  *vs;
428 < FILE  *fp;
426 > void
427 > virtverb(       /* print verbose description of virtual source */
428 >        int  sn,
429 >        FILE  *fp
430 > )
431   {
314        register int  i;
315
432          fprintf(fp, "%s virtual source %d in %s %s\n",
433 <                        vs->sflags & SDISTANT ? "distant" : "local",
434 <                        vs-source, ofun[vs->so->otype].funame, vs->so->oname);
433 >                        source[sn].sflags & SDISTANT ? "distant" : "local",
434 >                        sn, ofun[source[sn].so->otype].funame,
435 >                        source[sn].so->oname);
436          fprintf(fp, "\tat (%f,%f,%f)\n",
437 <                        vs->sloc[0], vs->sloc[1], vs->sloc[2]);
437 >                source[sn].sloc[0], source[sn].sloc[1], source[sn].sloc[2]);
438          fprintf(fp, "\tlinked to source %d (%s)\n",
439 <                        vs->sa.svnext, source[vs->sa.svnext].so->oname);
440 <        if (vs->sflags & SFOLLOW)
439 >                source[sn].sa.sv.sn, source[source[sn].sa.sv.sn].so->oname);
440 >        if (source[sn].sflags & SFOLLOW)
441                  fprintf(fp, "\talways followed\n");
442          else
443                  fprintf(fp, "\tnever followed\n");
444 <        if (!(vs->sflags & SSPOT))
444 >        if (!(source[sn].sflags & SSPOT))
445                  return;
446          fprintf(fp, "\twith spot aim (%f,%f,%f) and size %f\n",
447 <                        vs->sl.s->aim[0], vs->sl.s->aim[1], vs->sl.s->aim[2],
448 <                        vs->sl.s->siz);
447 >                        source[sn].sl.s->aim[0], source[sn].sl.s->aim[1],
448 >                        source[sn].sl.s->aim[2], source[sn].sl.s->siz);
449   }
450   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines