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.18 by greg, Wed Nov 29 14:35:27 1989 UTC vs.
Revision 1.28 by greg, Fri Dec 21 11:32:39 1990 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1990 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 32 | Line 32 | extern double  shadcert;               /* shadow testing certainty
32   SRCREC  *source = NULL;                 /* our list of sources */
33   int  nsources = 0;                      /* the number of sources */
34  
35 + static CONTRIB  *srccnt;                /* source contributions in direct() */
36 + static CNTPTR  *cntord;                 /* source ordering in direct() */
37  
38 +
39   marksources()                   /* find and mark source objects */
40   {
41          register OBJREC  *o, *m;
# Line 47 | Line 50 | marksources()                  /* find and mark source objects */
50  
51                  m = objptr(o->omod);
52  
53 <                if (m->otype != MAT_LIGHT &&
51 <                                m->otype != MAT_ILLUM &&
52 <                                m->otype != MAT_GLOW &&
53 <                                m->otype != MAT_SPOT)
53 >                if (!islight(m->otype))
54                          continue;
55          
56                  if (m->oargs.nfargs != (m->otype == MAT_GLOW ? 4 :
# Line 68 | Line 68 | marksources()                  /* find and mark source objects */
68                          source = (SRCREC *)realloc((char *)source,
69                                          (unsigned)(nsources+1)*sizeof(SRCREC));
70                  if (source == NULL)
71 <                        error(SYSTEM, "out of memory in marksources");
71 >                        goto memerr;
72  
73                  newsource(&source[nsources], o);
74  
# Line 83 | Line 83 | marksources()                  /* find and mark source objects */
83                  }
84                  nsources++;
85          }
86 +        if (nsources <= 0) {
87 +                error(WARNING, "no light sources found");
88 +                return;
89 +        }
90 +        srccnt = (CONTRIB *)malloc(nsources*sizeof(CONTRIB));
91 +        cntord = (CNTPTR *)malloc(nsources*sizeof(CNTPTR));
92 +        if (srccnt != NULL && cntord != NULL)
93 +                return;
94 +        /* fall through */
95 + memerr:
96 +        error(SYSTEM, "out of memory in marksources");
97   }
98  
99  
# Line 226 | Line 237 | register int  sn;              /* source number */
237                                                  /* domega constant */
238                  return(source[sn].ss2);
239  
229        else {
240                                                  /* check proximity */
241 <                if (source[sn].sflags & SPROX &&
242 <                                d > source[sn].sl.prox)
243 <                        return(0.0);
244 <
245 <                if (norm != NULL)
246 <                        ddot /= d;
247 <                else
248 <                        ddot = 1.0;
241 >        if (source[sn].sflags & SPROX &&
242 >                        d > source[sn].sl.prox)
243 >                return(0.0);
244 >                                                /* compute dot product */
245 >        if (norm != NULL)
246 >                ddot /= d;
247 >        else
248 >                ddot = 1.0;
249                                                  /* check angle */
250 <                if (source[sn].sflags & SSPOT) {
251 <                        if (source[sn].sl.s->siz < 2.0*PI *
250 >        if (source[sn].sflags & SSPOT) {
251 >                if (source[sn].sl.s->siz < 2.0*PI *
252                                  (1.0 + DOT(source[sn].sl.s->aim,sr->rdir)))
253 <                                return(0.0);
254 <                        d += source[sn].sl.s->flen;
245 <                }
246 <                                                /* return domega */
247 <                return(ddot*source[sn].ss2/(d*d));
253 >                        return(0.0);
254 >                d += source[sn].sl.s->flen;     /* adjust length */
255          }
256 +                                                /* compute domega */
257 +        return(ddot*source[sn].ss2/(d*d));
258   }
259  
260  
# Line 277 | Line 286 | register RAY  *r;
286                  for (i = 0; i < 3; i++)
287                          r->ron[i] = -r->rdir[i];
288                  r->rod = 1.0;
289 <                r->rofs = 1.0; setident4(r->rofx);
281 <                r->robs = 1.0; setident4(r->robx);
289 >                r->rox = NULL;
290                  return(1);
291          }
292          return(0);
# Line 304 | Line 312 | char  *p;                      /* data for f */
312   {
313          extern double  pow();
314          register int  sn;
307        register CONTRIB  *srccnt;
308        register CNTPTR  *cntord;
315          int  nshadcheck, ncnts;
316          double  prob, ourthresh, hwt, test2, hit2;
317          RAY  sr;
318 <
319 <        srccnt = (CONTRIB *)malloc(nsources*sizeof(CONTRIB));
320 <        cntord = (CNTPTR *)malloc(nsources*sizeof(CNTPTR));
315 <        if (srccnt == NULL || cntord == NULL)
316 <                error(SYSTEM, "out of memory in direct");
318 >                        /* NOTE: srccnt and cntord global so no recursion */
319 >        if (nsources <= 0)
320 >                return;         /* no sources?! */
321                                                  /* compute number to check */
322          nshadcheck = pow((double)nsources, shadcert) + .5;
323                                                  /* modify threshold */
# Line 335 | Line 339 | char  *p;                      /* data for f */
339                  if (!( source[sn].sflags & SDISTANT ?
340                                  sourcehit(&sr) :
341                                  (*ofun[source[sn].so->otype].funp)
342 <                                (source[sn].so, &sr) ))
342 >                                (source[sn].so, &sr) )) {
343 >                        sprintf(errmsg,
344 >                                "aiming failure for light source \"%s\"",
345 >                                        source[sn].so->oname);
346 >                        error(WARNING, errmsg);
347 >                        cntord[sn].brt = 0.0;
348                          continue;
349 +                }
350                                                  /* compute contribution */
351 <                rayshade(&sr, sr.ro->omod);
351 >                raycont(&sr);
352                  multcolor(srccnt[sn].val, sr.rcol);
353                  cntord[sn].brt = bright(srccnt[sn].val);
354          }
# Line 365 | Line 375 | char  *p;                      /* data for f */
375          for (sn = 0; sn < ncnts; sn++) {
376                                                  /* check threshold */
377                  if ((sn+nshadcheck>=ncnts ? cntord[sn].brt :
378 <                                cntord[sn].brt-cntord[sn+nshadcheck].brt) <
379 <                                ourthresh*bright(r->rcol))
378 >                                cntord[sn].brt-cntord[sn+nshadcheck].brt)
379 >                                < ourthresh*bright(r->rcol))
380                          break;
381                                                  /* get statistics */
382                  hwt = (double)source[cntord[sn].sno].nhits /
# Line 376 | Line 386 | char  *p;                      /* data for f */
386                                                  /* test for hit */
387                  rayorigin(&sr, r, SHADOW, 1.0);
388                  VCOPY(sr.rdir, srccnt[cntord[sn].sno].dir);
389 +                sr.rsrc = cntord[sn].sno;
390                  if (localhit(&sr, &thescene) &&
391                                  sr.ro != source[cntord[sn].sno].so) {
392                                                  /* check for transmission */
393 <                        if (sr.clipset != NULL && inset(sr.clipset, sr.ro->omod))
383 <                                raytrans(&sr);
384 <                        else
385 <                                rayshade(&sr, sr.ro->omod);
393 >                        raycont(&sr);
394                          if (bright(sr.rcol) <= FTINY)
395                                  continue;       /* missed! */
396                          (*f)(srccnt[cntord[sn].sno].val, p,
# Line 397 | Line 405 | char  *p;                      /* data for f */
405          }
406                                          /* weighted hit rate */
407          hwt = hit2 / test2;
408 < #ifdef notdef
408 > #ifdef DEBUG
409          sprintf(errmsg, "%d tested, %d untested, %f hit rate\n",
410                          sn, ncnts-sn, hwt);
411          eputs(errmsg);
# Line 409 | Line 417 | char  *p;                      /* data for f */
417                  scalecolor(srccnt[cntord[sn].sno].val, prob);
418                  addcolor(r->rcol, srccnt[cntord[sn].sno].val);
419          }
412                
413        free(srccnt);
414        free(cntord);
420   }
421  
422  
# Line 455 | Line 460 | register RAY  *r;
460                                    m->oargs.farg[2]);
461                                                  /* modify value */
462                  multcolor(r->rcol, r->pcol);
463 +                                                /* assign distance */
464 +                r->rt = r->rot;
465          }
466   }
460
461
462 o_source() {}           /* intersection with a source is done elsewhere */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines