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.46 by greg, Wed Sep 8 17:10:16 2004 UTC vs.
Revision 2.47 by greg, Thu Mar 10 22:37:00 2005 UTC

# Line 250 | Line 250 | nomat:
250   }
251  
252  
253 + static int
254 + transillum(                     /* check if material is transparent illum */
255 +        OBJECT  obj
256 + )
257 + {
258 +        OBJREC *m = findmaterial(objptr(obj));
259 +        
260 +        if (m == NULL)
261 +                return(1);
262 +        if (m->otype != MAT_ILLUM)
263 +                return(0);
264 +        return(!m->oargs.nsargs || !strcmp(m->oargs.sarg[0], VOIDID));
265 + }
266 +
267 +
268   extern int
269   sourcehit(                      /* check to see if ray hit distant source */
270          register RAY  *r
271   )
272   {
273 +        int  glowsrc = -1;
274 +        int  transrc = -1;
275          int  first, last;
276          register int  i;
277  
# Line 263 | Line 280 | sourcehit(                     /* check to see if ray hit distant source
280          } else {                        /* otherwise check all */
281                  first = 0; last = nsources-1;
282          }
283 <        for (i = first; i <= last; i++)
284 <                if ((source[i].sflags & (SDISTANT|SVIRTUAL)) == SDISTANT)
285 <                        /*
286 <                         * Check to see if ray is within
287 <                         * solid angle of source.
288 <                         */
289 <                        if (2.0*PI * (1.0 - DOT(source[i].sloc,r->rdir))
290 <                                        <= source[i].ss2) {
291 <                                r->ro = source[i].so;
292 <                                if (!(source[i].sflags & SSKIP))
293 <                                        break;
294 <                        }
295 <
296 <        if (r->ro != NULL) {
297 <                r->robj = objndx(r->ro);
298 <                for (i = 0; i < 3; i++)
299 <                        r->ron[i] = -r->rdir[i];
300 <                r->rod = 1.0;
301 <                r->pert[0] = r->pert[1] = r->pert[2] = 0.0;
302 <                r->uv[0] = r->uv[1] = 0.0;
303 <                r->rox = NULL;
304 <                return(1);
283 >        for (i = first; i <= last; i++) {
284 >                if ((source[i].sflags & (SDISTANT|SVIRTUAL)) != SDISTANT)
285 >                        continue;
286 >                /*
287 >                 * Check to see if ray is within
288 >                 * solid angle of source.
289 >                 */
290 >                if (2.*PI*(1. - DOT(source[i].sloc,r->rdir)) > source[i].ss2)
291 >                        continue;
292 >                                        /* is it the only possibility? */
293 >                if (first == last) {
294 >                        r->ro = source[i].so;
295 >                        break;
296 >                }
297 >                /*
298 >                 * If it's a glow or transparent illum, just remember it.
299 >                 */
300 >                if (source[i].sflags & SSKIP) {
301 >                        glowsrc = i;
302 >                        continue;
303 >                }
304 >                if (transillum(source[i].so->omod)) {
305 >                        transrc = i;
306 >                        continue;
307 >                }
308 >                r->ro = source[i].so;   /* otherwise, use first hit */
309 >                break;
310          }
311 <        return(0);
311 >        /*
312 >         * Do we need fallback?
313 >         */
314 >        if (r->ro == NULL) {
315 >                if (transrc >= 0 && r->crtype & (AMBIENT|SPECULAR))
316 >                        return(0);      /* avoid overcounting */
317 >                if (glowsrc >= 0)
318 >                        r->ro = source[glowsrc].so;
319 >                else
320 >                        return(0);      /* nothing usable */
321 >        }
322 >        /*
323 >         * Make assignments.
324 >         */
325 >        r->robj = objndx(r->ro);
326 >        for (i = 0; i < 3; i++)
327 >                r->ron[i] = -r->rdir[i];
328 >        r->rod = 1.0;
329 >        r->pert[0] = r->pert[1] = r->pert[2] = 0.0;
330 >        r->uv[0] = r->uv[1] = 0.0;
331 >        r->rox = NULL;
332 >        return(1);
333   }
334  
335  
# Line 553 | Line 596 | srcscatter(                    /* compute source scattering into ray */
596   static int
597   weaksrcmat(OBJECT obj)          /* identify material */
598   {
599 <        OBJREC *o = findmaterial(objptr(obj));
599 >        OBJREC *m = findmaterial(objptr(obj));
600          
601 <        if (o == NULL) return 0;
602 <        return((o->otype==MAT_ILLUM)|(o->otype==MAT_GLOW));
601 >        if (m == NULL) return(0);
602 >        return((m->otype==MAT_ILLUM) | (m->otype==MAT_GLOW));
603   }
604  
605   #define  illumblock(m, r)       (!(source[r->rsrc].sflags&SVIRTUAL) && \

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines