--- ray/src/rt/virtuals.c 1991/10/21 12:58:18 1.28 +++ ray/src/rt/virtuals.c 1994/12/20 20:18:43 2.3 @@ -1,4 +1,4 @@ -/* Copyright (c) 1991 Regents of the University of California */ +/* Copyright (c) 1994 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -41,7 +41,7 @@ markvirtuals() /* find and mark virtual sources */ o = objptr(i); if (!issurface(o->otype) || o->omod == OVOID) continue; - if (!isvlight(objptr(o->omod)->otype)) + if (!isvlight(vsmaterial(o)->otype)) continue; if (sfun[o->otype].of == NULL || sfun[o->otype].of->getpleq == NULL) { @@ -101,7 +101,7 @@ int n; if (o == source[sn].so) /* objects cannot project themselves */ return; /* get virtual source material */ - vsmat = sfun[objptr(o->omod)->otype].mf; + vsmat = sfun[vsmaterial(o)->otype].mf; /* project virtual sources */ for (i = 0; i < vsmat->nproj; i++) if ((*vsmat->vproj)(proj, o, &source[sn], i)) @@ -115,6 +115,23 @@ int n; } +OBJREC * +vsmaterial(o) /* get virtual source material pointer */ +OBJREC *o; +{ + register int i; + register OBJREC *m; + + i = o->omod; + m = objptr(i); + if (m->otype != MAT_ILLUM || m->oargs.nsargs < 1 || + !strcmp(m->oargs.sarg[0], VOIDID) || + (i = modifier(m->oargs.sarg[0])) == OVOID) + return(m); /* direct modifier */ + return(objptr(i)); /* illum alternate */ +} + + int makevsrc(op, sn, pm) /* make virtual source if reasonable */ OBJREC *op; @@ -143,6 +160,7 @@ MAT4 pm; ourspot.flen = 0.; if (source[sn].sflags & SSPOT) { multp3(theirspot.aim, source[sn].sl.s->aim, pm); + /* adjust for source size */ d = sqrt(dist2(ourspot.aim, theirspot.aim)); d = sqrt(source[sn].sl.s->siz/PI) + d*source[sn].srad; theirspot.siz = PI*d*d; @@ -169,6 +187,7 @@ MAT4 pm; if (source[sn].sflags & SPROX && d > source[sn].sl.prox) return(-1); /* too far away */ ourspot.flen = 0.; + /* adjust for source size */ d = (sqrt(maxrad2) + source[sn].srad) / d; if (d < 1.-FTINY) ourspot.siz = 2.*PI*(1. - sqrt(1.-d*d)); @@ -220,6 +239,7 @@ MAT4 pm; VCOPY(source[i].snorm, nsnorm); else multv3(source[i].ss[SW], source[sn].ss[SW], pm); + source[i].srad = source[sn].srad; source[i].ss2 = source[sn].ss2; if (nsflags & SSPOT) { if ((source[i].sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL) @@ -331,6 +351,7 @@ register int sn; /* target source number */ for (i = 0; i < 3; i++) sr.rorg[i] = oc[i] + offsdir[i]; d = DOT(offsdir,onorm); + sr.rmax = 0.0; if (infront) for (i = 0; i < 3; i++) { sr.rorg[i] -= (d-.0001)*onorm[i]; @@ -346,7 +367,7 @@ register int sn; /* target source number */ /* check against source */ initsrcindex(&si); si.sn = sn; - nopart(&si, sr.rorg); + nopart(&si, &sr); samplendx++; if (!srcray(&sr, NULL, &si) || sr.rsrc != sn) continue;