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.7 by greg, Mon Jun 24 16:10:59 1991 UTC vs.
Revision 1.13 by greg, Wed Jun 26 08:55:10 1991 UTC

# Line 19 | Line 19 | static char SCCSid[] = "$SunId$ LBL";
19  
20   #include  "random.h"
21  
22 + #define  MINSAMPLES     3               /* minimum number of pretest samples */
23 + #define  STESTMAX       30              /* maximum seeks per sample */
24  
23 #define  DISKTFRAC      0.25            /* disk area pretest fraction */
25  
26   double  getdisk();
27  
# Line 117 | Line 118 | OBJREC  *op;
118   register int  sn;
119   MAT4  pm;
120   {
121 <        FVECT  nsloc, nsnorm, ocent;
122 <        double  maxrad2;
121 >        FVECT  nsloc, nsnorm, ocent, v;
122 >        double  maxrad2, d;
123          int  nsflags;
123        double  d1;
124          SPOT  theirspot, ourspot;
125          register int  i;
126  
# Line 140 | Line 140 | MAT4  pm;
140                  if (source[sn].sflags & SSPOT) {
141                          copystruct(&theirspot, source[sn].sl.s);
142                          multp3(theirspot.aim, source[sn].sl.s->aim, pm);
143 +                        d = ourspot.siz;
144                          if (!commonbeam(&ourspot, &theirspot, nsloc))
145 <                                return(-1);             /* no overlap */
145 >                                return(-1);     /* no overlap */
146 >                        if (ourspot.siz < d-FTINY) {    /* it shrunk */
147 >                                d = beamdisk(v, op, &ourspot, nsloc);
148 >                                if (d <= FTINY)
149 >                                        return(-1);
150 >                                if (d < maxrad2) {
151 >                                        maxrad2 = d;
152 >                                        VCOPY(ocent, v);
153 >                                }
154 >                        }
155                  }
156          } else {                                /* local source */
157                  multp3(nsloc, source[sn].sloc, pm);
158                  for (i = 0; i < 3; i++)
159                          ourspot.aim[i] = ocent[i] - nsloc[i];
160 <                if ((d1 = normalize(ourspot.aim)) == 0.)
160 >                if ((d = normalize(ourspot.aim)) == 0.)
161                          return(-1);             /* at source!! */
162 <                if (source[sn].sflags & SPROX && d1 > source[sn].sl.prox)
162 >                if (source[sn].sflags & SPROX && d > source[sn].sl.prox)
163                          return(-1);             /* too far away */
164 <                ourspot.siz = 2.*PI*(1. - d1/sqrt(d1*d1+maxrad2));
164 >                ourspot.siz = 2.*PI*(1. - d/sqrt(d*d+maxrad2));
165                  ourspot.flen = 0.;
166                  if (source[sn].sflags & SSPOT) {
167                          copystruct(&theirspot, source[sn].sl.s);
168                          multv3(theirspot.aim, source[sn].sl.s->aim, pm);
169 +                        d = ourspot.siz;
170                          if (!commonspot(&ourspot, &theirspot, nsloc))
171                                  return(-1);     /* no overlap */
172 +                        if (ourspot.siz < d-FTINY) {    /* it shrunk */
173 +                                d = spotdisk(v, op, &ourspot, nsloc);
174 +                                if (d <= FTINY)
175 +                                        return(-1);
176 +                                if (d < maxrad2) {
177 +                                        maxrad2 = d;
178 +                                        VCOPY(ocent, v);
179 +                                }
180 +                        }
181                          ourspot.flen = theirspot.flen;
182                  }
183                  if (source[sn].sflags & SFLAT) {        /* behind source? */
184                          multv3(nsnorm, source[sn].snorm, pm);
185 <                        if (checkspot(&ourspot, nsnorm) < 0)
185 >                        if (!checkspot(&ourspot, nsnorm))
186                                  return(-1);
187                  }
188          }
# Line 200 | Line 220 | register int  sn;
220          double  rad2, roffs, offs, d, rd, rdoto;
221          FVECT  rnrm, nrm;
222                                  /* first, use object getdisk function */
223 <        rad2 = (*sfun[op->otype].of->getdisk)(oc, op);
223 >        rad2 = getmaxdisk(oc, op);
224          if (!(source[sn].sflags & SVIRTUAL))
225                  return(rad2);           /* all done for normal source */
226                                  /* check for correct side of relay surface */
227 <        roffs = (*sfun[source[sn].so->otype].of->getpleq)(rnrm, source[sn].so);
227 >        roffs = getplaneq(rnrm, source[sn].so);
228          rd = DOT(rnrm, source[sn].sloc);        /* source projection */
229          if (!(source[sn].sflags & SDISTANT))
230                  rd -= roffs;
# Line 212 | Line 232 | register int  sn;
232          if ((d > 0.) ^ (rd > 0.))
233                  return(rad2);           /* OK if opposite sides */
234          if (d*d >= rad2)
235 <                return(.0);             /* no relay is possible */
235 >                return(0.);             /* no relay is possible */
236                                  /* we need a closer look */
237 <        offs = (*sfun[op->otype].of->getpleq)(nrm, op);
237 >        offs = getplaneq(nrm, op);
238          rdoto = DOT(rnrm, nrm);
239          if (d*d >= rad2*(1.-rdoto*rdoto))
240                  return(0.);             /* disk entirely on projection side */
# Line 235 | Line 255 | register int  sn;      /* target source number */
255          FVECT  onorm;
256          FVECT  offsdir;
257          double  or, d;
258 <        int  nok, nhit;
258 >        int  infront;
259 >        int  ssn;
260 >        int  nhit, nok;
261          register int  i, n;
262                                  /* return if pretesting disabled */
263          if (vspretest <= 0)
264                  return(f);
265                                  /* get surface normal */
266 <        (*sfun[o->otype].of->getpleq)(onorm, o);
266 >        getplaneq(onorm, o);
267                                  /* set number of rays to sample */
268 <        if (source[sn].sflags & SDISTANT)
268 >        if (source[sn].sflags & SDISTANT) {
269                  n = (2./3.*PI*PI)*or2/(thescene.cusize*thescene.cusize)*
270                                  vspretest + .5;
271 <        else
272 <                n = or2/dist2(oc,source[sn].sloc)*vspretest + .5;
273 <        if (n < 1) n = 1;
274 <                                /* limit tests to central region */
275 <        or = DISKTFRAC*sqrt(or2);
271 >                infront = DOT(onorm, source[sn].sloc) > 0.;
272 >        } else {
273 >                for (i = 0; i < 3; i++)
274 >                        offsdir[i] = source[sn].sloc[i] - oc[i];
275 >                n = or2/DOT(offsdir,offsdir)*vspretest + .5;
276 >                infront = DOT(onorm, offsdir) > 0.;
277 >        }
278 >        if (n < MINSAMPLES) n = MINSAMPLES;
279 > #ifdef DEBUG
280 >        fprintf(stderr, "pretesting source %d in object %s with %d rays\n",
281 >                        sn, o->oname, n);
282 > #endif
283                                  /* sample */
284 +        or = sqrt(or2);
285 +        ssn = STESTMAX*n;
286          nhit = nok = 0;
287          while (n-- > 0) {
288 <                samplendx++;
289 <                /*
290 <                 * We're being real sloppy with our sample locations here.
291 <                 */
292 <                for (i = 0; i < 3; i++)
293 <                        offsdir[i] = or*(1. - 2.*urand(931*i+5821+n));
294 <                d = DOT(offsdir,onorm);
295 <                for (i = 0; i < 3; i++)
296 <                        sr.rorg[i] = oc[i] + (1.-d)*offsdir[i];
288 >                                        /* get sample point */
289 >                do {
290 >                        if (--ssn < 0) {
291 > #ifdef DEBUG
292 >                                fprintf(stderr, "\ttoo hard to hit\n");
293 > #endif
294 >                                return(f);      /* too small a target! */
295 >                        }
296 >                        for (i = 0; i < 3; i++)
297 >                                offsdir[i] = or*(1. -
298 >                                                2.*urand(931*i+5827+ssn));
299 >                        for (i = 0; i < 3; i++)
300 >                                sr.rorg[i] = oc[i] + offsdir[i];
301 >                        d = DOT(offsdir,onorm);
302 >                        if (infront)
303 >                                for (i = 0; i < 3; i++) {
304 >                                        sr.rorg[i] -= (d-.0001)*onorm[i];
305 >                                        sr.rdir[i] = -onorm[i];
306 >                                }
307 >                        else
308 >                                for (i = 0; i < 3; i++) {
309 >                                        sr.rorg[i] -= (d+.0001)*onorm[i];
310 >                                        sr.rdir[i] = onorm[i];
311 >                                }
312 >                        rayorigin(&sr, NULL, PRIMARY, 1.0);
313 >                } while (!(*ofun[o->otype].funp)(o, &sr));
314                                          /* check against source */
315 <                if (srcray(&sr, NULL, sn) == 0.0)
315 >                samplendx++;
316 >                if (srcray(&sr, NULL, sn) == 0.)
317                          continue;
318                  sr.revf = srcvalue;
319                  rayvalue(&sr);
# Line 274 | Line 323 | register int  sn;      /* target source number */
323                                          /* check against obstructions */
324                  srcray(&sr, NULL, sn);
325                  rayvalue(&sr);
326 <                if (bright(sr.rcol) <= FTINY)
327 <                        continue;
328 <                nhit++;
326 >                if (bright(sr.rcol) > FTINY)
327 >                        nhit++;
328 >                if (nhit > 0 && nhit < nok) {
329 > #ifdef DEBUG
330 >                        fprintf(stderr, "\tpartially occluded\n");
331 > #endif
332 >                        return(f);              /* need to shadow test */
333 >                }
334          }
335 <                                /* interpret results */
336 <        if (nhit == 0)
335 >        if (nhit == 0) {
336 > #ifdef DEBUG
337 >                fprintf(stderr, "\t0%% hit rate\n");
338 > #endif
339                  return(f | SSKIP);      /* 0% hit rate:  totally occluded */
340 <        if (nhit == nok)
341 <                return(f & ~SFOLLOW);   /* 100% hit rate:  no occlusion */
342 <        return(f);              /* no comment */
340 >        }
341 > #ifdef DEBUG
342 >        fprintf(stderr, "\t100%% hit rate\n");
343 > #endif
344 >        return(f & ~SFOLLOW);           /* 100% hit rate:  no occlusion */
345   }
346          
347  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines