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 2.3 by greg, Sun Apr 12 10:05:32 1992 UTC vs.
Revision 2.4 by greg, Fri Aug 28 14:07:41 1992 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 Regents of the University of California */
1 > /* Copyright (c) 1992 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 120 | Line 120 | RAY  *r;                       /* ray which hit object */
120   SRCINDEX  *si;                  /* source sample index */
121   {
122      double  d;                          /* distance to source */
123    FVECT  vd;
123      register SRCREC  *srcp;
125    register int  i;
124  
125      rayorigin(sr, r, SHADOW, 1.0);              /* ignore limits */
126  
# Line 130 | Line 128 | SRCINDEX  *si;                 /* source sample index */
128          sr->rsrc = si->sn;                      /* remember source */
129          srcp = source + si->sn;
130          if (srcp->sflags & SDISTANT) {
131 <                if (srcp->sflags & SSPOT) {     /* check location */
132 <                        for (i = 0; i < 3; i++)
135 <                            vd[i] = srcp->sl.s->aim[i] - sr->rorg[i];
136 <                        d = DOT(sr->rdir,vd);
137 <                        if (d <= FTINY)
138 <                                continue;
139 <                        d = DOT(vd,vd) - d*d;
140 <                        if (PI*d > srcp->sl.s->siz)
141 <                                continue;
142 <                }
131 >                if (srcp->sflags & SSPOT && spotout(sr, srcp->sl.s, 1))
132 >                        continue;
133                  return(1);              /* sample OK */
134          }
135                                  /* local source */
# Line 148 | Line 138 | SRCINDEX  *si;                 /* source sample index */
138                  continue;
139                                                  /* check angle */
140          if (srcp->sflags & SSPOT) {
141 <                if (srcp->sl.s->siz < 2.0*PI *
152 <                                (1.0 + DOT(srcp->sl.s->aim,sr->rdir)))
141 >                if (spotout(sr, srcp->sl.s, 0))
142                          continue;
143                                          /* adjust solid angle */
144                  si->dom *= d*d;
# Line 322 | Line 311 | char  *p;                      /* data for f */
311                  scalecolor(srccnt[cntord[sn].sndx].val, prob);
312                  addcolor(r->rcol, srccnt[cntord[sn].sndx].val);
313          }
314 + }
315 +
316 +
317 + /****************************************************************
318 + * The following macros were separated from the m_light() routine
319 + * because they are very nasty and difficult to understand.
320 + */
321 +
322 + /* wrongillum *
323 + *
324 + * We cannot allow an illum to pass to another illum, because that
325 + * would almost certainly constitute overcounting.
326 + * However, we do allow an illum to pass to another illum
327 + * that is actually going to relay to a virtual light source.
328 + */
329 +
330 + #define  wrongillum(m, r)       (!(source[r->rsrc].sflags&SVIRTUAL) && \
331 +                        objptr(source[r->rsrc].so->omod)->otype==MAT_ILLUM)
332 +
333 + /* wrongsource *
334 + *
335 + * This source is the wrong source (ie. overcounted) if we are
336 + * aimed to a different source than the one we hit and the one
337 + * we hit is not an illum which should be passed.
338 + */
339 +
340 + #define  wrongsource(m, r)      (r->rsrc>=0 && source[r->rsrc].so!=r->ro && \
341 +                                (m->otype!=MAT_ILLUM || wrongillum(m,r)))
342 +
343 + /* distglow *
344 + *
345 + * A distant glow is an object that sometimes acts as a light source,
346 + * but is too far away from the test point to be one in this case.
347 + */
348 +
349 + #define  distglow(m, r)         (m->otype==MAT_GLOW && \
350 +                                r->rot > m->oargs.farg[3])
351 +
352 + /* badcomponent *
353 + *
354 + * We must avoid counting light sources in the ambient calculation,
355 + * since the direct component is handled separately.  Therefore, any
356 + * ambient ray which hits an active light source must be discarded.
357 + * The same is true for stray specular samples, since the specular
358 + * contribution from light sources is calculated separately.
359 + */
360 +
361 + #define  badcomponent(m, r)     (r->crtype&(AMBIENT|SPECULAR) && \
362 +                                !(r->crtype&SHADOW || r->rod < 0.0 || \
363 +                                        distglow(m, r)))
364 +
365 + /* overcount *
366 + *
367 + * All overcounting possibilities are contained here.
368 + */
369 +
370 + #define  overcount(m, r)        (badcomponent(m,r) || wrongsource(m,r))
371 +
372 + /* passillum *
373 + *
374 + * An illum passes to another material type when we didn't hit it
375 + * on purpose (as part of a direct calculation), or it is relaying
376 + * a virtual light source.
377 + */
378 +
379 + #define  passillum(m, r)        (m->otype==MAT_ILLUM && \
380 +                                (r->rsrc<0 || source[r->rsrc].so!=r->ro || \
381 +                                source[r->rsrc].sflags&SVIRTUAL))
382 +
383 + /* srcignore *
384 + *
385 + * The -di flag renders light sources invisible, and here is the test.
386 + */
387 +
388 + #define  srcignore(m, r)        (directinvis && !(r->crtype&SHADOW) && \
389 +                                !distglow(m, r))
390 +
391 +
392 + m_light(m, r)                   /* ray hit a light source */
393 + register OBJREC  *m;
394 + register RAY  *r;
395 + {
396 +                                                /* check for over-counting */
397 +        if (overcount(m, r))
398 +                return;
399 +                                                /* check for passed illum */
400 +        if (passillum(m, r)) {
401 +                if (m->oargs.nsargs < 1 || !strcmp(m->oargs.sarg[0], VOIDID))
402 +                        raytrans(r);
403 +                else
404 +                        rayshade(r, modifier(m->oargs.sarg[0]));
405 +                return;
406 +        }
407 +                                        /* otherwise treat as source */
408 +                                                /* check for behind */
409 +        if (r->rod < 0.0)
410 +                return;
411 +                                                /* check for invisibility */
412 +        if (srcignore(m, r))
413 +                return;
414 +                                                /* check for outside spot */
415 +        if (m->otype==MAT_SPOT && spotout(r, (SPOT *)m->os, r->rot>=FHUGE))
416 +                return;
417 +                                                /* get distribution pattern */
418 +        raytexture(r, m->omod);
419 +                                                /* get source color */
420 +        setcolor(r->rcol, m->oargs.farg[0],
421 +                          m->oargs.farg[1],
422 +                          m->oargs.farg[2]);
423 +                                                /* modify value */
424 +        multcolor(r->rcol, r->pcol);
425   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines