--- ray/src/rt/source.c 1991/06/20 13:43:29 1.35 +++ ray/src/rt/source.c 1991/08/13 12:16:37 1.43 @@ -1,4 +1,4 @@ -/* Copyright (c) 1990 Regents of the University of California */ +/* Copyright (c) 1991 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -43,7 +43,7 @@ marksources() /* find and mark source objects */ { int i; register OBJREC *o, *m; - register SRCREC *ns; + register int ns; /* initialize dispatch table */ initstypes(); /* find direct sources */ @@ -72,20 +72,26 @@ marksources() /* find and mark source objects */ sfun[o->otype].of->setsrc == NULL) objerror(o, USER, "illegal material"); - if ((ns = newsource()) == NULL) + if ((ns = newsource()) < 0) goto memerr; - (*sfun[o->otype].of->setsrc)(ns, o); + setsource(&source[ns], o); if (m->otype == MAT_GLOW) { - ns->sflags |= SPROX; - ns->sl.prox = m->oargs.farg[3]; + source[ns].sflags |= SPROX; + source[ns].sl.prox = m->oargs.farg[3]; if (o->otype == OBJ_SOURCE) - ns->sflags |= SSKIP; + source[ns].sflags |= SSKIP; } else if (m->otype == MAT_SPOT) { - ns->sflags |= SSPOT; - if ((ns->sl.s = makespot(m)) == NULL) + source[ns].sflags |= SSPOT; + if ((source[ns].sl.s = makespot(m)) == NULL) goto memerr; + if (source[ns].sflags & SFLAT && + !checkspot(source[ns].sl.s,source[ns].snorm)) { + objerror(o, WARNING, + "invalid spotlight direction"); + source[ns].sflags |= SSKIP; + } } } if (nsources <= 0) { @@ -95,7 +101,7 @@ marksources() /* find and mark source objects */ markvirtuals(); /* find and add virtual sources */ srccnt = (CONTRIB *)malloc(nsources*sizeof(CONTRIB)); cntord = (CNTPTR *)malloc(nsources*sizeof(CNTPTR)); - if (srccnt != NULL && cntord != NULL) + if (srccnt == NULL || cntord == NULL) goto memerr; return; memerr: @@ -122,14 +128,6 @@ register int sn; /* source number */ sr->rsrc = sn; /* remember source */ /* get source direction */ if (source[sn].sflags & SDISTANT) { - if (source[sn].sflags & SSPOT) { /* check location */ - for (i = 0; i < 3; i++) - vd[i] = sr->rorg[i] - source[sn].sl.s->aim[i]; - d = DOT(source[sn].sloc,vd); - d = DOT(vd,vd) - d*d; - if (PI*d > source[sn].sl.s->siz) - return(0.0); - } /* constant direction */ VCOPY(sr->rdir, source[sn].sloc); } else { /* compute direction */ @@ -142,13 +140,10 @@ register int sn; /* source number */ } if (dstrsrc > FTINY) { /* distribute source direction */ - dimlist[ndims++] = sn; - for (i = 0; i < 3; i++) { - dimlist[ndims] = i + 8831; - vd[i] = dstrsrc * source[sn].ss * - (1.0 - 2.0*urand(ilhash(dimlist,ndims+1)+samplendx)); - } - ndims--; + dimlist[ndims] = sn + 8831; + peano(vd, 3, urand(ilhash(dimlist,ndims+1)+samplendx), .01); + for (i = 0; i < 3; i++) + vd[i] = dstrsrc * source[sn].ss * (1. - 2.*vd[i]); if (source[sn].sflags & SFLAT) { /* project offset */ d = DOT(vd, source[sn].snorm); for (i = 0; i < 3; i++) @@ -156,19 +151,29 @@ register int sn; /* source number */ } for (i = 0; i < 3; i++) /* offset source direction */ sr->rdir[i] += vd[i]; + /* normalize */ + d = normalize(sr->rdir); - } else if (source[sn].sflags & SDISTANT) - /* already normalized */ - return(source[sn].ss2); + } else if (!(source[sn].sflags & SDISTANT)) + /* normalize direction */ + d = normalize(sr->rdir); - if ((d = normalize(sr->rdir)) == 0.0) - /* at source! */ + if (source[sn].sflags & SDISTANT) { + if (source[sn].sflags & SSPOT) { /* check location */ + for (i = 0; i < 3; i++) + vd[i] = source[sn].sl.s->aim[i] - sr->rorg[i]; + d = DOT(sr->rdir,vd); + if (d <= FTINY) + return(0.0); + d = DOT(vd,vd) - d*d; + if (PI*d > source[sn].sl.s->siz) + return(0.0); + } + return(source[sn].ss2); /* domega constant */ + } + /* check direction */ + if (d == 0.0) return(0.0); - - if (source[sn].sflags & SDISTANT) - /* domega constant */ - return(source[sn].ss2); - /* check proximity */ if (source[sn].sflags & SPROX && d > source[sn].sl.prox) @@ -239,6 +244,7 @@ RAY *r; /* ray that hit surface */ int (*f)(); /* direct component coefficient function */ char *p; /* data for f */ { + extern int (*trace)(); extern double pow(); register int sn; int nshadcheck, ncnts; @@ -308,6 +314,8 @@ char *p; /* data for f */ source[cntord[sn].sno].sflags & SFOLLOW )) { /* follow entire path */ raycont(&sr); + if (trace != NULL) + (*trace)(&sr); /* trace execution */ if (bright(sr.rcol) <= FTINY) continue; /* missed! */ copycolor(srccnt[cntord[sn].sno].val, sr.rcol);