ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/virtuals.c
(Generate patch)

Comparing ray/src/rt/virtuals.c (file contents):
Revision 1.11 by greg, Tue Jun 25 15:48:11 1991 UTC vs.
Revision 2.2 by greg, Sat May 23 08:03:19 1992 UTC

# Line 19 | Line 19 | static char SCCSid[] = "$SunId$ LBL";
19  
20   #include  "random.h"
21  
22 + #define  MINSAMPLES     16              /* minimum number of pretest samples */
23 + #define  STESTMAX       32              /* maximum seeks per sample */
24  
25 +
26   double  getdisk();
27  
28   static OBJECT  *vobject;                /* virtual source objects */
# Line 38 | Line 41 | markvirtuals()                 /* find and mark virtual sources */
41                  o = objptr(i);
42                  if (!issurface(o->otype) || o->omod == OVOID)
43                          continue;
44 <                if (!isvlight(objptr(o->omod)->otype))
44 >                if (!isvlight(vsmaterial(o)->otype))
45                          continue;
46                  if (sfun[o->otype].of == NULL ||
47 <                                sfun[o->otype].of->getpleq == NULL)
48 <                        objerror(o, USER, "illegal material");
47 >                                sfun[o->otype].of->getpleq == NULL) {
48 >                        objerror(o,WARNING,"secondary sources not supported");
49 >                        continue;
50 >                }
51                  if (nvobjects == 0)
52                          vobject = (OBJECT *)malloc(sizeof(OBJECT));
53                  else
# Line 96 | Line 101 | int  n;
101          if (o == source[sn].so) /* objects cannot project themselves */
102                  return;
103                                  /* get virtual source material */
104 <        vsmat = sfun[objptr(o->omod)->otype].mf;
104 >        vsmat = sfun[vsmaterial(o)->otype].mf;
105                                  /* project virtual sources */
106          for (i = 0; i < vsmat->nproj; i++)
107                  if ((*vsmat->vproj)(proj, o, &source[sn], i))
108                          if ((ns = makevsrc(o, sn, proj)) >= 0) {
109 +                                source[ns].sa.sv.pn = i;
110   #ifdef DEBUG
111                                  virtverb(ns, stderr);
112   #endif
# Line 109 | Line 115 | int  n;
115   }
116  
117  
118 + OBJREC *
119 + vsmaterial(o)                   /* get virtual source material pointer */
120 + OBJREC  *o;
121 + {
122 +        register int  i;
123 +        register OBJREC  *m;
124 +
125 +        i = o->omod;
126 +        m = objptr(i);
127 +        if (m->otype != MAT_ILLUM || m->oargs.nsargs < 1 ||
128 +                        !strcmp(m->oargs.sarg[0], VOIDID) ||
129 +                        (i = modifier(m->oargs.sarg[0])) == OVOID)
130 +                return(m);              /* direct modifier */
131 +        return(objptr(i));              /* illum alternate */
132 + }
133 +
134 +
135   int
136   makevsrc(op, sn, pm)            /* make virtual source if reasonable */
137   OBJREC  *op;
# Line 131 | Line 154 | MAT4  pm;
154                  if (source[sn].sflags & SPROX)
155                          return(-1);             /* should never get here! */
156                  multv3(nsloc, source[sn].sloc, pm);
157 +                normalize(nsloc);
158                  VCOPY(ourspot.aim, ocent);
159                  ourspot.siz = PI*maxrad2;
160                  ourspot.flen = 0.;
161                  if (source[sn].sflags & SSPOT) {
138                        copystruct(&theirspot, source[sn].sl.s);
162                          multp3(theirspot.aim, source[sn].sl.s->aim, pm);
163 +                                                /* adjust for source size */
164 +                        d = sqrt(dist2(ourspot.aim, theirspot.aim));
165 +                        d = sqrt(source[sn].sl.s->siz/PI) + d*source[sn].srad;
166 +                        theirspot.siz = PI*d*d;
167 +                        ourspot.flen = theirspot.flen = source[sn].sl.s->flen;
168                          d = ourspot.siz;
169                          if (!commonbeam(&ourspot, &theirspot, nsloc))
170                                  return(-1);     /* no overlap */
# Line 158 | Line 186 | MAT4  pm;
186                          return(-1);             /* at source!! */
187                  if (source[sn].sflags & SPROX && d > source[sn].sl.prox)
188                          return(-1);             /* too far away */
161                ourspot.siz = 2.*PI*(1. - d/sqrt(d*d+maxrad2));
189                  ourspot.flen = 0.;
190 +                                                /* adjust for source size */
191 +                d = (sqrt(maxrad2) + source[sn].srad) / d;
192 +                if (d < 1.-FTINY)
193 +                        ourspot.siz = 2.*PI*(1. - sqrt(1.-d*d));
194 +                else
195 +                        nsflags &= ~SSPOT;
196                  if (source[sn].sflags & SSPOT) {
197                          copystruct(&theirspot, source[sn].sl.s);
198                          multv3(theirspot.aim, source[sn].sl.s->aim, pm);
199 <                        d = ourspot.siz;
200 <                        if (!commonspot(&ourspot, &theirspot, nsloc))
201 <                                return(-1);     /* no overlap */
199 >                        normalize(theirspot.aim);
200 >                        if (nsflags & SSPOT) {
201 >                                ourspot.flen = theirspot.flen;
202 >                                d = ourspot.siz;
203 >                                if (!commonspot(&ourspot, &theirspot, nsloc))
204 >                                        return(-1);     /* no overlap */
205 >                        } else {
206 >                                nsflags |= SSPOT;
207 >                                copystruct(&ourspot, &theirspot);
208 >                                d = 2.*ourspot.siz;
209 >                        }
210                          if (ourspot.siz < d-FTINY) {    /* it shrunk */
211                                  d = spotdisk(v, op, &ourspot, nsloc);
212                                  if (d <= FTINY)
# Line 175 | Line 216 | MAT4  pm;
216                                          VCOPY(ocent, v);
217                                  }
218                          }
178                        ourspot.flen = theirspot.flen;
219                  }
220                  if (source[sn].sflags & SFLAT) {        /* behind source? */
221                          multv3(nsnorm, source[sn].snorm, pm);
222 <                        if (checkspot(&ourspot, nsnorm) < 0)
222 >                        normalize(nsnorm);
223 >                        if (nsflags & SSPOT && !checkspot(&ourspot, nsnorm))
224                                  return(-1);
225                  }
226          }
# Line 192 | Line 233 | MAT4  pm;
233                  goto memerr;
234          source[i].sflags = nsflags;
235          VCOPY(source[i].sloc, nsloc);
236 +        multv3(source[i].ss[SU], source[sn].ss[SU], pm);
237 +        multv3(source[i].ss[SV], source[sn].ss[SV], pm);
238          if (nsflags & SFLAT)
239                  VCOPY(source[i].snorm, nsnorm);
240 <        source[i].ss = source[sn].ss; source[i].ss2 = source[sn].ss2;
241 <        if ((source[i].sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL)
242 <                goto memerr;
243 <        copystruct(source[i].sl.s, &ourspot);
240 >        else
241 >                multv3(source[i].ss[SW], source[sn].ss[SW], pm);
242 >        source[i].srad = source[sn].srad;
243 >        source[i].ss2 = source[sn].ss2;
244 >        if (nsflags & SSPOT) {
245 >                if ((source[i].sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL)
246 >                        goto memerr;
247 >                copystruct(source[i].sl.s, &ourspot);
248 >        }
249          if (nsflags & SPROX)
250                  source[i].sl.prox = source[sn].sl.prox;
251 <        source[i].sa.svnext = sn;
251 >        source[i].sa.sv.sn = sn;
252          source[i].so = op;
253          return(i);
254   memerr:
# Line 251 | Line 299 | register int  sn;      /* target source number */
299          RAY  sr;
300          FVECT  onorm;
301          FVECT  offsdir;
302 +        SRCINDEX  si;
303          double  or, d;
304          int  infront;
305 <        int  ssn;
305 >        int  stestlim, ssn;
306          int  nhit, nok;
307          register int  i, n;
308                                  /* return if pretesting disabled */
# Line 263 | Line 312 | register int  sn;      /* target source number */
312          getplaneq(onorm, o);
313                                  /* set number of rays to sample */
314          if (source[sn].sflags & SDISTANT) {
315 <                n = (2./3.*PI*PI)*or2/(thescene.cusize*thescene.cusize)*
316 <                                vspretest + .5;
315 >                                        /* 32. == heuristic constant */
316 >                n = 32.*or2/(thescene.cusize*thescene.cusize)*vspretest + .5;
317                  infront = DOT(onorm, source[sn].sloc) > 0.;
318          } else {
319                  for (i = 0; i < 3; i++)
320                          offsdir[i] = source[sn].sloc[i] - oc[i];
321 <                n = or2/DOT(offsdir,offsdir)*vspretest + .5;
321 >                d = DOT(offsdir,offsdir);
322 >                if (d <= FTINY)
323 >                        n = 2.*PI * vspretest + .5;
324 >                else
325 >                        n = 2.*PI * (1.-sqrt(1./(1.+or2/d)))*vspretest + .5;
326                  infront = DOT(onorm, offsdir) > 0.;
327          }
328 <        if (n < 1) n = 1;
328 >        if (n < MINSAMPLES) n = MINSAMPLES;
329   #ifdef DEBUG
330          fprintf(stderr, "pretesting source %d in object %s with %d rays\n",
331                          sn, o->oname, n);
332   #endif
333                                  /* sample */
334          or = sqrt(or2);
335 <        ssn = 25*n;
335 >        stestlim = n*STESTMAX;
336 >        ssn = 0;
337          nhit = nok = 0;
338          while (n-- > 0) {
339                                          /* get sample point */
340                  do {
341 <                        if (--ssn < 0) {
341 >                        if (ssn >= stestlim) {
342   #ifdef DEBUG
343                                  fprintf(stderr, "\ttoo hard to hit\n");
344   #endif
345                                  return(f);      /* too small a target! */
346                          }
347 +                        multisamp(offsdir, 3, urand(sn*931+5827+ssn));
348                          for (i = 0; i < 3; i++)
349 <                                offsdir[i] = or*(1. -
350 <                                                2.*urand(931*i+5827+ssn));
349 >                                offsdir[i] = or*(1. - 2.*offsdir[i]);
350 >                        ssn++;
351                          for (i = 0; i < 3; i++)
352                                  sr.rorg[i] = oc[i] + offsdir[i];
353                          d = DOT(offsdir,onorm);
# Line 309 | Line 364 | register int  sn;      /* target source number */
364                          rayorigin(&sr, NULL, PRIMARY, 1.0);
365                  } while (!(*ofun[o->otype].funp)(o, &sr));
366                                          /* check against source */
367 +                initsrcindex(&si);
368 +                si.sn = sn;
369 +                nopart(&si, &sr);
370                  samplendx++;
371 <                if (srcray(&sr, NULL, sn) == 0.)
371 >                if (!srcray(&sr, NULL, &si) || sr.rsrc != sn)
372                          continue;
373                  sr.revf = srcvalue;
374                  rayvalue(&sr);
# Line 318 | Line 376 | register int  sn;      /* target source number */
376                          continue;
377                  nok++;
378                                          /* check against obstructions */
379 <                srcray(&sr, NULL, sn);
379 >                rayclear(&sr);
380 >                sr.revf = raytrace;
381                  rayvalue(&sr);
382                  if (bright(sr.rcol) > FTINY)
383                          nhit++;
# Line 356 | Line 415 | FILE  *fp;
415          fprintf(fp, "\tat (%f,%f,%f)\n",
416                  source[sn].sloc[0], source[sn].sloc[1], source[sn].sloc[2]);
417          fprintf(fp, "\tlinked to source %d (%s)\n",
418 <                source[sn].sa.svnext, source[source[sn].sa.svnext].so->oname);
418 >                source[sn].sa.sv.sn, source[source[sn].sa.sv.sn].so->oname);
419          if (source[sn].sflags & SFOLLOW)
420                  fprintf(fp, "\talways followed\n");
421          else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines