--- ray/src/rt/source.c 2003/02/25 02:47:23 2.30 +++ ray/src/rt/source.c 2003/09/12 22:35:54 2.37 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: source.c,v 2.30 2003/02/25 02:47:23 greg Exp $"; +static const char RCSid[] = "$Id: source.c,v 2.37 2003/09/12 22:35:54 greg Exp $"; #endif /* * source.c - routines dealing with illumination sources. @@ -54,17 +54,22 @@ marksources() /* find and mark source objects */ /* initialize dispatch table */ initstypes(); /* find direct sources */ - for (i = 0; i < nobjects; i++) { + for (i = 0; i < nsceneobjs; i++) { o = objptr(i); if (!issurface(o->otype) || o->omod == OVOID) continue; - + /* find material */ m = objptr(o->omod); - - if (!islight(m->otype)) - continue; + while (!ismaterial(m->otype)) + if (ismixture(m->otype) || m->omod == OVOID) { + m = NULL; + break; + } else + m = objptr(m->omod); + if (m == NULL || !islight(m->otype)) + continue; /* not source modifier */ if (m->oargs.nfargs != (m->otype == MAT_GLOW ? 4 : m->otype == MAT_SPOT ? 7 : 3)) @@ -115,7 +120,7 @@ marksources() /* find and mark source objects */ maxcntr = nsources + MAXSPART; /* start with this many */ srccnt = (CONTRIB *)malloc(maxcntr*sizeof(CONTRIB)); cntord = (CNTPTR *)malloc(maxcntr*sizeof(CNTPTR)); - if (srccnt == NULL | cntord == NULL) + if ((srccnt == NULL) | (cntord == NULL)) goto memerr; return; memerr: @@ -250,6 +255,8 @@ register RAY *r; for (i = 0; i < 3; i++) r->ron[i] = -r->rdir[i]; r->rod = 1.0; + r->pert[0] = r->pert[1] = r->pert[2] = 0.0; + r->uv[0] = r->uv[1] = 0.0; r->rox = NULL; return(1); } @@ -291,11 +298,11 @@ char *p; /* data for f */ for (sn = 0; srcray(&sr, r, &si); sn++) { if (sn >= maxcntr) { maxcntr = sn + MAXSPART; - srccnt = (CONTRIB *)realloc((char *)srccnt, + srccnt = (CONTRIB *)realloc((void *)srccnt, maxcntr*sizeof(CONTRIB)); - cntord = (CNTPTR *)realloc((char *)cntord, + cntord = (CNTPTR *)realloc((void *)cntord, maxcntr*sizeof(CNTPTR)); - if (srccnt == NULL | cntord == NULL) + if ((srccnt == NULL) | (cntord == NULL)) error(SYSTEM, "out of memory in direct"); } cntord[sn].sndx = sn; @@ -353,7 +360,11 @@ char *p; /* data for f */ rayorigin(&sr, r, SHADOW, 1.0); VCOPY(sr.rdir, scp->dir); sr.rsrc = scp->sno; - source[scp->sno].ntests++; /* keep statistics */ + /* keep statistics */ + if (source[scp->sno].ntests++ > 0xfffffff0) { + source[scp->sno].ntests >>= 1; + source[scp->sno].nhits >>= 1; + } if (localhit(&sr, &thescene) && ( sr.ro != source[scp->sno].so || source[scp->sno].sflags & SFOLLOW )) { @@ -485,13 +496,19 @@ register RAY *r; * geometry behind (or inside) an effective radiator. */ -static int weaksrcmod(obj) int obj; /* efficiency booster function */ -{register OBJREC *o = objptr(obj); -return(o->otype==MAT_ILLUM|o->otype==MAT_GLOW);} +static int +weaksrcmat(int obj) /* identify material */ +{ + register OBJREC *o = objptr(obj); + + while (!ismaterial(o->otype)) /* find material */ + o = objptr(o->omod); + return((o->otype==MAT_ILLUM)|(o->otype==MAT_GLOW)); +} #define illumblock(m, r) (!(source[r->rsrc].sflags&SVIRTUAL) && \ r->rod > 0.0 && \ - weaksrcmod(source[r->rsrc].so->omod)) + weaksrcmat(source[r->rsrc].so->omod)) /* wrongsource * *