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

Comparing ray/src/rt/source.c (file contents):
Revision 1.9 by greg, Thu Jun 8 09:35:43 1989 UTC vs.
Revision 1.21 by greg, Tue Mar 27 11:40:13 1990 UTC

# Line 27 | Line 27 | static char SCCSid[] = "$SunId$ LBL";
27  
28   extern double  dstrsrc;                 /* source distribution amount */
29   extern double  shadthresh;              /* relative shadow threshold */
30 + extern double  shadcert;                /* shadow testing certainty */
31  
32   SRCREC  *source = NULL;                 /* our list of sources */
33   int  nsources = 0;                      /* the number of sources */
# Line 301 | Line 302 | RAY  *r;                       /* ray that hit surface */
302   int  (*f)();                    /* direct component coefficient function */
303   char  *p;                       /* data for f */
304   {
305 +        extern double  pow();
306          register int  sn;
307          register CONTRIB  *srccnt;
308          register CNTPTR  *cntord;
309 <        int  ncnts;
310 <        double  ourthresh, prob, hwt, test2, hit2;
309 >        int  nshadcheck, ncnts;
310 >        double  prob, ourthresh, hwt, test2, hit2;
311          RAY  sr;
312  
313          srccnt = (CONTRIB *)malloc(nsources*sizeof(CONTRIB));
314          cntord = (CNTPTR *)malloc(nsources*sizeof(CNTPTR));
315          if (srccnt == NULL || cntord == NULL)
316                  error(SYSTEM, "out of memory in direct");
317 +                                                /* compute number to check */
318 +        nshadcheck = pow((double)nsources, shadcert) + .5;
319                                                  /* modify threshold */
320          ourthresh = shadthresh / r->rweight;
321                                                  /* potential contributions */
# Line 325 | Line 329 | char  *p;                      /* data for f */
329                                                  /* compute coefficient */
330                  (*f)(srccnt[sn].val, p, srccnt[sn].dir, srccnt[sn].dom);
331                  cntord[sn].brt = bright(srccnt[sn].val);
332 <                if (cntord[sn].brt <= FTINY)
332 >                if (cntord[sn].brt <= 0.0)
333                          continue;
334                                                  /* compute intersection */
335                  if (!( source[sn].sflags & SDISTANT ?
# Line 334 | Line 338 | char  *p;                      /* data for f */
338                                  (source[sn].so, &sr) ))
339                          continue;
340                                                  /* compute contribution */
341 <                rayshade(&sr, sr.ro->omod);
341 >                raycont(&sr);
342                  multcolor(srccnt[sn].val, sr.rcol);
343                  cntord[sn].brt = bright(srccnt[sn].val);
344          }
345                                                  /* sort contributions */
346          qsort(cntord, nsources, sizeof(CNTPTR), cntcmp);
347 <        hit2 = 0.0; test2 = FTINY;
348 <                                                /* find last */
349 <        sn = 0; ncnts = nsources;
350 <        while (sn < ncnts-1) {
351 <                register int  m;
352 <                m = (sn + ncnts) >> 1;
353 <                if (cntord[m].brt > 0.0)
354 <                        sn = m;
355 <                else
356 <                        ncnts = m;
347 >        {                                       /* find last */
348 >                register int  l, m;
349 >
350 >                sn = 0; ncnts = l = nsources;
351 >                while ((m = (sn + ncnts) >> 1) != l) {
352 >                        if (cntord[m].brt > 0.0)
353 >                                sn = m;
354 >                        else
355 >                                ncnts = m;
356 >                        l = m;
357 >                }
358          }
359 <                                                /* accumulate tail */
360 <        for (sn = ncnts-1; sn > 0; sn--)
361 <                cntord[sn-1].brt += cntord[sn].brt;
362 <                                                /* shadow testing */
359 >                                                /* accumulate tail */
360 >        for (sn = ncnts-1; sn > 0; sn--)
361 >                cntord[sn-1].brt += cntord[sn].brt;
362 >                                                /* start with prob=.5 */
363 >        hit2 = 0.5; test2 = 1.0;
364 >                                                /* test for shadows */
365          for (sn = 0; sn < ncnts; sn++) {
366 <                                                /* tail below threshold? */
367 <                if (cntord[sn].brt < ourthresh*bright(r->rcol))
366 >                                                /* check threshold */
367 >                if ((sn+nshadcheck>=ncnts ? cntord[sn].brt :
368 >                                cntord[sn].brt-cntord[sn+nshadcheck].brt) <
369 >                                ourthresh*bright(r->rcol))
370                          break;
371                                                  /* get statistics */
372                  hwt = (double)source[cntord[sn].sno].nhits /
# Line 367 | Line 376 | char  *p;                      /* data for f */
376                                                  /* test for hit */
377                  rayorigin(&sr, r, SHADOW, 1.0);
378                  VCOPY(sr.rdir, srccnt[cntord[sn].sno].dir);
379 +                sr.rsrc = cntord[sn].sno;
380                  if (localhit(&sr, &thescene) &&
381                                  sr.ro != source[cntord[sn].sno].so) {
382                                                  /* check for transmission */
383 <                        if (sr.clipset != NULL && inset(sr.clipset,sr.ro->omod))
374 <                                raytrans(&sr);          /* object is clipped */
375 <                        else
376 <                                rayshade(&sr, sr.ro->omod);
383 >                        raycont(&sr);
384                          if (bright(sr.rcol) <= FTINY)
385                                  continue;       /* missed! */
386                          (*f)(srccnt[cntord[sn].sno].val, p,
# Line 389 | Line 396 | char  *p;                      /* data for f */
396                                          /* weighted hit rate */
397          hwt = hit2 / test2;
398   #ifdef DEBUG
399 <        fprintf(stderr, "%d tested, %d untested, %f hit rate\n",
399 >        sprintf(errmsg, "%d tested, %d untested, %f hit rate\n",
400                          sn, ncnts-sn, hwt);
401 +        eputs(errmsg);
402   #endif
403                                          /* add in untested sources */
404          for ( ; sn < ncnts; sn++) {
# Line 399 | Line 407 | char  *p;                      /* data for f */
407                  scalecolor(srccnt[cntord[sn].sno].val, prob);
408                  addcolor(r->rcol, srccnt[cntord[sn].sno].val);
409          }
410 +                
411          free(srccnt);
412          free(cntord);
413   }
# Line 420 | Line 429 | m_light(m, r)                  /* ray hit a light source */
429   register OBJREC  *m;
430   register RAY  *r;
431   {
423                                                /* check for behind */
424        if (r->rod < 0.0)
425                return;
432                                                  /* check for over-counting */
433          if (wrongsource(m, r) || badambient(m, r))
434                  return;
# Line 436 | Line 442 | register RAY  *r;
442  
443                                                  /* otherwise treat as source */
444          } else {
445 +                                                /* check for behind */
446 +                if (r->rod < 0.0)
447 +                        return;
448                                                  /* get distribution pattern */
449                  raytexture(r, m->omod);
450                                                  /* get source color */
# Line 444 | Line 453 | register RAY  *r;
453                                    m->oargs.farg[2]);
454                                                  /* modify value */
455                  multcolor(r->rcol, r->pcol);
456 +                                                /* assign distance */
457 +                r->rt = r->rot;
458          }
459   }
460  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines